Normalize an underscore-separated descriptor to something more readable.

    i.e. 'NAGIOS_SERVER' becomes 'Nagios Server', and 'host_components' becomes
    'Host Components'
555639
def normalize_underscore_case(name):
    
    normalized = name.lower()
    normalized = re.sub(r'_(\w)',
                        lambda match: ' ' + match.group(1).upper(),
                        normalized)
    return normalized[0].upper() + normalized[1:]
650885
def _normalize_hosts(hosts):
    
    # if hosts are empty, just defer to defaults down the line
    if hosts is None:
        return [{}]

    # passed in just one string
    if isinstance(hosts, string_types):
        hosts = [hosts]

    out = []
    # normalize hosts to dicts
    for host in hosts:
        if isinstance(host, string_types):
            if "://" not in host:
                host = "//%s" % host

            parsed_url = urlparse(host)
            h = {"host": parsed_url.hostname}

            if parsed_url.port:
                h["port"] = parsed_url.port

            if parsed_url.scheme == "https":
                h["port"] = parsed_url.port or 443
                h["use_ssl"] = True

            if parsed_url.username or parsed_url.password:
                h["http_auth"] = "%s:%s" % (
                    unquote(parsed_url.username),
                    unquote(parsed_url.password),
                )

            if parsed_url.path and parsed_url.path != "/":
                h["url_prefix"] = parsed_url.path

            out.append(h)
        else:
            out.append(host)
    return out
670007
def normalize_LCSH(subject):
    """"""
    # Strip then divide on -- which is a delimiter for LCSH;
    # rejoin after stripping parts.
    subject_parts = subject.strip().split('--')
    joined_subject = ' -- '.join([part.strip() for part in subject_parts])

    # Check if there is punctuation at the end of the string,
    # and if not, add a trailing period.
    if re.search(r'[^a-zA-Z0-9]$', joined_subject) is None:
        joined_subject = joined_subject + '.'

    return joined_subject
1112297
def normalizeToName(val):
    
    if val not in tagsAndNameSet:
        raise KeyError("{} is not a tag or name string".format(val))
    else:
        try:
            return tagToFullDict[val]
        except KeyError:
            return val
12568
def to_underscore(s):
    
    return re.sub(
            r'(?!^)([A-Z]+)',
            lambda m: "_{0}".format(m.group(1).lower()),
            re.sub(r'(?!^)([A-Z]{1}[a-z]{1})', lambda m: "_{0}".format(m.group(1).lower()), s)
        ).lower()
624995
def normalize(self, parts):
        

        part = parts.list[0]

        return {
            'content': part.file.read(),
            'content-type': part.type,
            'file-ext': extensions.get(part.type),
            'file-name': part.filename,
        }
1121377
def _normalize(self, name):
        
        name = re.sub(
            r'^(Senator|Representative|Sen\.?|Rep\.?|'
            'Hon\.?|Right Hon\.?|Mr\.?|Mrs\.?|Ms\.?|L\'hon\.?|'
            'Assembly(member|man|woman)) ',
            '',
            name)
        return name.strip().lower().replace('.', '')
466187
def normalize_match_data_captures(match_data)
      match_data.names.inject({}) do |mem, capture|
        mem[capture.gsub(/\d/,'')] = match_data[capture]
        break mem if mem.keys.length >= 2
        mem
      end
    end
727015
def normalize!
      if path && path == ''
        set_path('/')
      end
      if scheme && scheme != scheme.downcase
        set_scheme(self.scheme.downcase)
      end
      if host && host != host.downcase
        set_host(self.host.downcase)
      end        
    end
1127343
def _normalize(self, flags):
        """"""
        norm = None
        if isinstance(flags, MessageFlags):
            norm = flags.bytes
        elif isinstance(flags, bytearray):
            norm = binascii.hexlify(flags)
        elif isinstance(flags, int):
            norm = bytes([flags])
        elif isinstance(flags, bytes):
            norm = binascii.hexlify(flags)
        elif isinstance(flags, str):
            flags = flags[0:2]
            norm = binascii.hexlify(binascii.unhexlify(flags.lower()))
        elif flags is None:
            norm = None
        else:
            _LOGGER.warning('MessageFlags with unknown type %s: %r',
                            type(flags), flags)
        return norm
474260
def normalize(name):
    """"""

    # Name should not contain some specials chars (issue #1068)
    ret = name.replace(':', '')
    ret = ret.replace('%', '')
    ret = ret.replace(' ', '_')

    return ret
466552
def _normalize_rename(self, mapping, schema, field):
        
        if 'rename' in schema[field]:
            mapping[schema[field]['rename']] = mapping[field]
            del mapping[field]
227324
def normalize_pipeline_name(name=''):
    """"""
    normalized_name = name
    for bad in '\\/?%#':
        normalized_name = normalized_name.replace(bad, '_')
    return normalized_name
1242161
def normalize_node(node, headers=None):
    """"""
    headers = {} if headers is None else headers
    if isinstance(node, str):
        url = normalize_url(node)
        return {'endpoint': url, 'headers': headers}

    url = normalize_url(node['endpoint'])
    node_headers = node.get('headers', {})
    return {'endpoint': url, 'headers': {**headers, **node_headers}}
965036
def normalize_hostname(hostname):
    ''''''
    try:
        new_hostname = hostname.encode('idna').decode('ascii').lower()
    except UnicodeError as error:
        raise UnicodeError('Hostname {} rejected: {}'.format(hostname, error)) from error

    if hostname != new_hostname:
        # Check for round-trip. May raise UnicodeError
        new_hostname.encode('idna')

    return new_hostname
263117
def normalizer(text, exclusion=OPERATIONS_EXCLUSION, lower=True, separate_char='-', **kwargs):
    
    clean_str = re.sub(r'[^\w{}]'.format(
        "".join(exclusion)), separate_char, text.strip()) or ''
    clean_lowerbar = clean_str_without_accents = strip_accents(clean_str)

    if '_' not in exclusion:
        clean_lowerbar = re.sub(r'\_', separate_char, clean_str_without_accents.strip())

    limit_guion = re.sub(r'\-+', separate_char, clean_lowerbar.strip())

    # TODO: refactor with a regexp
    if limit_guion and separate_char and separate_char in limit_guion[0]:
        limit_guion = limit_guion[1:]

    if limit_guion and separate_char and separate_char in limit_guion[-1]:
        limit_guion = limit_guion[:-1]

    if lower:
        limit_guion = limit_guion.lower()

    return limit_guion
225642
def normalize(input, case_mapping=protocol.DEFAULT_CASE_MAPPING):
    
    if case_mapping not in protocol.CASE_MAPPINGS:
        raise pydle.protocol.ProtocolViolation('Unknown case mapping ({})'.format(case_mapping))

    input = input.lower()

    if case_mapping in ('rfc1459', 'rfc1459-strict'):
        input = input.replace('{', '[').replace('}', ']').replace('|', '\\')
    if case_mapping == 'rfc1459':
        input = input.replace('~', '^')

    return input