MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / open

Function open

tools/python-3.11.9-amd64/Lib/bz2.py:271–310  ·  view source on GitHub ↗

Open a bzip2-compressed file in binary or text mode. The filename argument can be an actual filename (a str, bytes, or PathLike object), or an existing file object to read from or write to. The mode argument can be "r", "rb", "w", "wb", "x", "xb", "a" or "ab" for binary

(filename, mode="rb", compresslevel=9,
         encoding=None, errors=None, newline=None)

Source from the content-addressed store, hash-verified

269
270
271def open(filename, mode="rb", compresslevel=9,
272 encoding=None, errors=None, newline=None):
273 """Open a bzip2-compressed file in binary or text mode.
274
275 The filename argument can be an actual filename (a str, bytes, or
276 PathLike object), or an existing file object to read from or write
277 to.
278
279 The mode argument can be "r", "rb", "w", "wb", "x", "xb", "a" or
280 "ab" for binary mode, or "rt", "wt", "xt" or "at" for text mode.
281 The default mode is "rb", and the default compresslevel is 9.
282
283 For binary mode, this function is equivalent to the BZ2File
284 constructor: BZ2File(filename, mode, compresslevel). In this case,
285 the encoding, errors and newline arguments must not be provided.
286
287 For text mode, a BZ2File object is created, and wrapped in an
288 io.TextIOWrapper instance with the specified encoding, error
289 handling behavior, and line ending(s).
290
291 """
292 if "t" in mode:
293 if "b" in mode:
294 raise ValueError("Invalid mode: %r" % (mode,))
295 else:
296 if encoding is not None:
297 raise ValueError("Argument 'encoding' not supported in binary mode")
298 if errors is not None:
299 raise ValueError("Argument 'errors' not supported in binary mode")
300 if newline is not None:
301 raise ValueError("Argument 'newline' not supported in binary mode")
302
303 bz_mode = mode.replace("t", "")
304 binary_file = BZ2File(filename, bz_mode, compresslevel=compresslevel)
305
306 if "t" in mode:
307 encoding = io.text_encoding(encoding)
308 return io.TextIOWrapper(binary_file, encoding, errors, newline)
309 else:
310 return binary_file
311
312
313def compress(data, compresslevel=9):

Callers 15

_maybe_openFunction · 0.70
symtable.pyFile · 0.70
fwalkFunction · 0.70
_fwalkFunction · 0.70
pickletools.pyFile · 0.70
dump_statsMethod · 0.70
translationFunction · 0.70
get_dataMethod · 0.70
_reopenMethod · 0.70
get_sourceMethod · 0.70
extend_pathFunction · 0.70
__setupMethod · 0.70

Calls 2

BZ2FileClass · 0.85
replaceMethod · 0.45

Tested by 1

_load_testfileFunction · 0.56