[Zope3-checkins] CVS: Zope3/lib/python/Zope/Publisher - BaseRequest.py:1.7
Jeremy Hylton
jeremy@zope.com
Wed, 17 Jul 2002 18:55:23 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher
In directory cvs.zope.org:/tmp/cvs-serv1057/Zope/Publisher
Modified Files:
BaseRequest.py
Log Message:
Refactor __setupPath().
HTTPRequest and VFSRequest had almost identical methods, so move the
duplicate code up into the base class. Both version s had the same
bug: Raising an exception that was not defined. XXX Fixed this by
replacing with reference to Zope.Exceptions.NotFoundError.
XXX Also remove test of _streaming, since it isn't defined.
=== Zope3/lib/python/Zope/Publisher/BaseRequest.py 1.6 => 1.7 ===
from RequestDataProperty import RequestDataProperty, RequestDataMapper
from cStringIO import StringIO
+from Zope.Exceptions import NotFoundError
+
class IRequest(IPublisherRequest, IPublicationRequest, IApplicationRequest):
"""The basic request contract
"""
@@ -207,7 +209,7 @@
if body is None:
s = self._body_instream
if s is None:
- return default
+ return None # XXX what should be returned here?
p = s.tell()
s.seek(0)
body = s.read()
@@ -297,7 +299,28 @@
return '<%s instance at 0x%x, URL=%s>' % (
str(self.__class__), id(self), `self.URL`)
+ def _setupPath_helper(self, attr):
+ path = self.get(attr, "/").strip()
+ if path.endswith('/'):
+ path = path[:-1] # XXX Why? Not sure
+ self._endswithslash = 1
+ else:
+ self._endswithslash = 0
+
+ clean = []
+ for item in path.split('/'):
+ if not item or item == '.':
+ continue
+ elif item == '..':
+ try: del clean[-1]
+ except IndexError:
+ raise NotFoundError('..')
+ else: clean.append(item)
+
+ clean.reverse()
+ self.setTraversalStack(clean)
+ self._path_suffix = None
class TestRequest(BaseRequest):