Add a mapping between a type and an extension. When the extension is already known, the new type will replace the old one. When the type is already known the extension will be added to the list of known extensions. If strict is true, information will be adde
(self, type, ext, strict=True)
| 79 | self.read(name, strict) |
| 80 | |
| 81 | def add_type(self, type, ext, strict=True): |
| 82 | """Add a mapping between a type and an extension. |
| 83 | |
| 84 | When the extension is already known, the new |
| 85 | type will replace the old one. When the type |
| 86 | is already known the extension will be added |
| 87 | to the list of known extensions. |
| 88 | |
| 89 | If strict is true, information will be added to |
| 90 | list of standard types, else to the list of non-standard |
| 91 | types. |
| 92 | |
| 93 | Valid extensions are empty or start with a '.'. |
| 94 | """ |
| 95 | if ext and not ext.startswith('.'): |
| 96 | from warnings import _deprecated |
| 97 | |
| 98 | _deprecated( |
| 99 | "Undotted extensions", |
| 100 | "Using undotted extensions is deprecated and " |
| 101 | "will raise a ValueError in Python {remove}", |
| 102 | remove=(3, 16), |
| 103 | ) |
| 104 | |
| 105 | if not type: |
| 106 | return |
| 107 | self.types_map[strict][ext] = type |
| 108 | exts = self.types_map_inv[strict].setdefault(type, []) |
| 109 | if ext not in exts: |
| 110 | exts.append(ext) |
| 111 | |
| 112 | def guess_type(self, url, strict=True): |
| 113 | """Guess the type of a file which is either a URL or a path-like object. |