<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def service(self, entity_id, typ, service, binding=None):
 """ Get me all services with a specified entity ID and type, that supports the specified version of binding. :param entity_id: The EntityId :param service: which service that is sought for :param binding: A binding identifier :return: list of service descriptions. Or if no binding was specified a list of 2-tuples (binding, srv) """

        try:
            srvs = []
            for t in self[entity_id][typ]:
                try:
                    srvs.extend(t[service])
                except KeyError:
                    pass
        except KeyError:
            return None

        if not srvs:
            return srvs

        if binding:
            res = []
            for srv in srvs:
                if srv["binding"] == binding:
                    res.append(srv)
        else:
            res = {}
            for srv in srvs:
                try:
                    res[srv["binding"]].append(srv)
                except KeyError:
                    res[srv["binding"]] = [srv]
        logger.debug("service => %s", res)
        return res