[Zope-CVS] CVS: Packages/HTTPMounter - HTTPMounter.py:1.13
Andreas Jung
andreas@digicool.com
Thu, 30 May 2002 09:13:53 -0400
Update of /cvs-repository/Packages/HTTPMounter
In directory cvs.zope.org:/tmp/cvs-serv30958
Modified Files:
HTTPMounter.py
Log Message:
- added retry loop
- code cleanup
- added comments and more docs
=== Packages/HTTPMounter/HTTPMounter.py 1.12 => 1.13 ===
class HTTPMounter(Persistent, Implicit, SimpleItem):
- """ The HTTPMounter product acts like a dump LocalFS and mounts
- another HTTP into a running Zope instance.
+ """ The HTTPMounter product acts like a dumb LocalFS and mounts
+ another HTTP server into a Zope instance.
+
+ Accessing content directly through direct traversal:
+
+ /foo/http_mounter_mountpoint/relative/remote/path/bar.txt
+
+ or inside an acquired object
+
+ /foo/http_mounter_mountpoint/relative/remote/path/bar.txt/render_html
+
+ where render_html might containt <dtml-var getContent> to access
+ the content of bar.txt
+
"""
meta_type = 'HTTPMounter'
@@ -47,31 +59,50 @@
self.id = id
self.title = title
self.url = url
- self._v_traversal = []
+ self._v_traversal = [] # keep path information relative to the mountpoint
def __bobo_traverse__(self, request, entry_name):
""" fool Zope traversal - hehehe"""
- if not hasattr(self, '_v_traversal'):
+ # check if we have the relative traversal stack
+ if not hasattr(self, '_v_traversal'):
self._v_traversal = []
+ # check for our ZMI management methods
if entry_name in ('manage_main','manage_workspace', 'manage_preferences'):
return self
if hasattr(self, entry_name):
+ # We need to return an acquired object !
+ # 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, '/')
- self._http_request(host, path)
- self._v_traversal = []
+ tries = 0
+ while tries < MAX_TRIES:
- return getattr(self, entry_name)
+ try:
+ self._http_request(host, path)
+ self._v_traversal = []
+ return getattr(self, entry_name)
+
+ except IOError:
+ tries = tries + 1
+ time.sleep(TIME2SLEEP)
+
+ raise IOError
else:
+
+ # we don't have acquire an object, so we
+ # collect the traversal information until we need it.
+
self._v_traversal.append(entry_name)
return self
@@ -99,6 +130,9 @@
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)
@@ -112,6 +146,8 @@
return IOError
+ index_html = __call__
+
def _http_request(self, host, path):
""" get URL """
@@ -143,7 +179,6 @@
RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=Settings%20saved')
- index_html = __call__
manage_workspace = DTMLFile("dtml/manageHTTPMounter",globals())