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

Method open

Lib/zipfile/_path/__init__.py:334–352  ·  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

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