

def makeService(config):
    s = appservice.MultiService()
    conf = inetdconf.InetdConf()
    conf.parseFile(open(config['file']))
    rpcConf = inetdconf.RPCServicesConf()
    try:
        rpcConf.parseFile(open(config['rpc']))
    except:
        log.deferr()
    for service in conf.services:
        rpc = service.protocol.startswith('rpc/')
        protocol = service.protocol
        if (rpc and (not rpcOk)):
            log.msg('Skipping rpc service due to lack of rpc support')
            continue
        if rpc:
            protocol = protocol[4:]
            if (not protocolDict.has_key(protocol)):
                log.msg(('Bad protocol: ' + protocol))
                continue
            try:
                (name, rpcVersions) = service.name.split('/')
            except ValueError:
                log.msg(('Bad RPC service/version: ' + service.name))
                continue
            if (not rpcConf.services.has_key(name)):
                log.msg(('Unknown RPC service: ' + repr(service.name)))
                continue
            try:
                if ('-' in rpcVersions):
                    (start, end) = map(int, rpcVersions.split('-'))
                    rpcVersions = range(start, (end + 1))
                else:
                    rpcVersions = [int(rpcVersions)]
            except ValueError:
                log.msg(('Bad RPC versions: ' + str(rpcVersions)))
                continue
        if ((protocol, service.socketType) not in [('tcp', 'stream'), ('udp', 'dgram')]):
            log.msg(('Skipping unsupported type/protocol: %s/%s' % (service.socketType, service.protocol)))
            continue
        try:
            service.user = int(service.user)
        except ValueError:
            try:
                service.user = pwd.getpwnam(service.user)[2]
            except KeyError:
                log.msg(('Unknown user: ' + service.user))
                continue
        if (service.group is None):
            service.group = pwd.getpwuid(service.user)[3]
        else:
            try:
                service.group = int(service.group)
            except ValueError:
                try:
                    service.group = grp.getgrnam(service.group)[2]
                except KeyError:
                    log.msg(('Unknown group: ' + service.group))
                    continue
        if (service.program == 'internal'):
            if config['nointernal']:
                continue
            if (not inetd.internalProtocols.has_key(service.name)):
                log.msg(('Unknown internal service: ' + service.name))
                continue
            factory = ServerFactory()
            factory.protocol = inetd.internalProtocols[service.name]
        elif rpc:
            i = RPCServer(rpcVersions, rpcConf, proto, service)
            i.setServiceParent(s)
            continue
        else:
            factory = inetd.InetdFactory(service)
        if (protocol == 'tcp'):
            internet.TCPServer(service.port, factory).setServiceParent(s)
        elif (protocol == 'udp'):
            raise RuntimeError('not supporting UDP')
    return s

dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/runner/inetdtap.py makeService/original