Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import pathlib
- class Path(pathlib.Path):
- def __new__(cls, *args, **kwargs):
- if cls is Path:
- cls = WindowsPath if os.name == 'nt' else PosixPath
- self = cls._from_parts(args, init=False)
- if not self._flavour.is_supported:
- raise NotImplementedError("cannot instantiate %r on your system"
- % (cls.__name__,))
- self._init()
- return self
- def read_chunks(self, size=1024, *, mode='rb'):
- with self.open(mode) as f:
- sentinel = b'' if 'b' in mode else ''
- for chunk in iter(lambda: f.read(size), sentinel):
- yield chunk
- class PosixPath(Path, pathlib.PurePosixPath):
- __slots__ = ()
- class WindowsPath(Path, pathlib.PureWindowsPath):
- __slots__ = ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement