[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/Browser - BrowserRequest.py:1.1.2.3
Jim Fulton
jim@zope.com
Mon, 25 Mar 2002 18:31:12 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/Browser
In directory cvs.zope.org:/tmp/cvs-serv31034/Zope/Publisher/Browser
Modified Files:
Tag: Zope3-publisher-refactor-branch
BrowserRequest.py
Log Message:
Refactord BaseRequest/BaseResponse and HTTPRequest/Response some more:
- Use slots so I can keep track of what's going on. ;)
- Use properties for environment, cookies, headers, URLs.
- Put URL responsibilities in HTTPRequest.
- Have HTTP traverse delegate to and augment Base traverse.
=== Zope3/lib/python/Zope/Publisher/Browser/BrowserRequest.py 1.1.2.2 => 1.1.2.3 ===
super(BrowserRequest, self).__init__(body_instream, outstream, environ)
-
- get_env = environ.get
-
- self.__steps = []
- self.__quoted_steps = []
self.__form = {}
- ################################################################
- # Get base info first. This isn't likely to cause
- # errors and might be useful to error handlers.
- base = script = get_env('SCRIPT_NAME','').strip()
-
- # _script and the other _names are meant for URL construction
- self.__script = map(quote, filter(None, script.split('/')))
-
- # Remove trailing /'s
- while base and base.endswith('/'):
- base = base[:-1]
-
- # strip off last element of the URL
- p = base.rfind('/')
- if p >= 0:
- base = base[:p+1]
- else:
- base = ''
-
- # strip off leading /'s
- while base and base.startswith('/'):
- base = base[1:]
-
- # get server URL and store it too, since we are already looking it up
- server_url = get_env('SERVER_URL', None)
- if server_url is not None:
- self.__server_url = server_url = server_url.strip()
- else:
- server_url = self._deduceServerURL()
-
- if server_url.endswith('/'):
- server_url = server_url[:-1]
-
- # put the complete base URL together
- if base:
- self.base = "%s/%s" % (server_url, base)
- else:
- self.base = server_url
-
- # strip off leading /'s of script
- while script.startswith('/'):
- script = script[1:]
-
- # put the script URL together
- if script:
- script = "%s/%s" % (server_url,script)
- else:
- script = server_url
-
- self.URL = self.script = script
-
-
############################################################
# Implementation methods for interface
# Zope.Publisher.Browser.IBrowserRequest.IBrowserRequest
@@ -251,16 +194,6 @@
######################################
# from: Zope.Publisher.IPublisherRequest.IPublisherRequest
- # This method is not part of the interface.
- def _afterTraversal(self):
- '''Do whatever needs to be done after an object traveral'''
- parents = self.traversed
- parents.pop()
- parents.reverse()
- self.other['PARENTS'] = tuple(parents)
- self.other['PUBLISHED'] = self.traversed[-1]
-
-
def processInputs(self):
'See Zope.Publisher.IPublisherRequest.IPublisherRequest'
@@ -598,6 +531,30 @@
self.setPathSuffix((meth,))
+
+
+ ######################################
+ # from: Zope.Publisher.IPublisherRequest.IPublisherRequest
+ def traverse(self, object):
+ 'See Zope.Publisher.IPublisherRequest.IPublisherRequest'
+
+ ob = super(BrowserRequest, self).traverse(object)
+ if self._path_suffix:
+ # We had a :method variable, so we need to set the base,
+ # but we don't look for default documents any more.
+ base_needed = 1
+ elif self._environ.get('REQUEST_METHOD', 'GET').upper() == 'GET':
+ # We need to check for default documents
+ publication = self.getPublication()
+ ob, add_steps = publication.getDefaultTraversal(self, ob)
+ while add_steps:
+ base_needed = 1
+ ob = super(BrowserRequest, self).traverse(object)
+ ob, add_steps = publication.getDefaultTraversal(self, ob)
+ else:
+ base_needed = 0
+
+
######################################
# from: Interface.Common.Mapping.IEnumerableMapping
@@ -687,29 +644,6 @@
del self.other[x]
self._computed_urls = ()
-
- def _deduceServerURL(self):
- environ = self.environ
- have_env = environ.has_key
-
- if have_env('HTTPS') and (
- environ['HTTPS'] == "on" or environ['HTTPS'] == "ON"):
- protocol = 'https'
-
- elif (have_env('SERVER_PORT_SECURE') and
- environ['SERVER_PORT_SECURE'] == "1"):
- protocol = 'https'
- else: protocol = 'http'
-
- if have_env('HTTP_HOST'):
- host = environ['HTTP_HOST'].strip()
- hostname, port = splitport(host)
-
- else:
- hostname = environ.get('SERVER_NAME', '').strip()
- port = environ.get('SERVER_PORT', '')
- self.setServerURL(protocol=protocol, hostname=hostname, port=port)
- return self.getServerURL()
_key_handlers = BaseRequest._key_handlers.copy()