import codecs import locale import re import sys from pip._internal.utils.typing import MYPY_CHECK_RUNNING if MYPY_CHECK_RUNNING: from typing import List, Tuple, Text BOMS = [ (codecs.BOM_UTF8, 'utf-8'), (codecs.BOM_UTF16, 'utf-16'), (codecs.BOM_UTF16_BE, 'utf-16-be'), (codecs.BOM_UTF16_LE, 'utf-16-le'), (codecs.BOM_UTF32, 'utf-32'), (codecs.BOM_UTF32_BE, 'utf-32-be'), (codecs.BOM_UTF32_LE, 'utf-32-le'), ] # type: List[Tuple[bytes, Text]] ENCODING_RE = re.compile(br'coding[:=]\s*([-\w.]+)') def auto_decode(data): # type: (bytes) -> Text """Check a bytes string for a BOM to correctly detect the encoding Fallback to locale.getpreferredencoding(False) like open() on Python3""" for bom, encoding in BOMS: if data.startswith(bom): return data[len(bom):].decode(encoding) # Lets check the first two lines as in PEP263 for line in data.split(b'\n')[:2]: if line[0:1] == b'#' and ENCODING_RE.search(line): result = ENCODING_RE.search(line) assert result is not None encoding = result.groups()[0].decode('ascii') return data.decode(encoding) return data.decode( locale.getpreferredencoding(False) or sys.getdefaultencoding(), )
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 2755 |
|
|
__init__.py | File | 0 B | 0644 |
|
appdirs.py | File | 1.32 KB | 0644 |
|
compat.py | File | 9.27 KB | 0644 |
|
compatibility_tags.py | File | 5.31 KB | 0644 |
|
datetime.py | File | 295 B | 0644 |
|
deprecation.py | File | 3.24 KB | 0644 |
|
direct_url_helpers.py | File | 4.26 KB | 0644 |
|
distutils_args.py | File | 1.32 KB | 0644 |
|
encoding.py | File | 1.25 KB | 0644 |
|
entrypoints.py | File | 1.13 KB | 0644 |
|
filesystem.py | File | 6.78 KB | 0644 |
|
filetypes.py | File | 571 B | 0644 |
|
glibc.py | File | 3.22 KB | 0644 |
|
hashes.py | File | 4.57 KB | 0644 |
|
inject_securetransport.py | File | 810 B | 0644 |
|
logging.py | File | 12.79 KB | 0644 |
|
misc.py | File | 27.34 KB | 0644 |
|
models.py | File | 1.17 KB | 0644 |
|
packaging.py | File | 2.96 KB | 0644 |
|
parallel.py | File | 3.32 KB | 0644 |
|
pkg_resources.py | File | 1.22 KB | 0644 |
|
setuptools_build.py | File | 4.94 KB | 0644 |
|
subprocess.py | File | 9.69 KB | 0644 |
|
temp_dir.py | File | 8.18 KB | 0644 |
|
typing.py | File | 1.37 KB | 0644 |
|
unpacking.py | File | 9.27 KB | 0644 |
|
urls.py | File | 1.49 KB | 0644 |
|
virtualenv.py | File | 3.62 KB | 0644 |
|
wheel.py | File | 7.13 KB | 0644 |
|