MCPcopy Index your code
hub / github.com/RustPython/RustPython / hook_compressed

Function hook_compressed

Lib/fileinput.py:401–417  ·  view source on GitHub ↗
(filename, mode, *, encoding=None, errors=None)

Source from the content-addressed store, hash-verified

399
400
401def hook_compressed(filename, mode, *, encoding=None, errors=None):
402 if encoding is None and "b" not in mode: # EncodingWarning is emitted in FileInput() already.
403 encoding = "locale"
404 ext = os.path.splitext(filename)[1]
405 if ext == '.gz':
406 import gzip
407 stream = gzip.open(filename, mode)
408 elif ext == '.bz2':
409 import bz2
410 stream = bz2.BZ2File(filename, mode)
411 else:
412 return open(filename, mode, encoding=encoding, errors=errors)
413
414 # gzip and bz2 are binary mode by default.
415 if "b" not in mode:
416 stream = io.TextIOWrapper(stream, encoding=encoding, errors=errors)
417 return stream
418
419
420def hook_encoded(encoding, errors=None):

Callers

nothing calls this directly

Calls 3

splitextMethod · 0.80
openFunction · 0.70
openMethod · 0.45

Tested by

no test coverage detected