[Zope-dev] [Checkins] SVN: zope.traversing/trunk/s Standard cleanup :

Souheil CHELFOUH trollfot at gmail.com
Fri Mar 25 13:32:53 EDT 2011


zope.browserpage is included in the configure.zcml of the "browser" module.
Should we introduce "browser-only" dependencies, for this module, by
adding a 'browser' section in the setup.py requires ?
That would permit people that don't use the "browser" module to have
lighter dependencies, but, at the same time, it's a bit opaque at
first glance.

2011/3/25 Souheil CHELFOUH <souheil at chelfouh.com>:
> Log message for revision 121128:
>  Standard cleanup :
>    - Removed unused imports
>    - Removed unused dependency on zope.tal
>    - Added missing dependency on zope.browserpage
>    - Cosmetics including pep8 normalization
>
>
>
> Changed:
>  U   zope.traversing/trunk/setup.py
>  U   zope.traversing/trunk/src/zope/traversing/adapters.py
>  U   zope.traversing/trunk/src/zope/traversing/api.py
>  U   zope.traversing/trunk/src/zope/traversing/browser/absoluteurl.py
>  U   zope.traversing/trunk/src/zope/traversing/browser/interfaces.py
>  U   zope.traversing/trunk/src/zope/traversing/browser/tests.py
>  U   zope.traversing/trunk/src/zope/traversing/namespace.py
>  U   zope.traversing/trunk/src/zope/traversing/publicationtraverse.py
>  U   zope.traversing/trunk/src/zope/traversing/testing.py
>
> -=-
> Modified: zope.traversing/trunk/setup.py
> ===================================================================
> --- zope.traversing/trunk/setup.py      2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/setup.py      2011-03-25 17:06:56 UTC (rev 121128)
> @@ -36,28 +36,30 @@
>       packages=find_packages('src'),
>       package_dir = {'': 'src'},
>       namespace_packages=['zope',],
> -      extras_require = dict(test=['zope.browserpage',
> -                                  'zope.browserresource[zcml]>=3.12',
> -                                  'zope.component[zcml]',
> -                                  'zope.configuration',
> -                                  'zope.container',
> -                                  'zope.pagetemplate',
> -                                  'zope.security[zcml]>=3.8',
> -                                  'zope.site',
> -                                  'zope.tal >= 3.5.0',
> -                                  'zope.testing',
> -                                  'ZODB3',
> -                                  ]),
> -      install_requires=['setuptools',
> -                        'zope.component',
> -                        'zope.i18n',
> -                        'zope.i18nmessageid',
> -                        'zope.interface',
> -                        'zope.proxy',
> -                        'zope.publisher',
> -                        'zope.security',
> -                        'zope.location>=3.7.0',
> -                        ],
> +      extras_require = dict(test=[
> +          'ZODB3',
> +          'zope.annotation',
> +          'zope.browserresource[zcml]>=3.12',
> +          'zope.component[zcml]',
> +          'zope.configuration',
> +          'zope.container',
> +          'zope.pagetemplate',
> +          'zope.security[zcml]>=3.8',
> +          'zope.site',
> +          'zope.testing',
> +          ]),
> +      install_requires=[
> +          'setuptools',
> +          'zope.browserpage',
> +          'zope.component',
> +          'zope.i18n',
> +          'zope.i18nmessageid',
> +          'zope.interface',
> +          'zope.location>=3.7.0',
> +          'zope.proxy',
> +          'zope.publisher',
> +          'zope.security',
> +          ],
>       include_package_data = True,
>       zip_safe = False,
>       )
>
> Modified: zope.traversing/trunk/src/zope/traversing/adapters.py
> ===================================================================
> --- zope.traversing/trunk/src/zope/traversing/adapters.py       2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/src/zope/traversing/adapters.py       2011-03-25 17:06:56 UTC (rev 121128)
> @@ -16,19 +16,18 @@
>  from types import StringTypes
>
>  import zope.interface
> -import zope.component
>
>  from zope.location.interfaces import ILocationInfo, LocationError
>  from zope.traversing.interfaces import ITraversable, ITraverser
> -
>  from zope.traversing.namespace import namespaceLookup
> -from zope.traversing.namespace import UnexpectedParameters
>  from zope.traversing.namespace import nsParse
>
> -from zope.location.traversing import RootPhysicallyLocatable # BBB
> +from zope.location.traversing import RootPhysicallyLocatable  # BBB
>
> +
>  _marker = object()  # opaque marker that doesn't get security proxied
>
> +
>  class DefaultTraversable(object):
>     """Traverses objects via attribute and item lookup"""
>     zope.interface.implements(ITraversable)
> @@ -49,6 +48,7 @@
>                 pass
>         raise LocationError(subject, name)
>
> +
>  class Traverser(object):
>     """Provide traverse features"""
>
> @@ -119,7 +119,7 @@
>
>     if name == '..':
>         return obj.__parent__
> -
> +
>     if name and name[:1] in '@+':
>         ns, nm = nsParse(name)
>         if ns:
>
> Modified: zope.traversing/trunk/src/zope/traversing/api.py
> ===================================================================
> --- zope.traversing/trunk/src/zope/traversing/api.py    2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/src/zope/traversing/api.py    2011-03-25 17:06:56 UTC (rev 121128)
> @@ -14,7 +14,7 @@
>  """Convenience functions for traversing the object tree.
>  """
>  from zope.interface import moduleProvides
> -from zope.location.interfaces import ILocationInfo, IRoot, LocationError
> +from zope.location.interfaces import ILocationInfo, IRoot
>  from zope.traversing.interfaces import ITraversalAPI, ITraverser
>
>
> @@ -23,6 +23,7 @@
>
>  _marker = object()
>
> +
>  def joinPath(path, *args):
>     """Join the given relative paths to the given path.
>
> @@ -54,16 +55,19 @@
>             raise ValueError("Leading or trailing slashes in path elements")
>     return _normalizePath(path + u'/'.join(args))
>
> +
>  def getPath(obj):
>     """Returns a string representing the physical path to the object.
>     """
>     return ILocationInfo(obj).getPath()
>
> +
>  def getRoot(obj):
>     """Returns the root of the traversal for the given object.
>     """
>     return ILocationInfo(obj).getRoot()
>
> +
>  def traverse(object, path, default=_marker, request=None):
>     """Traverse 'path' relative to the given object.
>
> @@ -86,6 +90,7 @@
>     else:
>         return traverser.traverse(path, default=default, request=request)
>
> +
>  def traverseName(obj, name, default=_marker, traversable=None, request=None):
>     """Traverse a single step 'name' relative to the given object.
>
> @@ -115,11 +120,13 @@
>     else:
>         return obj
>
> +
>  def getName(obj):
>     """Get the name an object was traversed via
>     """
>     return ILocationInfo(obj).getName()
>
> +
>  def getParent(obj):
>     """Returns the container the object was traversed via.
>
> @@ -185,6 +192,7 @@
>
>     return prefix + u'/'.join(new_segments)
>
> +
>  def canonicalPath(path_or_object):
>     """Returns a canonical absolute unicode path for the given path or object.
>
>
> Modified: zope.traversing/trunk/src/zope/traversing/browser/absoluteurl.py
> ===================================================================
> --- zope.traversing/trunk/src/zope/traversing/browser/absoluteurl.py    2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/src/zope/traversing/browser/absoluteurl.py    2011-03-25 17:06:56 UTC (rev 121128)
> @@ -27,11 +27,13 @@
>                        "This is probably due to a bug in setting up location "
>                        "information.")
>
> -_safe = '@+' # Characters that we don't want to have quoted
> +_safe = '@+'  # Characters that we don't want to have quoted
>
> +
>  def absoluteURL(ob, request):
>     return zope.component.getMultiAdapter((ob, request), IAbsoluteURL)()
>
> +
>  class AbsoluteURL(BrowserView):
>     implements(IAbsoluteURL)
>
> @@ -92,7 +94,7 @@
>
>         if sameProxiedObjects(context, request.getVirtualHostRoot()) or \
>                isinstance(context, Exception):
> -            return ({'name':'', 'url': self.request.getApplicationURL()}, )
> +            return ({'name': '', 'url': self.request.getApplicationURL()}, )
>
>         base = tuple(zope.component.getMultiAdapter(
>                 (container, request), IAbsoluteURL).breadcrumbs())
> @@ -110,6 +112,7 @@
>
>         return base
>
> +
>  class SiteAbsoluteURL(BrowserView):
>     implements(IAbsoluteURL)
>
> @@ -138,9 +141,9 @@
>         request = self.request
>
>         if sameProxiedObjects(context, request.getVirtualHostRoot()):
> -            return ({'name':'', 'url': self.request.getApplicationURL()}, )
> +            return ({'name': '', 'url': self.request.getApplicationURL()}, )
>
> -        base = ({'name':'', 'url': self.request.getApplicationURL()}, )
> +        base = ({'name': '', 'url': self.request.getApplicationURL()}, )
>
>         name = getattr(context, '__name__', None)
>         if name:
>
> Modified: zope.traversing/trunk/src/zope/traversing/browser/interfaces.py
> ===================================================================
> --- zope.traversing/trunk/src/zope/traversing/browser/interfaces.py     2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/src/zope/traversing/browser/interfaces.py     2011-03-25 17:06:56 UTC (rev 121128)
> @@ -15,6 +15,7 @@
>  """
>  from zope.interface import Interface
>
> +
>  class IAbsoluteURL(Interface):
>
>     def __unicode__():
> @@ -36,6 +37,7 @@
>         URL is the link for that segment of the breadcrumbs.
>         """
>
> +
>  class IAbsoluteURLAPI(Interface):
>
>     def absoluteURL(ob, request):
>
> Modified: zope.traversing/trunk/src/zope/traversing/browser/tests.py
> ===================================================================
> --- zope.traversing/trunk/src/zope/traversing/browser/tests.py  2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/src/zope/traversing/browser/tests.py  2011-03-25 17:06:56 UTC (rev 121128)
> @@ -31,21 +31,27 @@
>
>  from zope.container.contained import contained
>
> +
>  class IRoot(Interface):
>     pass
>
> +
>  class Root(object):
>     implements(IRoot)
>
> +
>  class TrivialContent(object):
>     """Trivial content object, used because instances of object are rocks."""
>
> +
>  class AdaptedContent(object):
>     """A simple content object that has an ILocation adapter for it."""
> -
> +
> +
>  class FooContent(object):
>     """Class whose location will be provided by an adapter."""
>
> +
>  class FooLocation(object):
>     """Adapts FooAdapter to the ILocation protocol."""
>     implements(ILocation)
> @@ -62,6 +68,7 @@
>     def __parent__(self):
>         return contained(TrivialContent(), Root(), name='bar')
>
> +
>  class TestAbsoluteURL(PlacelessSetup, TestCase):
>
>     def setUp(self):
> @@ -79,7 +86,7 @@
>         # don't define a more specific adapter
>         zope.component.provideAdapter(LocationProxy, (Interface,),
>                                       ILocation)
> -
> +
>     def tearDown(self):
>         PlacelessSetup.tearDown(self)
>
> @@ -121,7 +128,6 @@
>                           {'name': 'c', 'url': 'http://127.0.0.1/a/b/c'},
>                           ))
>
> -
>     def testParentButNoLocation(self):
>         request = TestRequest()
>
> @@ -141,7 +147,7 @@
>         self.assertEqual(str(view), 'http://127.0.0.1/a/b/c')
>         self.assertEqual(absoluteURL(content3, request),
>                          'http://127.0.0.1/a/b/c')
> -
> +
>     def testAdaptedContext(self):
>         request = TestRequest()
>
> @@ -164,17 +170,15 @@
>         # adapter
>         request = TestRequest()
>
> -
>         content = FooContent()
>         content.__parent__ = Root()
>         content.__name__ = 'foo'
> -
> +
>         view = getMultiAdapter((content, request), name='absolute_url')
>         self.assertEqual(str(view), 'http://127.0.0.1/foo')
>         self.assertEqual(absoluteURL(content, request),
>                          'http://127.0.0.1/foo')
>
> -
>     def testBasicContext_unicode(self):
>         #Tests so that AbsoluteURL handle unicode names as well
>         request = TestRequest()
> @@ -289,7 +293,6 @@
>         self.assertEqual(str(view), 'http://127.0.0.1')
>         self.assertEqual(absoluteURL(None, request), 'http://127.0.0.1')
>
> -
>     def testVirtualHostingWithoutContextInformation(self):
>         request = TestRequest()
>         request._vh_root = contained(TrivialContent(), Root(), name='a')
> @@ -301,5 +304,5 @@
>  def test_suite():
>     return makeSuite(TestAbsoluteURL)
>
> -if __name__=='__main__':
> +if __name__ == '__main__':
>     main(defaultTest='test_suite')
>
> Modified: zope.traversing/trunk/src/zope/traversing/namespace.py
> ===================================================================
> --- zope.traversing/trunk/src/zope/traversing/namespace.py      2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/src/zope/traversing/namespace.py      2011-03-25 17:06:56 UTC (rev 121128)
> @@ -21,8 +21,8 @@
>  import zope.interface
>  from zope.i18n.interfaces import IModifiableUserPreferredLanguages
>  from zope.component.interfaces import ComponentLookupError
> -from zope.interface import providedBy, directlyProvides, directlyProvidedBy
> -from zope.location.interfaces import IRoot, LocationError
> +from zope.interface import providedBy, directlyProvides
> +from zope.location.interfaces import LocationError
>  from zope.publisher.interfaces.browser import IBrowserSkinType
>  from zope.publisher.skinnable import applySkin
>  from zope.security.proxy import removeSecurityProxy
> @@ -34,9 +34,11 @@
>  class UnexpectedParameters(LocationError):
>     "Unexpected namespace parameters were provided."
>
> +
>  class ExcessiveDepth(LocationError):
>     "Too many levels of containment. We don't believe them."
>
> +
>  def namespaceLookup(ns, name, object, request=None):
>     """Lookup a value from a namespace
>
> @@ -114,6 +116,7 @@
>
>  namespace_pattern = re.compile('[+][+]([a-zA-Z0-9_]+)[+][+]')
>
> +
>  def nsParse(name):
>     """Parse a namespace-qualified name into a namespace name and a
>     name.  Returns the namespace name and a name.
> @@ -154,12 +157,14 @@
>
>     return ns, name
>
> +
>  def getResource(site, name, request):
>     resource = queryResource(site, name, request)
>     if resource is None:
>         raise LocationError(site, name)
>     return resource
>
> +
>  def queryResource(site, name, request, default=None):
>     resource = zope.component.queryAdapter(request, name=name)
>     if resource is None:
> @@ -174,6 +179,7 @@
>
>     return resource
>
> +
>  # ---- namespace processors below ----
>
>  class SimpleHandler(object):
> @@ -194,6 +200,7 @@
>         """
>         self.context = context
>
> +
>  class acquire(SimpleHandler):
>     """Traversal adapter for the acquire namespace
>     """
> @@ -262,6 +269,7 @@
>
>         raise ExcessiveDepth(self.context, name)
>
> +
>  class attr(SimpleHandler):
>
>     def traverse(self, name, ignored):
> @@ -277,6 +285,7 @@
>         """
>         return getattr(self.context, name)
>
> +
>  class item(SimpleHandler):
>
>     def traverse(self, name, ignored):
> @@ -291,6 +300,7 @@
>            """
>         return self.context[name]
>
> +
>  class etc(SimpleHandler):
>
>     def traverse(self, name, ignored):
> @@ -330,6 +340,7 @@
>
>         return view
>
> +
>  class resource(view):
>
>     def traverse(self, name, ignored):
> @@ -337,6 +348,7 @@
>         # resource, which is needed to generate the absolute URL.
>         return getResource(self.context, name, self.request)
>
> +
>  class lang(view):
>
>     def traverse(self, name, ignored):
> @@ -345,6 +357,7 @@
>         languages.setPreferredLanguages([name])
>         return self.context
>
> +
>  class skin(view):
>
>     def traverse(self, name, ignored):
> @@ -356,6 +369,7 @@
>         applySkin(self.request, skin)
>         return self.context
>
> +
>  class vh(view):
>
>     def traverse(self, name, ignored):
> @@ -511,7 +525,7 @@
>                     # if we want to enable tracebacks when also trying to
>                     # debug a different skin?
>                     skin = zope.component.getUtility(IBrowserSkinType, 'Debug')
> -                    directlyProvides(request, providedBy(request)+skin)
> +                    directlyProvides(request, providedBy(request) + skin)
>                 else:
>                     raise ValueError("Unknown debug flag: %s" % flag)
>             return self.context
>
> Modified: zope.traversing/trunk/src/zope/traversing/publicationtraverse.py
> ===================================================================
> --- zope.traversing/trunk/src/zope/traversing/publicationtraverse.py    2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/src/zope/traversing/publicationtraverse.py    2011-03-25 17:06:56 UTC (rev 121128)
> @@ -25,6 +25,7 @@
>  from zope.publisher.interfaces import IPublishTraverse
>  from zope.publisher.interfaces.browser import IBrowserPublisher
>
> +
>  class PublicationTraverser(object):
>     """Traversal used for publication.
>
> @@ -45,7 +46,7 @@
>         return ProxyFactory(ob)
>
>     def traverseName(self, request, ob, name):
> -        nm = name # the name to look up the object with
> +        nm = name  # the name to look up the object with
>
>         if name and name[:1] in '@+':
>             # Process URI segment parameters.
> @@ -92,9 +93,9 @@
>         # Remove double dots
>         while '..' in path:
>             l = path.index('..')
> -            if l < 0 or l+2 > len(path):
> +            if l < 0 or l + 2 > len(path):
>                 break
> -            del path[l:l+2]
> +            del path[l:l + 2]
>
>         pop = path.pop
>
> @@ -119,9 +120,11 @@
>
>             ob = self.traversePath(request, ob, path)
>
> +
>  # alternate spelling
>  PublicationTraverse = PublicationTraverser
>
> +
>  class PublicationTraverserWithoutProxy(PublicationTraverse):
>
>     def proxy(self, ob):
>
> Modified: zope.traversing/trunk/src/zope/traversing/testing.py
> ===================================================================
> --- zope.traversing/trunk/src/zope/traversing/testing.py        2011-03-25 16:29:46 UTC (rev 121127)
> +++ zope.traversing/trunk/src/zope/traversing/testing.py        2011-03-25 17:06:56 UTC (rev 121128)
> @@ -28,6 +28,7 @@
>  from zope.traversing.browser.interfaces import IAbsoluteURL
>  from zope.traversing.namespace import etc
>
> +
>  def setUp():
>     zope.component.provideAdapter(Traverser, (None,), ITraverser)
>     zope.component.provideAdapter(DefaultTraversable, (None,), ITraversable)
> @@ -50,6 +51,7 @@
>     zope.component.provideAdapter(factory, (for_, IDefaultBrowserLayer),
>                                   providing, name=name)
>
> +
>  def browserResource(name, factory, providing=zope.interface.Interface):
>     zope.component.provideAdapter(factory, (IDefaultBrowserLayer,),
>                                   providing, name=name)
>
> _______________________________________________
> checkins mailing list
> checkins at zope.org
> https://mail.zope.org/mailman/listinfo/checkins
>


More information about the Zope-Dev mailing list