[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP - HTTPRequest.py:1.1.2.2
Shane Hathaway
shane@digicool.com
Thu, 15 Nov 2001 10:14:58 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP
In directory cvs.zope.org:/tmp/cvs-serv456/HTTP
Modified Files:
Tag: Zope-3x-branch
HTTPRequest.py
Log Message:
- Changed name of URLn and BASEn methods for clarity
- Used better __getitem__(), get(), has_key() pattern
- Added URL to __str__() and text(), removed override of __repr__()
=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPRequest.py 1.1.2.1 => 1.1.2.2 ===
DEFAULT_PORTS = {'http': '80', 'https': '443'}
-_marker=[]
+URLmatch=re.compile('URL(PATH)?([0-9]+)$').match
+BASEmatch=re.compile('BASE(PATH)?([0-9]+)$').match
+
+_marker = []
+
class HTTPRequest(BaseRequest):
"""
@@ -142,10 +146,10 @@
path = filter(None, path.split('/'))
self._script[:] = map(quote, path)
del self.quoted_steps[:]
- parents = self.PARENTS
+ traversed = self.traversed
if hard:
- del parents[:-1]
- self.other['VirtualRootPhysicalPath'] = parents[-1].getPhysicalPath()
+ del traversed[:-1]
+ self.other['VirtualRootPhysicalPath'] = traversed[-1].getPhysicalPath()
self._resetURLs()
def physicalPathToVirtualPath(self, path):
@@ -663,7 +667,7 @@
return environ.get(name, default)
- def URLn(self, key, n, pathonly):
+ def computeURLn(self, key, n, pathonly):
path = self._script + self.quoted_steps
n = len(path) - n
if n < 0:
@@ -677,7 +681,7 @@
return res
- def BASEn(self, key, n, pathonly):
+ def computeBASEn(self, key, n, pathonly):
path = self.quoted_steps
if n:
n = n - 1
@@ -695,11 +699,7 @@
return res
- def __getitem__(self,key,
- default=_marker,
- URLmatch=re.compile('URL(PATH)?([0-9]+)$').match,
- BASEmatch=re.compile('BASE(PATH)?([0-9]+)$').match,
- ):
+ def get(self, key, default=None):
"""
Gets a variable value
@@ -722,7 +722,13 @@
match = URLmatch(key)
if match is not None:
pathonly, n = match.groups()
- return self.URLn(key, int(n), pathonly)
+ return self.computeURLn(key, int(n), pathonly)
+
+ if key[:1]=='B':
+ match = BASEmatch(key)
+ if match is not None:
+ pathonly, n = match.groups()
+ return self.computeBASEn(key, int(n), pathonly)
if isCGI_NAME(key) or key[:5] == 'HTTP_':
environ=self.environ
@@ -730,30 +736,22 @@
return environ[key]
return ''
- if key[:1]=='B':
- match = BASEmatch(key)
- if match is not None:
- pathonly, n = match.groups()
- return self.BASEn(key, int(n), pathonly)
-
if v is _marker:
v = self.common.get(key, _marker)
+ return default
- if default is not _marker:
- return default
- else:
+ def __getitem__(self, key):
+ res = self.get(key, _marker)
+ if res is _marker:
raise KeyError, key
-
- def get(self, key, default=None):
- return self.__getitem__(key, default)
+ else:
+ return res
def has_key(self, key):
- try: self[key]
- except: return 0
- else: return 1
+ return self.get(key, _marker) is not _marker
def keys(self):
- keys = {}
+ keys = {'URL':1}
keys.update(self.common)
for key in self.environ.keys():
@@ -781,7 +779,8 @@
return keys
def __str__(self):
- result="<h3>form</h3><table>"
+ result = "<p>URL: %s</p>" % self.URL
+ result = result + "<h3>form</h3><table>"
row='<tr valign="top" align="left"><th>%s</th><td>%s</td></tr>'
for k,v in self.form.items():
result=result + row % (escape(k), escape(repr(v)))
@@ -808,10 +807,9 @@
result=result + row % (escape(k), escape(repr(v)))
return result+"</table>"
- __repr__=__str__
-
def text(self):
- result="FORM\n\n"
+ result = "URL: %s\n" % self.URL
+ result = result + "FORM\n\n"
row='%-20s %s\n'
for k,v in self.form.items():
result=result + row % (k, repr(v))