[py-dev] py.path.dict and py.path.proxy patch

holger krekel hpk at trillke.net
Mon Feb 14 19:18:51 CET 2005


Dear Matthew, 

sorry for taking some time ... PyPy and other stuff keeps
me busy :-) 

On Fri, Jan 28, 2005 at 23:04 -0600, Matthew Scott wrote:
> What py.path.proxy allows you to do is to take an arbitrary path and 
> create a proxy filesystem into a limited area of that path's filesystem. 
>  Maybe a better word would be sandbox, but I found proxy to be easier 
> to type.  Naming suggestions are welcome.  This code is set in fresh 
> mud, not in stone.  :)

Hehe, i like the patch and your examples.  Yet i am trying to
think of real use cases for proxy() and dict() paths.  I
guess you have some, don't you? 

> I haven't yet tried py.path.proxy using anything but py.path.local root 
> paths.

py.path.proxy() seems like a kind of a "chroot" path, btw.

> Here's an example of using py.path.proxy to wrap a directory specified 
> by py.path.local, and of using py.path.dict to create a dictionary-based 
> virtual file system that contains a copy of that directory:

Especially your dict-proxy path implementation is interesting.  IIRC, 
i have been thinking with Armin about refactoring path implementations
to work with some kind of filesystem representation as well. I think the 
idea arosed around Armin's nfs-pure-python server that works based on 
py.path, so you can basically mount certain revisions from a svn
repository, and with py.path.dict from a dictionary :-) 

A note about your patch: since a few month we have a revised 
concept for error-handling: basically all py.path.local 
(and some of the py.path.svn* stuff) will raise py.error.X 
where X == name from errno.*.  The logic to convert 
OSErrors to py.error's is in _callex() in path/common.py. 

Example: 

>>> py.path.local('/tmp/x').chdir()
------------------------------------------------------------
Traceback (most recent call last):
      File "<stdin>", line 1, in ?
  File "/home/hpk/projects/dist-vadm/py/path/local/local.py", line 306, in chdir
    self._callex(os.chdir, self.strpath)
  File "/home/hpk/projects/dist-vadm/py/path/common.py", line 216, in _callex
    raise cls, value
ENOTDIR: [Not a directory]: chdir('/tmp/x',)
>>>

This is obviously a nicely descriptive error which you can
cleanly catch via "except py.error.ENOTDIR:".  Generally
py.path implementations should now use this error mechanism to
give users a uniform way dealing with permission or semantic
problems. 

To make this error handling more transparently available i am
thinking of having a dynamically wrapped 'os' module which
error-decorates calls into os.*. maybe reachable by "py.os_x" ...
um well, probably better "py.os" :-) 

Now, if we can come up with some real life use cases i am all
for integrating your patch into the py lib nonwithstanding 
some documentation and refactorings (which shouldn't break 
the tests, though, yadda yadda).

cheers and thanks for your ideas and code!

    holger



More information about the Pytest-dev mailing list