(encoding)
return ''.join(chars)
Normalize an encoding name.

        Normalization works as follows: all non-alphanumeric
        characters except the dot used for Python package names are
        collapsed and replaced with a single underscore, e.g. '  -;#'
        becomes '_'. Leading and trailing underscores are removed.

        Note that encoding names should be ASCII only.
Normalize an encoding name.
Normalize an encoding name .
def normalize_encoding(encoding):

    """ Normalize an encoding name.

        Normalization works as follows: all non-alphanumeric
        characters except the dot used for Python package names are
        collapsed and replaced with a single underscore, e.g. '  -;#'
        becomes '_'. Leading and trailing underscores are removed.

        Note that encoding names should be ASCII only.

    """
    if isinstance(encoding, bytes):
        encoding = str(encoding, "ascii")

    chars = []
    punct = False
    for c in encoding:
        if c.isalnum() or c == '.':
            if punct and chars:
                chars.append('_')
            if c.isascii():
                chars.append(c)
            punct = False
        else:
            punct = True
    return ''.join(chars)
def normalize_encoding ( encoding ) : if isinstance ( encoding , bytes ) : encoding = str ( encoding , "ascii" ) chars = [ ] punct = False for c in encoding : if c . isalnum ( ) or c == '.' : if punct and chars : chars . append ( '_' ) if c . isascii ( ) : chars . append ( c ) punct = False else : punct = True return '' . join ( chars )