+1 for the context manager ideas. Anything that is like a resource should be available as a context manager.
On Sat, Nov 8, 2014 at 9:46 AM, Ionel Cristian Mărieș <cont...@ionelmc.ro> wrote: > Hello, > > In the current incarnation Pathlib is missing some key features I need in > my usecases. I want to contribute them but i'd like a bit of feedback on > the new api before jumping to implementation. > > The four things I need are: > > #1. A context manager for temporary files and dirs (that cleans everything > up on exit). Eg: > > with pathlib.TmpDir(suffix='', prefix='') as tmp: > assert isinstance(tmp, pathlib.Path) > > with pathlib.TmpFile(suffix='', prefix='') as tmp: > assert isinstance(tmp, pathlib.Path) > > #2. A context manager for changing working directory (that switches to the > old cwd on exit). Eg: > > with path.cd(): > assert os.getcwd() == path > > # > 3 > . Shutil-like features: > > - copy_file > - copy_dir (or copy_tree?) > - copy (does copy_dir or copy_file depending on what the source is. How to > handle symlinks?) > - rm_dir (or rm_tree? Also, this would be required for the TmpDir path). > > #4. Zip files support. A specialised Path subclass that works inside a zip > file. I'm ok having this as an external package but some discussion would > be useful as I'd have to rely on pathlib internals. > > After some brief looking in the pathlib code it would appear the wise > thing would be to have the zip path as the "drive" for the ZipPaths that > refer to files inside the zip. > > I'm not sure where the best place is to store the internal zipfile object. > Perhaps the accessor? > > Ideally the ZipFiles would work with the shtuil-like api just fine (or at > least the readonly operations). > > Thanks, > -- Ionel M. > > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/rymg19%40gmail.com > > -- Ryan If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated." Personal reality distortion fields are immune to contradictory evidence. - srean Check out my website: http://kirbyfan64.github.io/
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com