Parse through system-known services
    :return: {
        'svc': [
          {  'port': port
             'proto': proto,
             'desc': comment
          },
        ],
    }
352772
def services(services_file='/etc/services'):
    '''
    
    '''
    res = {}
    with salt.utils.files.fopen(services_file, 'r') as svc_defs:
        for svc_def in svc_defs.readlines():
            svc_def = salt.utils.stringutils.to_unicode(svc_def.strip())
            if not svc_def or svc_def.startswith('#'):
                continue
            elif '#' in svc_def:
                svc_def, comment = svc_def.split('#', 1)
                comment = comment.strip()
            else:
                comment = None
            svc_def = svc_def.split()

            port, proto = svc_def.pop(1).split('/')
            port = int(port)

            for name in svc_def:
                svc_res = res.get(name, {})
                pp_res = svc_res.get(port, False)
                if not pp_res:
                    svc = {
                        'port':  port,
                        'proto': proto,
                    }
                    if comment:
                        svc['desc'] = comment
                    svc_res[port] = svc
                else:
                    curr_proto = pp_res['proto']
                    if isinstance(curr_proto, (list, tuple)):
                        curr_proto.append(proto)
                    else:
                        pp_res['proto'] = [curr_proto, proto]

                    curr_desc = pp_res.get('desc', False)
                    if comment:
                        if not curr_desc:
                            pp_res['desc'] = comment
                        elif comment != curr_desc:
                            pp_res['desc'] = '{0}, {1}'.format(curr_desc, comment)
                res[name] = svc_res

    for svc, data in res.items():
        if len(data) == 1:
            res[svc] = data.values().pop()
            continue
        else:
            res[svc] = list(data.values())

    return res
39082
def get_all():
    '''
    
    '''
    ret = []
    service = _cmd()
    for svc in __salt__['cmd.run']('{0} ls all'.format(service)).splitlines():
        ret.append(svc)
    return sorted(ret)
958967
def _parse_ports(self, ports):
        
        if not ports:
            return []

        return [tuple(port_pair.split("::")) for port_pair in ports.strip(";").split(";")]
677650
def connected_svcports(self):
        '''

        '''
        return [p for p in self.ports \
                if p.__class__.__name__ == 'CorbaPort' and p.is_connected]
730902
function parsePorts(arg) {
  // coerce and split
  var ports = ('' + arg).split(':');
  if (ports.length !== 2) {
    panic('Error parsing ports.');
  }

  // parse ints
  var devicePort = Number((ports[0] === '') ? NaN : ports[0])
    , relayPort = Number((ports[1] === '') ? NaN : ports[1]);

  // NaN check em
  if (devicePort !== devicePort || relayPort !== relayPort) {
    panic('Error parsing ports.');
  }

  return [devicePort, relayPort];
}
461416
def parse_addr(addr, *, proto=None, host=None):
    
    port = None

    if isinstance(addr, Address):
        return addr
    elif isinstance(addr, str):
        if addr.startswith('http://'):
            proto, addr = 'http', addr[7:]
        if addr.startswith('udp://'):
            proto, addr = 'udp', addr[6:]
        elif addr.startswith('tcp://'):
            proto, addr = 'tcp', addr[6:]
        elif addr.startswith('unix://'):
            proto, addr = 'unix', addr[7:]
        a, _, b = addr.partition(':')
        host = a or host
        port = b or port
    elif isinstance(addr, (tuple, list)):
        # list is not good
        a, b = addr
        host = a or host
        port = b or port
    elif isinstance(addr, int):
        port = addr
    else:
        raise ValueError('bad value')

    if port is not None:
        port = int(port)
    return Address(proto, host, port)
1015132
def _parse_device_information(device_info_string) -> dict:
    '''
    
    '''
    error_msg = 'Unexpected argument to _parse_device_information: {}'.format(
        device_info_string)
    if not device_info_string or \
            not isinstance(device_info_string, str):
        raise ParseError(error_msg)
    parsed_values = device_info_string.strip().split(' ')
    if len(parsed_values) < 3:
        log.error(error_msg)
        raise ParseError(error_msg)
    res = {
        _parse_key_from_substring(s): _parse_string_value_from_substring(s)
        for s in parsed_values[:3]
    }
    for key in ['model', 'version', 'serial']:
        if key not in res:
            raise ParseError(error_msg)
    return res
762395
def _extract_ports(port_string):
    
    _ports = str(port_string)
    if '-' in _ports:
        start, end = _ports.split('-')
        return {'min_port': start, 'max_port': end}
    return {'min_port': _ports, 'max_port': _ports}
9493
def parse_service_data_from_options
      data = {}
      data[:strategy] = deploy_strategy if deploy_strategy
      data[:ports] = parse_ports(ports_list) unless ports_list.empty?
      data[:links] = parse_links(link_list) unless link_list.empty?
      data[:memory] = parse_memory(memory) if memory
      data[:memory_swap] = parse_memory(memory_swap) if memory_swap
      data[:shm_size] = parse_memory(shm_size) if shm_size
      data[:cpus] = cpus if cpus
      data[:cpu_shares] = cpu_shares if cpu_shares
      data[:affinity] = affinity_list unless affinity_list.empty?
      data[:env] = env_list unless env_list.empty?
      data[:secrets] = parse_secrets(secret_list) unless secret_list.empty?
      data[:container_count] = instances if instances
      data[:cmd] = Shellwords.split(cmd) if cmd
      data[:user] = user if user
      data[:image] = parse_image(image) if image
      data[:privileged] = privileged?
      data[:cap_add] = cap_add_list if cap_add_list
      data[:cap_drop] = cap_drop_list if cap_drop_list
      data[:net] = net if net
      data[:log_driver] = log_driver if log_driver
      data[:log_opts] = parse_log_opts(log_opt_list) if log_opt_list
      deploy_opts = parse_deploy_opts
      data[:deploy_opts] = deploy_opts unless deploy_opts.empty?
      health_check = parse_health_check
      data[:health_check] = health_check unless health_check.empty?
      data[:pid] = pid if pid
      data[:stop_signal] = stop_signal if stop_signal
      data[:stop_grace_period] = stop_timeout if stop_timeout
      data
    end
344768
def list(cls, spec=None):
        

        if spec is None:
            spec = {}

        xmlrpc = XMLRPCConnection()
        try:
            pref_list = xmlrpc.connection.list_prefix(
                {
                    'prefix': spec,
                    'auth': AuthOptions().options
                })
        except xmlrpclib.Fault as xml_fault:
            raise _fault_to_exception(xml_fault)
        res = list()
        for pref in pref_list:
            p = Prefix.from_dict(pref)
            res.append(p)

        return res
281674
def status(svc_name=''):
    '''
    
    '''
    cmd = 'monit status'
    res = __salt__['cmd.run'](cmd)
    prostr = 'Process'+' '*28
    s = res.replace('Process', prostr).replace("'", '').split('\n\n')
    entries = {}
    for process in s[1:-1]:
        pro = process.splitlines()
        tmp = {}
        for items in pro:
            key = items[:36].strip()
            tmp[key] = items[35:].strip()
        entries[pro[0].split()[1]] = tmp
    if svc_name == '':
        ret = entries
    else:
        ret = entries.get(svc_name, 'No such service')
    return ret
990086
def parse_itms_services(url_data):
    """"""
    query = url_data.urlparts[3]
    for k, v, sep in urlutil.parse_qsl(query, keep_blank_values=True):
        if k == "url":
            url_data.add_url(v)
            break
213333
def _get_service_state(service_id: str):
        """"""
        LOG.debug('Getting state of service %s', service_id)
        services = get_service_id_list()
        service_ids = [s for s in services if service_id in s]
        if len(service_ids) != 1:
            return 'Service not found! services = {}'.format(str(services))
        subsystem, name, version = service_ids[0].split(':')
        return ServiceState(subsystem, name, version)
99701
def parseService(self, yadis_url, uri, type_uris, service_element):
        """"""
        self.type_uris = type_uris
        self.server_url = uri
        self.used_yadis = True

        if not self.isOPIdentifier():
            # XXX: This has crappy implications for Service elements
            # that contain both 'server' and 'signon' Types.  But
            # that's a pathological configuration anyway, so I don't
            # think I care.
            self.local_id = findOPLocalIdentifier(service_element,
                                                  self.type_uris)
            self.claimed_id = yadis_url
811802
def _parse_response(self, response):
        

        response_dict = {}
        for line in response.splitlines():
            key, value = response.split("=", 1)
            response_dict[key] = value
        return response_dict
402894
def parse_headers(cls, msg):
        
        return list(email.parser.Parser().parsestr(msg).items())
152285
def parse_services(rule):
    '''
    
    '''
    parser = argparse.ArgumentParser()
    rules = shlex.split(rule)
    rules.pop(0)
    parser.add_argument('--disabled', dest='disabled', action='store')
    parser.add_argument('--enabled', dest='enabled', action='store')

    args = clean_args(vars(parser.parse_args(rules)))
    parser = None
    return args