Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Jul 22, 2016
1 parent 09b7ba8 commit 39cbbff
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/zExceptions/ExceptionFormatter.py
Expand Up @@ -21,7 +21,7 @@
DEBUG_EXCEPTION_FORMATTER = 1


class TextExceptionFormatter:
class TextExceptionFormatter(object):

line_sep = '\n'
show_revisions = 0
Expand Down Expand Up @@ -196,7 +196,7 @@ def formatException(self, etype, value, tb, limit=None):
return result


class HTMLExceptionFormatter (TextExceptionFormatter):
class HTMLExceptionFormatter(TextExceptionFormatter):

line_sep = '<br />\r\n'

Expand Down
2 changes: 1 addition & 1 deletion src/zExceptions/_compat.py
Expand Up @@ -2,7 +2,7 @@
import sys


PY3 = sys.version_info[0] == 3
PY3 = sys.version_info >= (3, 0)
if PY3:
import builtins
class_types = type,
Expand Down
12 changes: 3 additions & 9 deletions src/zExceptions/tests/testExceptionFormatter.py
Expand Up @@ -16,7 +16,7 @@
"""

import sys
from unittest import TestCase, TestSuite, makeSuite
from unittest import TestCase

from zExceptions.ExceptionFormatter import format_exception

Expand All @@ -33,7 +33,7 @@ class ExceptionForTesting(Exception):
pass


class TestingTracebackSupplement:
class TestingTracebackSupplement(object):

source_url = '/somepath'
line = 634
Expand All @@ -48,7 +48,7 @@ class Test(TestCase):

def testBasicNamesText(self, as_html=0):
try:
raise ExceptionForTesting
raise ExceptionForTesting()
except ExceptionForTesting:
s = tb(as_html)
# The traceback should include the name of this function.
Expand Down Expand Up @@ -131,9 +131,3 @@ class C:
self.fail('no exception occurred')
self.assert_(s.find('&lt;') >= 0, s)
self.assert_(s.find('&gt;') >= 0, s)


def test_suite():
return TestSuite((
makeSuite(Test),
))
11 changes: 2 additions & 9 deletions src/zExceptions/tests/test___init__.py
@@ -1,7 +1,7 @@
import unittest


class Test_convertExceptionType(unittest.TestCase):
class TestConvertExceptionType(unittest.TestCase):

def _callFUT(self, name):
from zExceptions import convertExceptionType
Expand All @@ -21,7 +21,7 @@ def test_name_in_zExceptions_not_an_exception_returns_None(self):
self.failUnless(self._callFUT('convertExceptionType') is None)


class Test_upgradeException(unittest.TestCase):
class TestUpgradeException(unittest.TestCase):

def _callFUT(self, t, v):
from zExceptions import upgradeException
Expand All @@ -48,10 +48,3 @@ def test_string_miss_returns_InternalError(self):
t, v = self._callFUT('Nonesuch', 'TEST')
self.assertEqual(t, InternalError)
self.assertEqual(v, ('Nonesuch', 'TEST'))


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test_convertExceptionType),
unittest.makeSuite(Test_upgradeException),
))
29 changes: 16 additions & 13 deletions src/zExceptions/tests/test_unauthorized.py
Expand Up @@ -24,7 +24,6 @@ class UnauthorizedTests(unittest.TestCase):

def _getTargetClass(self):
from zExceptions.unauthorized import Unauthorized

return Unauthorized

def _makeOne(self, *args, **kw):
Expand Down Expand Up @@ -92,9 +91,11 @@ def test_ascii_name(self):
self.assertEqual(exc.needed, None)

self.assertEqual(
bytes(exc), b"You are not allowed to access 'ERROR_NAME' in this context")
bytes(exc),
b"You are not allowed to access 'ERROR_NAME' in this context")
self.assertEqual(
unicode(exc), u("You are not allowed to access 'ERROR_NAME' in this context"))
unicode(exc),
u("You are not allowed to access 'ERROR_NAME' in this context"))

def test_encoded_name(self):
arg = u('ERROR_NAME_\u03A9').encode('utf-8')
Expand All @@ -106,9 +107,13 @@ def test_encoded_name(self):
self.assertEqual(exc.needed, None)

self.assertEqual(
bytes(exc), b"You are not allowed to access 'ERROR_NAME_\xce\xa9' in this context")
bytes(exc),
(b"You are not allowed to access "
b"'ERROR_NAME_\xce\xa9' in this context"))
self.assertEqual(
unicode(exc), u("You are not allowed to access 'ERROR_NAME_\u03A9' in this context"))
unicode(exc),
u("You are not allowed to access "
"'ERROR_NAME_\u03A9' in this context"))

def test_unicode_name(self):
arg = u('ERROR_NAME_\u03A9')
Expand All @@ -120,12 +125,10 @@ def test_unicode_name(self):
self.assertEqual(exc.needed, None)

self.assertEqual(
bytes(exc), b"You are not allowed to access 'ERROR_NAME_\xce\xa9' in this context")
bytes(exc),
(b"You are not allowed to access "
b"'ERROR_NAME_\xce\xa9' in this context"))
self.assertEqual(
unicode(exc), u("You are not allowed to access 'ERROR_NAME_\u03A9' in this context"))


def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UnauthorizedTests))
return suite
unicode(exc),
u("You are not allowed to access "
"'ERROR_NAME_\u03A9' in this context"))
17 changes: 11 additions & 6 deletions src/zExceptions/unauthorized.py
Expand Up @@ -42,8 +42,9 @@ def __init__(self, message=None, value=None, needed=None, name=None, **kw):
(e.g. {'permission': 'add spam'}). Any extra keyword arguments
provides are added to needed.
"""
if name is None and (
not isinstance(message, string_types) or len(message.split()) <= 1):
if (name is None and (
not isinstance(message, string_types) or
len(message.split()) <= 1)):
# First arg is a name, not a message
name = message
message = None
Expand All @@ -62,12 +63,16 @@ def __init__(self, message=None, value=None, needed=None, name=None, **kw):

def __unicode__(self):
if self.message is not None:
message = self.message if isinstance(self.message, unicode) else self.message.decode(
'utf-8')
message = (self.message if
isinstance(self.message, unicode) else
self.message.decode('utf-8'))
return message
if self.name is not None:
name = self.name if isinstance(self.name, unicode) else self.name.decode('utf-8')
return ("You are not allowed to access '%s' in this context" % name)
name = (self.name if
isinstance(self.name, unicode) else
self.name.decode('utf-8'))
return ("You are not allowed to access '%s' in this context"
% name)
elif self.value is not None:
return ("You are not allowed to access '%s' in this context"
% self.getValueName())
Expand Down

0 comments on commit 39cbbff

Please sign in to comment.