Skip to content

Commit

Permalink
Flake8.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed May 14, 2020
1 parent 29a26d8 commit bfc78ca
Show file tree
Hide file tree
Showing 25 changed files with 276 additions and 260 deletions.
6 changes: 3 additions & 3 deletions src/zope/app/publication/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
This module implements browser-specific publication and traversal components
for the publisher.
"""
__docformat__ = 'restructuredtext'

from zope.component import queryMultiAdapter
from zope.publisher.interfaces.browser import IBrowserPublisher

from zope.app.publication.http import BaseHTTPPublication

from zope.traversing.publicationtraverse import PublicationTraverser #BBB import
from zope.traversing.publicationtraverse import PublicationTraverser # noqa: F401 E501 (BBB and long line)


class BrowserPublication(BaseHTTPPublication):
"""Web browser publication handling."""
Expand All @@ -47,6 +46,7 @@ def afterCall(self, request, ob):
if request.method == 'HEAD':
request.response.setResult('')


# For now, have a factory that returns a singleton
class PublicationFactory(object):

Expand Down
2 changes: 0 additions & 2 deletions src/zope/app/publication/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
##############################################################################
"""Test FTP Publication.
"""
__docformat__ = 'restructuredtext'
import zope.component

from zope.publisher.interfaces import NotFound
Expand All @@ -22,7 +21,6 @@
from zope.app.publication.zopepublication import ZopePublication



class FTPPublication(ZopePublication):
"""The Publication will do all the work for the FTP"""

Expand Down
7 changes: 1 addition & 6 deletions src/zope/app/publication/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@
##############################################################################
"""HTTP Publication
"""

__docformat__ = 'restructuredtext'

from zope.interface import Attribute
from zope.interface import implements
from zope.publisher.interfaces.http import IHTTPException
from zope.publisher.interfaces.http import MethodNotAllowed
from zope.publisher.publish import mapply
import zope.component

from zope.app.publication.zopepublication import ZopePublication

from zope.publisher.interfaces.http import IMethodNotAllowed #BBB import
from zope.publisher.interfaces.http import IMethodNotAllowed # noqa: F401 E501 (BBB and long line)


class BaseHTTPPublication(ZopePublication):
Expand Down
21 changes: 13 additions & 8 deletions src/zope/app/publication/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
##############################################################################
"""Publication Interfaces
"""
__docformat__ = 'restructuredtext'

from zope import interface

# BBB: Re-import symbols to their old location.
from zope.publisher.interfaces import IEndRequestEvent
from zope.publisher.interfaces import EndRequestEvent
from zope.traversing.interfaces import IBeforeTraverseEvent
from zope.traversing.interfaces import BeforeTraverseEvent
from zope.publisher.interfaces import IEndRequestEvent # noqa: F401 (BBB)
from zope.publisher.interfaces import EndRequestEvent # noqa: F401 (BBB)
from zope.traversing.interfaces import IBeforeTraverseEvent # noqa: F401 (BBB)
from zope.traversing.interfaces import BeforeTraverseEvent # noqa: F401 (BBB)


class IPublicationRequestFactory(interface.Interface):
Expand All @@ -33,24 +31,30 @@ def __call__(input_stream, env):
A request is created and configured with a publication object.
"""


class IRequestFactory(interface.Interface):

def __call__(input_stream, env):
"""Create a request object to handle input."""


class ISOAPRequestFactory(IRequestFactory):
"""SOAP request factory"""


class IHTTPRequestFactory(IRequestFactory):
# TODO: should SOAP, XMLRPC, and Browser extend this?
"""generic HTTP request factory"""


class IXMLRPCRequestFactory(IRequestFactory):
"""XMLRPC request factory"""


class IBrowserRequestFactory(IRequestFactory):
"""Browser request factory"""


class IFileContent(interface.Interface):
"""Marker interface for content that can be managed as files.
Expand All @@ -61,7 +65,7 @@ class IFileContent(interface.Interface):


class IRequestPublicationFactory(interface.Interface):
""" request-publication factory """
"""Request-publication factory"""

def canHandle(environment):
"""Return ``True`` if it can handle the request, otherwise ``False``.
Expand All @@ -73,6 +77,7 @@ def canHandle(environment):
def __call__():
"""Return a tuple (request, publication)"""


class IRequestPublicationRegistry(interface.Interface):
"""A registry to lookup a RequestPublicationFactory by
request method + mime-type. Multiple factories can be configured
Expand All @@ -83,7 +88,7 @@ class IRequestPublicationRegistry(interface.Interface):
"""

def register(method, mimetype, name, priority, factory):
"""Registers a factory for method+mimetype."""
"""Register a factory for method+mimetype."""

def lookup(method, mimetype, environment):
"""Lookup a factory for a given method+mimetype and a
Expand Down
11 changes: 5 additions & 6 deletions src/zope/app/publication/metaconfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
See metadirective.py
"""
__docformat__ = 'restructuredtext'

from zope.app.publication.requestpublicationregistry import factoryRegistry


def publisher(_context, name, factory, methods=['*'], mimetypes=['*'],
priority=0):

Expand All @@ -27,7 +26,7 @@ def publisher(_context, name, factory, methods=['*'], mimetypes=['*'],
for method in methods:
for mimetype in mimetypes:
_context.action(
discriminator = (method, mimetype, priority),
callable = factoryRegistry.register,
args = (method, mimetype, name, priority, factory)
)
discriminator=(method, mimetype, priority),
callable=factoryRegistry.register,
args=(method, mimetype, name, priority, factory)
)
3 changes: 1 addition & 2 deletions src/zope/app/publication/metadirectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
The sortkey helps when several directives can handle a request:
they are sorted by this key and the highest one is taken.
"""
__docformat__ = 'restructuredtext'

from zope.interface import Interface
from zope.configuration.fields import GlobalObject, Tokens
from zope.schema import TextLine, Int


class IRequestPublicationDirective(Interface):
"""Link a request type to a request and publication factory"""

Expand Down
11 changes: 6 additions & 5 deletions src/zope/app/publication/publicationtraverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#
##############################################################################
import warnings
from zope.traversing.publicationtraverse import PublicationTraverse # noqa: F401 E501 (BBB and long line)
from zope.traversing.publicationtraverse import PublicationTraverser # noqa: F401 E501 (BBB and long line)


warnings.warn("""%s is deprecated
Expand All @@ -21,13 +24,11 @@
""" % __name__, DeprecationWarning, stacklevel=1)


from zope.traversing.publicationtraverse import PublicationTraverse #BBB import
from zope.traversing.publicationtraverse import PublicationTraverser #BBB import

#BBB: do not use
# BBB: do not use
class DuplicateNamespaces(Exception):
"""More than one namespace was specified in a request"""

#BBB: do not use

# BBB: do not use
class UnknownNamespace(Exception):
"""A parameter specified an unknown namespace"""
6 changes: 3 additions & 3 deletions src/zope/app/publication/requestpublicationfactories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
This module provides factories for tuples (request, publication).
"""
__docformat__ = 'restructuredtext'

from zope import component
from zope.interface import implementer
from zope.app.publication.interfaces import IRequestPublicationFactory
Expand All @@ -29,6 +27,7 @@
from zope.publisher.http import HTTPRequest
from zope.publisher.browser import BrowserRequest


@implementer(IRequestPublicationFactory)
class SOAPFactory(object):

Expand Down Expand Up @@ -63,6 +62,7 @@ def __call__(self):
interfaces.IHTTPRequestFactory, default=HTTPRequest)
return request_class, HTTPPublication


@implementer(IRequestPublicationFactory)
class BrowserFactory(object):

Expand All @@ -71,5 +71,5 @@ def canHandle(self, environment):

def __call__(self):
request_class = component.queryUtility(
interfaces.IBrowserRequestFactory, default=BrowserRequest)
interfaces.IBrowserRequestFactory, default=BrowserRequest)
return request_class, BrowserPublication
26 changes: 11 additions & 15 deletions src/zope/app/publication/requestpublicationregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
##############################################################################
"""A registry for Request-Publication factories.
"""
__docformat__ = 'restructuredtext'
from zope.interface import implementer
from zope.app.publication.interfaces import IRequestPublicationRegistry
from zope.configuration.exceptions import ConfigurationError


@implementer(IRequestPublicationRegistry)
class RequestPublicationRegistry(object):
"""The registry implements a three stage lookup for registered factories
Expand All @@ -38,39 +38,37 @@ def __init__(self):
self._d = {} # method -> { mimetype -> {factories_data}}

def register(self, method, mimetype, name, priority, factory):
"""Register a factory for method+mimetype """

"""Register a factory for method+mimetype"""
# initialize the two-level deep nested datastructure if necessary
if method not in self._d:
self._d[method] = {}
if mimetype not in self._d[method]:
self._d[method][mimetype] = []
l = self._d[method][mimetype]
factories_data = self._d[method][mimetype]

# Check if there is already a registered publisher factory (check by
# name). If yes then it will be removed and replaced by a new
# publisher.
for pos, d in enumerate(l):
for pos, d in enumerate(factories_data):
if d['name'] == name:
del l[pos]
del factories_data[pos]
break
# add the publisher factory + additional informations
l.append({'name' : name, 'factory' : factory, 'priority' : priority})
factories_data.append(
{'name': name, 'factory': factory, 'priority': priority})

# order by descending priority
l.sort(key=lambda v: v['priority'], reverse=True)
factories_data.sort(key=lambda v: v['priority'], reverse=True)

# check if the priorities are unique
priorities = [item['priority'] for item in l]
if len(set(priorities)) != len(l):
priorities = [item['priority'] for item in factories_data]
if len(set(priorities)) != len(factories_data):
raise ConfigurationError('All registered publishers for a given '
'method+mimetype must have distinct '
'priorities. Please check your ZCML '
'configuration')


def getFactoriesFor(self, method, mimetype):

if ';' in mimetype:
# `mimetype` might be something like 'text/xml; charset=utf8'. In
# this case we are only interested in the first part.
Expand All @@ -81,11 +79,9 @@ def getFactoriesFor(self, method, mimetype):
except KeyError:
return None


def lookup(self, method, mimetype, environment):
"""Lookup a factory for a given method+mimetype and a environment.
"""
factories = []
for m, mt in ((method, mimetype), (method, '*'), ('*', '*')):
# Collect, in order, from most specific to most generic, the
# factories that potentially handle the given environment.
Expand All @@ -111,4 +107,4 @@ def lookup(self, method, mimetype, environment):
except ImportError:
pass
else:
zope.testing.cleanup.addCleanUp(lambda : factoryRegistry.__init__())
zope.testing.cleanup.addCleanUp(lambda: factoryRegistry.__init__())
2 changes: 2 additions & 0 deletions src/zope/app/publication/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

from zope.app.publication.http import BaseHTTPPublication


# Don't need any special handling for SOAP
SOAPPublication = BaseHTTPPublication


class SOAPPublicationFactory(object):

def __init__(self, db):
Expand Down
2 changes: 2 additions & 0 deletions src/zope/app/publication/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
from zope.publisher.interfaces.browser import (IDefaultBrowserLayer,
IBrowserRequest)


def provideNamespaceHandler(name, handler):
component.provideAdapter(handler, (None,), ITraversable,
name=name)
component.provideAdapter(handler, (None, None), ITraversable,
name=name)


def setDefaultViewName(for_, name, layer=IDefaultBrowserLayer,
type=IBrowserRequest):
if layer is None:
Expand Down
Loading

0 comments on commit bfc78ca

Please sign in to comment.