Commit 482a309b authored by Nikolay Kim's avatar Nikolay Kim

micro optimizations

parent 4dc2e280
......@@ -144,8 +144,9 @@ class PropertyManager(Base, ElementWithAttributes):
Returns the optional second argument or None if no such property is
found.
"""
if self.hasProperty(id):
return getattr(self, id)
for p in self._properties:
if id==p['id']:
return getattr(self, id)
return d
security.declareProtected(access_contents_information, 'getPropertyType')
......
......@@ -39,6 +39,7 @@ from zope.traversing.namespace import namespaceLookup
from zope.traversing.namespace import nsParse
_marker = object()
NullResource = None
class Traversable:
......@@ -142,30 +143,29 @@ class Traversable:
If true, then all of the objects along the path are validated with
the security machinery. Usually invoked using restrictedTraverse().
"""
from webdav.NullResource import NullResource
if not path:
return self
if isinstance(path, str):
if type(path) is str:
# Unicode paths are not allowed
path = path.split('/')
else:
path = list(path)
REQUEST = {'TraversalRequestNameStack': path}
path.reverse()
#path.reverse()
path_pop = path.pop
if len(path) > 1 and not path[0]:
if len(path) > 1 and not path[-1]:
# Remove trailing slash
path_pop(0)
path_pop()
if restricted:
validate = getSecurityManager().validate
if not path[-1]:
if not path[0]:
# If the path starts with an empty string, go to the root first.
path_pop()
path_pop(0)
obj = self.getPhysicalRoot()
if restricted:
validate(None, None, None, obj) # may raise Unauthorized
......@@ -174,8 +174,7 @@ class Traversable:
resource = _marker
try:
while path:
name = path_pop()
for name in path:
__traceback_info__ = path, name
if name[0] == '_':
......@@ -190,7 +189,7 @@ class Traversable:
obj = next
continue
bobo_traverse = getattr(obj, '__bobo_traverse__', None)
bobo_traverse = None
try:
if name and name[:1] in '@+' and name != '+' and nsParse(name)[1]:
# Process URI segment parameters.
......@@ -209,6 +208,7 @@ class Traversable:
else:
next = UseTraversalDefault # indicator
try:
bobo_traverse = getattr(obj, '__bobo_traverse__', None)
if bobo_traverse is not None:
next = bobo_traverse(REQUEST, name)
if restricted:
......@@ -256,6 +256,10 @@ class Traversable:
# The item lookup may return a NullResource,
# if this is the case we save it and return it
# if all other lookups fail.
global NullResource
if NullResource is None:
from webdav.NullResource import NullResource
if isinstance(next, NullResource):
resource = next
raise KeyError(name)
......
......@@ -332,7 +332,7 @@ class HTTPRequest(BaseRequest):
self.environ = environ
get_env = environ.get
self.response = response
other = self.other = {'RESPONSE': response}
other = self.other = {'REQUEST': self, 'RESPONSE': response}
self.form = {}
self.taintedform = {}
self.steps = []
......@@ -379,9 +379,8 @@ class HTTPRequest(BaseRequest):
while b and b[0] == '/':
b = b[1:]
server_url = get_env('SERVER_URL',None)
if server_url is not None:
other['SERVER_URL'] = server_url = server_url.strip()
if 'SERVER_URL' in environ:
other['SERVER_URL'] = server_url = environ['SERVER_URL'].strip()
else:
if 'HTTPS' in environ and (
environ['HTTPS'] == "on" or environ['HTTPS'] == "ON"):
......@@ -1255,8 +1254,6 @@ class HTTPRequest(BaseRequest):
""" #"
other = self.other
if key in other:
if key == 'REQUEST':
return self
return other[key]
if key[:1] == 'U':
......@@ -1266,7 +1263,7 @@ class HTTPRequest(BaseRequest):
path = self._script + self._steps
n = len(path) - int(n)
if n < 0:
raise KeyError, key
return default
if pathonly:
path = [''] + path[:n]
else:
......@@ -1284,9 +1281,6 @@ class HTTPRequest(BaseRequest):
return environ[key]
return ''
if key == 'REQUEST':
return self
if key[:1] == 'B':
match = BASEmatch(key)
if match is not None:
......@@ -1296,7 +1290,7 @@ class HTTPRequest(BaseRequest):
if n:
n = n - 1
if len(path) < n:
raise KeyError, key
return default
v = self._script + path[:n]
else:
......@@ -1394,12 +1388,10 @@ class HTTPRequest(BaseRequest):
self._lazies[key] = callable
def has_key(self, key, returnTaints=0):
try:
self.__getitem__(key, returnTaints=returnTaints)
except:
return 0
else:
return 1
v = self.get(key, _marker, returnTaints=returnTaints)
if v is _marker:
return False
return True
def keys(self, returnTaints=0):
keys = {}
......@@ -1525,7 +1517,7 @@ class HTTPRequest(BaseRequest):
base64.decodestring(auth.split()[-1]).split(':', 1)
return name, password
def taintWrapper(self, enabled=TAINTING_ENABLED):
def taintWrapper(self, enabled=False):
return enabled and TaintRequestWrapper(self) or self
def shiftNameToApplication(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment