Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for Python 3 #1

Merged
merged 4 commits into from Mar 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
14 changes: 12 additions & 2 deletions setup.py
Expand Up @@ -23,15 +23,25 @@
description="error log for Zope 2.",
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
long_description=open('README.txt').read() + '\n' +
long_description=open('README.rst').read() + '\n' +
open('CHANGES.txt').read(),
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Zope Public License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Framework :: Zope2",
"Topic :: Software Development :: Libraries :: Python Modules",
],
packages=find_packages('src'),
namespace_packages=['Products'],
package_dir={'': 'src'},
extras_require=dict(
test=['transaction'],
zope212=['AccessControl',
'DocumentTemplate',
'Zope2']),
install_requires=[
'setuptools',
Expand Down
23 changes: 15 additions & 8 deletions src/Products/SiteErrorLog/SiteErrorLog.py
Expand Up @@ -19,15 +19,16 @@
import time
import logging
from random import random
from thread import allocate_lock
try:
# Python 3
from _thread import allocate_lock
except ImportError:
# Python 2
from thread import allocate_lock
from zope.event import notify
from Products.SiteErrorLog.interfaces import ErrorRaisedEvent

try:
from AccessControl.class_init import InitializeClass
InitializeClass # pyflakes
except ImportError, e:
from Globals import InitializeClass
from AccessControl.class_init import InitializeClass

from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.SecurityManagement import getSecurityManager
Expand Down Expand Up @@ -70,6 +71,12 @@

cleanup_lock = allocate_lock()

try:
# Python 2
bstr = basestring
except NameError:
# Python 3
bstr = str

class SiteErrorLog (SimpleItem):
"""Site error log class. You can put an error log anywhere in the tree
Expand Down Expand Up @@ -165,7 +172,7 @@ def raising(self, info):
if strtype in self._ignored_exceptions:
return

if not isinstance(info[2], basestring):
if not isinstance(info[2], bstr):
tb_text = ''.join(
format_exception(*info, **{'as_html': 0}))
tb_html = ''.join(
Expand Down Expand Up @@ -267,7 +274,7 @@ def setProperties(self, keep_entries, copy_to_zlog=0,
self.keep_entries = int(keep_entries)
self.copy_to_zlog = copy_to_zlog
self._ignored_exceptions = tuple(
filter(None, map(str, ignored_exceptions)))
[_f for _f in map(str, ignored_exceptions) if _f])
if RESPONSE is not None:
RESPONSE.redirect(
'%s/manage_main?manage_tabs_message=Changed+properties.' %
Expand Down
18 changes: 9 additions & 9 deletions src/Products/SiteErrorLog/tests/testSiteErrorLog.py
Expand Up @@ -28,7 +28,7 @@ def setUp(self):
self.app.manage_addDTMLMethod('doc', '')

self.logger = logging.getLogger('Zope.SiteErrorLog')
self.log = logging.handlers.BufferingHandler(sys.maxint)
self.log = logging.handlers.BufferingHandler(sys.maxsize)
self.logger.addHandler(self.log)
self.old_level = self.logger.level
self.logger.setLevel(logging.ERROR)
Expand All @@ -46,16 +46,16 @@ def testInstantiation(self):
sel_ob = getattr(self.app, 'error_log', None)

# Does the error log exist?
self.assert_(sel_ob is not None)
self.assertTrue(sel_ob is not None)

# Is the __error_log__ hook in place?
self.assert_(self.app.__error_log__ == sel_ob)
self.assertEqual(self.app.__error_log__, sel_ob)

# Right now there should not be any entries in the log
# but if another test fails and leaves something in the
# log (which belongs to app , we get a spurious error here.
# There's no real point in testing this anyway.
#self.assertEquals(len(sel_ob.getLogEntries()), 0)
#self.assertEqual(len(sel_ob.getLogEntries()), 0)

def testSimpleException(self):
# Grab the Site Error Log and make sure it's empty
Expand All @@ -75,7 +75,7 @@ def testSimpleException(self):
sel_ob.raising(sys.exc_info())

# Now look at the SiteErrorLog, it has one more log entry
self.assertEquals(len(sel_ob.getLogEntries()), previous_log_length + 1)
self.assertEqual(len(sel_ob.getLogEntries()), previous_log_length + 1)

def testEventSubscription(self):
sel_ob = self.app.error_log
Expand Down Expand Up @@ -113,13 +113,13 @@ def testForgetException(self):
previous_log_length = len(elog.getLogEntries())

entries = elog.getLogEntries()
self.assertEquals(entries[0]['value'], "DummyAttribute")
self.assertEqual(entries[0]['value'], "DummyAttribute")

# Kick it
elog.forgetEntry(entries[0]['id'])

# Really gone?
self.assertEquals(len(elog.getLogEntries()), previous_log_length - 1)
self.assertEqual(len(elog.getLogEntries()), previous_log_length - 1)

def testIgnoredException(self):
# Grab the Site Error Log
Expand Down Expand Up @@ -148,7 +148,7 @@ def testIgnoredException(self):

# Now look at the SiteErrorLog, it must have the same number of
# log entries
self.assertEquals(len(sel_ob.getLogEntries()), previous_log_length)
self.assertEqual(len(sel_ob.getLogEntries()), previous_log_length)

def testEntryID(self):
elog = self.app.error_log
Expand All @@ -169,7 +169,7 @@ def testEntryID(self):
def testCleanup(self):
# Need to make sure that the __error_log__ hook gets cleaned up
self.app._delObject('error_log')
self.assertEquals(getattr(self.app, '__error_log__', None), None)
self.assertEqual(getattr(self.app, '__error_log__', None), None)


def test_suite():
Expand Down