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.
(encoding)
| 41 | pass |
| 42 | |
| 43 | def normalize_encoding(encoding): |
| 44 | |
| 45 | """ Normalize an encoding name. |
| 46 | |
| 47 | Normalization works as follows: all non-alphanumeric |
| 48 | characters except the dot used for Python package names are |
| 49 | collapsed and replaced with a single underscore, e.g. ' -;#' |
| 50 | becomes '_'. Leading and trailing underscores are removed. |
| 51 | |
| 52 | Note that encoding names should be ASCII only. |
| 53 | |
| 54 | """ |
| 55 | if isinstance(encoding, bytes): |
| 56 | encoding = str(encoding, "ascii") |
| 57 | |
| 58 | chars = [] |
| 59 | punct = False |
| 60 | for c in encoding: |
| 61 | if c.isalnum() or c == '.': |
| 62 | if punct and chars: |
| 63 | chars.append('_') |
| 64 | if c.isascii(): |
| 65 | chars.append(c) |
| 66 | punct = False |
| 67 | else: |
| 68 | punct = True |
| 69 | return ''.join(chars) |
| 70 | |
| 71 | def search_function(encoding): |
| 72 |
no test coverage detected