Commit 33f72dcb authored by Hanno Schlichting's avatar Hanno Schlichting

flake8

parent b625d776
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""Zope Framework Class Finder
"""
import OFS.Uninstalled
def ClassFactory(jar, module, name,
_silly=('__doc__',), _globals={},
):
def ClassFactory(jar, module, name, _silly=('__doc__',), _globals={}):
try:
m=__import__(module, _globals, _globals, _silly)
m = __import__(module, _globals, _globals, _silly)
return getattr(m, name)
except:
return OFS.Uninstalled.Broken(jar, None, (module, name))
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
......@@ -84,21 +84,21 @@ def startup():
try:
# Try to use custom storage
try:
m=imp.find_module('custom_zodb',[configuration.testinghome])
m = imp.find_module('custom_zodb', [configuration.testinghome])
except:
m=imp.find_module('custom_zodb',[configuration.instancehome])
m = imp.find_module('custom_zodb', [configuration.instancehome])
except Exception:
# if there is no custom_zodb, use the config file specified databases
DB = dbtab.getDatabase('/', is_root=1)
else:
m=imp.load_module('Zope2.custom_zodb', m[0], m[1], m[2])
sys.modules['Zope2.custom_zodb']=m
m = imp.load_module('Zope2.custom_zodb', m[0], m[1], m[2])
sys.modules['Zope2.custom_zodb'] = m
# Get the database and join it to the dbtab multidatabase
# FIXME: this uses internal datastructures of dbtab
databases = getattr(dbtab, 'databases', {})
if hasattr(m,'DB'):
DB=m.DB
if hasattr(m, 'DB'):
DB = m.DB
databases.update(getattr(DB, 'databases', {}))
DB.databases = databases
else:
......@@ -173,7 +173,7 @@ def validated_hook(request, user):
class RequestContainer(ExtensionClass.Base):
def __init__(self, r):
self.REQUEST=r
self.REQUEST = r
class ZPublisherExceptionHook:
......@@ -234,8 +234,8 @@ class ZPublisherExceptionHook:
error_log_url = log.raising((t, v, traceback))
if (REQUEST is None or
(getattr(REQUEST.get('RESPONSE', None), '_error_format', '')
!= 'text/html')):
(getattr(REQUEST.get('RESPONSE', None),
'_error_format', '') != 'text/html')):
raise t, v, traceback
# Lookup a view for the exception and render it, then
......@@ -245,7 +245,8 @@ class ZPublisherExceptionHook:
# zope.publisher uses as well.
view = queryMultiAdapter((v, REQUEST), name=u'index.html')
if view is not None:
if IAcquirer.providedBy(view) and IAcquirer.providedBy(published):
if (IAcquirer.providedBy(view) and
IAcquirer.providedBy(published)):
view = view.__of__(published)
else:
view.__parent__ = published
......@@ -262,9 +263,9 @@ class ZPublisherExceptionHook:
return response
if (published is None or published is app or
isinstance(published, list)):
isinstance(published, list)):
# At least get the top-level object
published=app.__bobo_traverse__(REQUEST).__of__(
published = app.__bobo_traverse__(REQUEST).__of__(
RequestContainer(REQUEST))
published = getattr(published, 'im_self', published)
......@@ -312,7 +313,9 @@ class ZPublisherExceptionHook:
zpublisher_exception_hook = ZPublisherExceptionHook()
ac_logger = logging.getLogger('event.AccessControl')
class TransactionsManager:
class TransactionsManager(object):
def begin(self,
# Optimize global var lookups:
transaction=transaction):
......@@ -345,8 +348,8 @@ class TransactionsManager:
to_append = (object.__name__,)
object = object.im_self
while object is not None and \
not hasattr(object, 'getPhysicalPath'):
while (object is not None and
not hasattr(object, 'getPhysicalPath')):
if getattr(object, '__name__', None) is None:
object = None
break
......@@ -364,14 +367,13 @@ class TransactionsManager:
T = transaction.get()
T.note(path)
auth_user=request_get('AUTHENTICATED_USER',None)
auth_user = request_get('AUTHENTICATED_USER', None)
if auth_user is not None:
auth_folder = aq_parent(auth_user)
if auth_folder is None:
ac_logger.warning(
'A user object of type %s has no aq_parent.',
type(auth_user)
)
type(auth_user))
auth_path = request_get('AUTHENTICATION_PATH')
else:
auth_path = '/'.join(auth_folder.getPhysicalPath()[1:-1])
......
##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of the Zope2.App package."""
......@@ -15,6 +15,7 @@
import unittest
import transaction
class DoomedTransactionInManagerTest(unittest.TestCase):
def testDoomedFails(self):
......@@ -31,8 +32,3 @@ class DoomedTransactionInManagerTest(unittest.TestCase):
trans = transaction.get()
trans.doom()
tm.commit()
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(DoomedTransactionInManagerTest))
return suite
......@@ -110,9 +110,10 @@ class ExceptionHookTestCase(unittest.TestCase):
sys.exc_info()[1],
sys.exc_info()[2],
)
except Exception, e:
except Exception as e:
return e
class ExceptionHookTest(ExceptionHookTestCase):
def testSystemExit(self):
......@@ -122,6 +123,7 @@ class ExceptionHookTest(ExceptionHookTestCase):
def testUnauthorized(self):
from AccessControl import Unauthorized
def f():
raise Unauthorized('1')
self.assertRaises(Unauthorized, self.call, None, {}, f)
......@@ -130,11 +132,12 @@ class ExceptionHookTest(ExceptionHookTestCase):
from ZPublisher import Retry
from ZODB.POSException import ConflictError
from App.config import getConfiguration
def f():
raise ConflictError()
request = self._makeRequest()
old_value = getattr(getConfiguration(), 'conflict_error_log_level', 0)
self.assertEquals(old_value, 0) # default value
self.assertEquals(old_value, 0) # default value
try:
getConfiguration().conflict_error_log_level = logging.CRITICAL
level = getattr(getConfiguration(), 'conflict_error_log_level', 0)
......@@ -145,6 +148,7 @@ class ExceptionHookTest(ExceptionHookTestCase):
def testConflictErrorCount(self):
from ZODB.POSException import ConflictError
def f():
raise ConflictError()
hook = self._makeOne()
......@@ -156,8 +160,10 @@ class ExceptionHookTest(ExceptionHookTestCase):
def testRetryRaisesOriginalException(self):
from ZPublisher import Retry
class CustomException(Exception):
pass
def f():
try:
raise CustomException('Zope')
......@@ -170,6 +176,7 @@ class ExceptionHookTest(ExceptionHookTestCase):
def testRetryRaisesConflictError(self):
from ZPublisher import Retry
from ZODB.POSException import ConflictError
def f():
try:
raise ConflictError()
......@@ -182,6 +189,7 @@ class ExceptionHookTest(ExceptionHookTestCase):
def testRetryUnresolvedConflictErrorCount(self):
from ZPublisher import Retry
from ZODB.POSException import ConflictError
def f():
try:
raise ConflictError()
......@@ -196,6 +204,7 @@ class ExceptionHookTest(ExceptionHookTestCase):
self.call_no_exc(hook, None, None, f)
self.assertEquals(hook.unresolved_conflict_errors, 2)
class Client(Acquisition.Explicit):
def __init__(self):
......@@ -205,6 +214,7 @@ class Client(Acquisition.Explicit):
def dummyMethod(self):
return 'Aye'
class StandardClient(Client):
def raise_standardErrorMessage(self, c, r, t, v, tb, error_log_url):
......@@ -212,15 +222,18 @@ class StandardClient(Client):
fmt = format_exception(t, v, tb, as_html=0)
self.messages.append(''.join([error_log_url] + fmt))
class BrokenClient(Client):
def raise_standardErrorMessage(self, c, r, t, v, tb, error_log_url):
raise AttributeError('ouch')
class ExceptionMessageRenderTest(ExceptionHookTestCase):
def testRenderUnauthorizedStandardClient(self):
from AccessControl import Unauthorized
def f():
raise Unauthorized('1')
request = self._makeRequest()
......@@ -232,6 +245,7 @@ class ExceptionMessageRenderTest(ExceptionHookTestCase):
def testRenderUnauthorizedStandardClientMethod(self):
from AccessControl import Unauthorized
def f():
raise Unauthorized('1')
request = self._makeRequest()
......@@ -243,6 +257,7 @@ class ExceptionMessageRenderTest(ExceptionHookTestCase):
def testRenderUnauthorizedBrokenClient(self):
from AccessControl import Unauthorized
def f():
raise Unauthorized('1')
request = self._makeRequest()
......@@ -251,8 +266,10 @@ class ExceptionMessageRenderTest(ExceptionHookTestCase):
def testRenderRetryRaisesOriginalException(self):
from ZPublisher import Retry
class CustomException(Exception):
pass
def f():
try:
raise CustomException('Zope')
......@@ -270,6 +287,7 @@ class ExceptionMessageRenderTest(ExceptionHookTestCase):
def testRenderRetryRaisesConflictError(self):
from ZPublisher import Retry
from ZODB.POSException import ConflictError
def f():
try:
raise ConflictError()
......@@ -284,6 +302,7 @@ class ExceptionMessageRenderTest(ExceptionHookTestCase):
tb = client.messages[0]
self.assertTrue("ConflictError: database conflict error" in tb, tb)
class CustomExceptionView(Acquisition.Explicit):
def __init__(self, context, request):
......@@ -291,9 +310,10 @@ class CustomExceptionView(Acquisition.Explicit):
self.request = request
def __call__(self):
return "Exception View: %s\nContext: %s" % (
return ("Exception View: %s\nContext: %s" % (
self.context.__class__.__name__,
Acquisition.aq_parent(self).__class__.__name__)
Acquisition.aq_parent(self).__class__.__name__))
def registerExceptionView(for_):
from zope.interface import Interface
......@@ -307,11 +327,13 @@ def registerExceptionView(for_):
name=u'index.html',
)
class ExceptionViewsTest(PlacelessSetup, ExceptionHookTestCase):
def testCustomExceptionViewUnauthorized(self):
from AccessControl import Unauthorized
registerExceptionView(IUnauthorized)
def f():
raise Unauthorized('1')
request = self._makeRequest()
......@@ -325,6 +347,7 @@ class ExceptionViewsTest(PlacelessSetup, ExceptionHookTestCase):
from ZPublisher.HTTPResponse import HTTPResponse
from zExceptions import Forbidden
registerExceptionView(IForbidden)
def f():
raise Forbidden("argh")
request = self._makeRequest()
......@@ -338,6 +361,7 @@ class ExceptionViewsTest(PlacelessSetup, ExceptionHookTestCase):
from ZPublisher.HTTPResponse import HTTPResponse
from zExceptions import NotFound
registerExceptionView(INotFound)
def f():
raise NotFound("argh")
request = self._makeRequest()
......@@ -351,6 +375,7 @@ class ExceptionViewsTest(PlacelessSetup, ExceptionHookTestCase):
from ZPublisher.HTTPResponse import HTTPResponse
from zExceptions import BadRequest
registerExceptionView(IException)
def f():
raise BadRequest("argh")
request = self._makeRequest()
......@@ -364,6 +389,7 @@ class ExceptionViewsTest(PlacelessSetup, ExceptionHookTestCase):
from ZPublisher.HTTPResponse import HTTPResponse
from zExceptions import InternalError
registerExceptionView(IException)
def f():
raise InternalError("argh")
request = self._makeRequest()
......@@ -376,6 +402,7 @@ class ExceptionViewsTest(PlacelessSetup, ExceptionHookTestCase):
def testRedirectNoExceptionView(self):
from zExceptions import Redirect
registerExceptionView(IException)
def f():
raise Redirect("http://zope.org/")
request = self._makeRequest()
......@@ -383,11 +410,3 @@ class ExceptionViewsTest(PlacelessSetup, ExceptionHookTestCase):
v = self.call_exc_value(client, request, f)
self.assertTrue(isinstance(v, Redirect), v)
self.assertEquals(v.args[0], "http://zope.org/")
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(ExceptionHookTest))
suite.addTest(unittest.makeSuite(ExceptionMessageRenderTest))
suite.addTest(unittest.makeSuite(ExceptionViewsTest))
return suite
......@@ -43,6 +43,7 @@ class Zope2VocabularyRegistryTests(unittest.TestCase, CleanUp):
from zope.component import provideUtility
from zope.schema.interfaces import IVocabularyFactory
_marker = object()
def _factory(context):
return _marker
provideUtility(_factory, IVocabularyFactory, 'foundit')
......
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from zExceptions import Forbidden
from zope.interface.interface import InterfaceClass
from zope.traversing import namespace
......
......@@ -11,8 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""ZCML machinery
"""
import os.path
......@@ -70,6 +68,6 @@ def cleanUp():
_context = None
from zope.testing.cleanup import addCleanUp
from zope.testing.cleanup import addCleanUp # NOQA
addCleanUp(cleanUp)
del addCleanUp
......@@ -10,8 +10,11 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Zope Framework Class Finder
"""
# Stub in case anyone depends on this
from App.ClassFactory import ClassFactory # NOQA
from zope.deferredimport import deprecated
# BBB Zope 5.0
deprecated(
'Please import from Zope2.App.ClassFactory.',
ClassFactory='Zope2.App.ClassFactory:ClassFactory',
)
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from zExceptions import (
HTTPException,
InternalError,
......
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of the Zope2.Startup package."""
......@@ -11,7 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test that the Zope schema can be loaded."""
import os
import cStringIO
......
......@@ -11,7 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test that the warning filter works."""
import os
import cStringIO
......
#!python
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
......
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