|
23 | 23 | read_mime_types(file) -- parse one file, return a dictionary or None |
24 | 24 | """ |
25 | 25 |
|
| 26 | +lazy import os |
| 27 | +lazy import posixpath |
| 28 | +lazy import urllib.parse |
| 29 | + |
26 | 30 | try: |
27 | 31 | from _winapi import _mimetypes_read_windows_registry |
28 | 32 | except ImportError: |
|
33 | 37 | except ImportError: |
34 | 38 | _winreg = None |
35 | 39 |
|
36 | | -lazy import urllib.parse |
37 | | - |
38 | 40 | __all__ = [ |
39 | 41 | "knownfiles", "inited", "MimeTypes", |
40 | 42 | "guess_type", "guess_file_type", "guess_all_extensions", "guess_extension", |
@@ -123,9 +125,6 @@ def guess_type(self, url, strict=True): |
123 | 125 | Optional 'strict' argument when False adds a bunch of commonly found, |
124 | 126 | but non-standard types. |
125 | 127 | """ |
126 | | - # Lazy import to improve module import time |
127 | | - import os |
128 | | - |
129 | 128 | # TODO: Deprecate accepting file paths (in particular path-like objects). |
130 | 129 | url = os.fspath(url) |
131 | 130 | # Without a ':' the argument cannot carry a URL scheme, so it cannot |
@@ -159,19 +158,13 @@ def guess_type(self, url, strict=True): |
159 | 158 | type = 'text/plain' |
160 | 159 | return type, None # never compressed, so encoding is None |
161 | 160 |
|
162 | | - # Lazy import to improve module import time |
163 | | - import posixpath |
164 | | - |
165 | 161 | return self._guess_file_type(url, strict, posixpath.splitext) |
166 | 162 |
|
167 | 163 | def guess_file_type(self, path, *, strict=True): |
168 | 164 | """Guess the type of a file based on its path. |
169 | 165 |
|
170 | 166 | Similar to guess_type(), but takes file path instead of URL. |
171 | 167 | """ |
172 | | - # Lazy import to improve module import time |
173 | | - import os |
174 | | - |
175 | 168 | path = os.fsdecode(path) |
176 | 169 | path = os.path.splitdrive(path)[1] |
177 | 170 | return self._guess_file_type(path, strict, os.path.splitext) |
@@ -418,9 +411,6 @@ def init(files=None): |
418 | 411 | else: |
419 | 412 | db = _db |
420 | 413 |
|
421 | | - # Lazy import to improve module import time |
422 | | - import os |
423 | | - |
424 | 414 | for file in files: |
425 | 415 | if os.path.isfile(file): |
426 | 416 | db.read(file) |
|
0 commit comments