[Zope-CVS] CVS: Packages/HTTPMounter - HTTPMounter.py:1.15
Andreas Jung
andreas@digicool.com
Thu, 6 Jun 2002 10:11:56 -0400
Update of /cvs-repository/Packages/HTTPMounter
In directory cvs.zope.org:/tmp/cvs-serv11378
Modified Files:
HTTPMounter.py
Log Message:
- HTTP requesting code refactored
- added support to traverse a HTTPMounter instance using slicing.
=== Packages/HTTPMounter/HTTPMounter.py 1.14 => 1.15 ===
self._v_traversal = [] # keep path information relative to the mountpoint
+
def __bobo_traverse__(self, request, entry_name):
""" fool Zope traversal - hehehe"""
@@ -78,25 +79,10 @@
# So we first retrieve the object we collected
# traversal information from.
- tup = urlparse.urlparse(self.url)
- host = tup[1]
- path = tup[2]
- if path[-1] != '/': path = path + '/'
- path = path + string.join(self._v_traversal, '/')
-
- tries = 0
- while tries < MAX_TRIES:
-
- try:
- self._http_request(host, path)
- self._v_traversal = []
- return getattr(self, entry_name)
-
- except IOError:
- tries = tries + 1
- time.sleep(TIME2SLEEP)
-
- raise IOError
+ self.doRequest( string.join(self._v_traversal, '/') )
+ self._v_traversal = []
+
+ return getattr(self, entry_name)
else:
@@ -119,6 +105,31 @@
if REQUEST['URL1'][- len(self.id):] == self.id:
sub_path = sub_path + self.default_document
+ self.doRequest(sub_path)
+
+ # get headers from original response and fake them into
+ # our response to the web client
+ for k in ('content-type','content-length','etag','last-modified'):
+ v = self._v_headers.getheader(k)
+ if v: RESPONSE.setHeader(k,v)
+
+ RESPONSE.write( self.getContent() )
+
+ return
+
+
+ def __getitem__(self, item):
+ # check if we have the relative traversal stack
+ if not hasattr(self, '_v_traversal'):
+ self._v_traversal = []
+
+ self._v_traversal.append(item)
+ return self
+
+
+
+ def doRequest(self, sub_path):
+
tries = 0
while tries<MAX_TRIES:
@@ -129,25 +140,19 @@
if path[-1] != '/': path = path + '/'
path = path + sub_path
- status, data, headers = self._http_request(host, path)
-
- # get headers from original response and fake them into
- # our response to the web client
- for k in ('content-type','content-length','etag','last-modified'):
- v = headers.getheader(k)
- if v: RESPONSE.setHeader(k,v)
- RESPONSE.write(data)
+ self._http_request(host, path)
return
except IOError:
tries = tries + 1
time.sleep(TIME2SLEEP)
- return IOError
+ raise IOError
index_html = __call__
+
def _http_request(self, host, path):
""" get URL """
@@ -160,12 +165,22 @@
H.endheaders()
status, msg, headers = H.getreply()
+
+ self._v_status = status
+ self._v_msg = msg
+ self._v_headers = headers
self._v_content = H.getfile().read()
- return (status, self._v_content, headers)
+ return
+
def getContent(self):
""" returns content"""
+
+ if not hasattr(self, '_v_content'):
+ self.doRequest( string.join(self._v_traversal, '/') )
+
+ self._v_traversal = []
return self._v_content