MCPcopy Index your code
hub / github.com/python/cpython / open

Method open

Lib/zipfile/_path/__init__.py:337–355  ·  view source on GitHub ↗

Open this entry as text or binary following the semantics of ``pathlib.Path.open()`` by passing arguments through to io.TextIOWrapper().

(self, mode='r', *args, pwd=None, **kwargs)

Source from the content-addressed store, hash-verified

335 return hash((self.root, self.at))
336
337 def open(self, mode='r', *args, pwd=None, **kwargs):
338 """
339 Open this entry as text or binary following the semantics
340 of ``pathlib.Path.open()`` by passing arguments through
341 to io.TextIOWrapper().
342 """
343 if self.is_dir():
344 raise IsADirectoryError(self)
345 zip_mode = mode[0]
346 if zip_mode == 'r' and not self.exists():
347 raise FileNotFoundError(self)
348 stream = self.root.open(self.at, zip_mode, pwd=pwd)
349 if 'b' in mode:
350 if args or kwargs:
351 raise ValueError("encoding args invalid for binary operation")
352 return stream
353 # Text mode:
354 encoding, args, kwargs = _extract_text_encoding(*args, **kwargs)
355 return io.TextIOWrapper(stream, encoding, *args, **kwargs)
356
357 def _base(self):
358 return pathlib.PurePosixPath(self.at) if self.at else self.filename

Callers 2

read_textMethod · 0.95
read_bytesMethod · 0.95

Calls 3

is_dirMethod · 0.95
existsMethod · 0.95
_extract_text_encodingFunction · 0.85

Tested by

no test coverage detected