[PEAK] config.fileNearModule() in peak.ini

Phillip J. Eby pje at telecommunity.com
Wed Apr 20 12:14:07 EDT 2005


At 05:05 PM 04/20/2005 +0300, Yaroslav Samchuk wrote:
>Yaroslav Samchuk wrote:
>>Yesterday I tried to execute application, which uses `peak.web` and is 
>>distributed using py2exe. And noticed, that there were some problems 
>>zip-importing `peak.web/resource_defaults.ini`.
>
>And one more interesting thing. Trying to access any undefined resource, I 
>always get an exception (traceback is attached to this mail), which is 
>raised, cuz `os.listdir` can't list files in archives. Temporary, I had 
>fixed peak/web/resources.py, until you'll do something there. On the off 
>chance, a patch with my changes is also attached to this mail.

The correct fix will be to add a "glob_resources" facility to the 
pkg_resources module, so that the os.listdir can be replaced with something 
that can read zipfile directory entries.  So, for now you may want to just 
go ahead and use your patch.  I can't use it for PEAK because the list is 
used to support extension polymorphism.  That is, if you request resource 
"foo", PEAK searches for any resource that is "foo" plus an 
extension.  This means that your URLs do not become invalid if you change 
from using PWT or ZPT to a static HTML file or vice versa.

However, in order to provide this feature PEAK can't just try extensions 
until it finds a match, it has to instead search the resources that are 
present.  So, I'm going to need to add a glob feature to pkg_resources in 
order to support this.  At the moment, pkg_resources isn't even a part of 
PEAK so it's probably going to be a while before I can get this right.




>--
>Best wishes,
>Yaroslav
>
>
>Traceback (most recent call last):
>   File "wsgiref\handlers.pyo", line 92, in run
>   File "peak\web\publish.pyo", line 233, in __call__
>   File "peak\web\publish.pyo", line 258, in _handle_http
>   File "peak\web\publish.pyo", line 138, in handleException
>   File "peak\web\errors.pyo", line 64, in handleException
>   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112, in 
> _once.BaseDescriptor.__get__
>   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100, in 
> _once.__get__
>   File "peak\binding\once.pyo", line 539, in <lambda>
>   File "peak\web\errors.pyo", line 31, in template
>   File "peak\web\skins.pyo", line 101, in getResource
>   File "peak\web\publish.pyo", line 68, in traverse
>   File "peak\web\environ.pyo", line 229, in traverseName
>   File "peak\web\places.pyo", line 51, in traverseTo
>   File "peak\web\environ.pyo", line 387, in traverseDefault
>   File "peak\web\environ.pyo", line 348, in traverseItem
>   File "peak\web\resources.pyo", line 125, in __getitem__
>   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112, in 
> _once.BaseDescriptor.__get__
>   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100, in 
> _once.__get__
>   File "peak\binding\once.pyo", line 539, in <lambda>
>   File "peak\web\resources.pyo", line 109, in filenames
>WindowsError: [Errno 3] The system cannot find the path specified: 
>'E:\\TEMP\\web_test\\bin\\library.dat\\peak\\web/*.*'
>--- resources.py.bak    2005-04-20 14:53:59.000000000 +0300
>+++ resources.py        2005-04-20 17:01:03.906250000 +0300
>@@ -106,7 +106,24 @@
>
>      def filenames(self):    # XXX need a way to invalidate this!
>          nms = {}
>-        for filename in os.listdir(self.filename):
>+        import errno
>+        if sys.platform == "win32":
>+            # os.listdir raises WindowsError on win32
>+            exc = WindowsError
>+            expectErrno = errno.ESRCH
>+        else:
>+            # and OSError on linux
>+            # XXX: I don't know what happens on other platforms
>+            exc = OSError
>+            expectErrno = errno.ENOENT
>+        try:
>+            names = os.listdir(self.filename)
>+        except exc, err:
>+            # XXX: reraise always if we aren't zip-imported?
>+            if err.errno == expectErrno:
>+                return nms
>+            raise
>+        for filename in names:
>              if filename in ('.','..'):
>                  continue
>              parts = filename.split('.')




More information about the PEAK mailing list