Skip to content

Commit

Permalink
Small speed-ups, avoid raising two exceptions during traversal.
Browse files Browse the repository at this point in the history
This removes two exceptions and one import-lock from the normal
traversal logic used in the WSGI publisher.
  • Loading branch information
hannosch committed Sep 10, 2017
1 parent 3ba1b54 commit aecf344
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/OFS/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def Redirect(self, destination, URL1):
ZopeRedirect = Redirect

def __bobo_traverse__(self, REQUEST, name=None):
if name is None:
# Make this more explicit, otherwise getattr(self, name)
# would raise a TypeErorr getattr(): attribute name must be string
return None

if name == 'Control_Panel':
return APP_MANAGER.__of__(self)
try:
Expand Down
5 changes: 1 addition & 4 deletions src/OFS/ObjectManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,8 @@ def __getitem__(self, key):
method = request.get('REQUEST_METHOD', 'GET')
if (request.maybe_webdav_client and
method not in ('GET', 'POST')):
try:
if bbb.HAS_ZSERVER:
from webdav.NullResource import NullResource
except ImportError:
pass
else:
return NullResource(self, key, request).__of__(self)
raise KeyError(key)

Expand Down
24 changes: 11 additions & 13 deletions src/ZPublisher/BaseRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from Acquisition import aq_base, aq_inner
from Acquisition.interfaces import IAcquirer
from ExtensionClass import Base
import pkg_resources
from six.moves.urllib.parse import quote as urllib_quote
from zExceptions import Forbidden
from zExceptions import NotFound
Expand All @@ -36,19 +35,15 @@
from zope.traversing.namespace import namespaceLookup
from zope.traversing.namespace import nsParse

from App.bbb import HAS_ZSERVER
from ZPublisher.Converters import type_converters
from ZPublisher.interfaces import UseTraversalDefault

HAS_ZSERVER = True
try:
dist = pkg_resources.get_distribution('ZServer')
except pkg_resources.DistributionNotFound:
HAS_ZSERVER = False

if HAS_ZSERVER:
from ZServer.ZPublisher.xmlrpc import is_xmlrpc_response
else:
def is_xmlrpc_response(response):
return False
else:
from ZServer.ZPublisher.xmlrpc import is_xmlrpc_response

_marker = []
UNSPECIFIED_ROLES = ''
Expand Down Expand Up @@ -418,8 +413,11 @@ def traverse(self, path, response=None, validated_hook=None):
# to possibly traverse to an alternate top-level object.
if hasattr(object, '__bobo_traverse__'):
try:
object = object.__bobo_traverse__(request)
self.roles = getRoles(None, None, object, UNSPECIFIED_ROLES)
new_object = object.__bobo_traverse__(request)
if new_object is not None:
object = new_object
self.roles = getRoles(None, None, object,
UNSPECIFIED_ROLES)
except Exception:
pass

Expand All @@ -444,9 +442,9 @@ def traverse(self, path, response=None, validated_hook=None):
self._post_traverse = post_traverse = []

# import time ordering problem
try:
if HAS_ZSERVER:
from webdav.NullResource import NullResource
except ImportError:
else:
NullResource = None

entry_name = ''
Expand Down

0 comments on commit aecf344

Please sign in to comment.