Skip to content

Commit

Permalink
Python 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
regebro committed Feb 5, 2018
1 parent 62614da commit 0c23354
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: python
python:
- 2.7
- 3.5
- 3.6
install:
- virtualenv env
- env/bin/pip install -U setuptools
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CHANGES
1.0.11 (unreleased)
-------------------

- Nothing changed yet.
- Support Python 2.7, 3.5 and 3.6


1.0.10 (2015-10-23)
Expand Down
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def read(*rnames):
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
Expand All @@ -48,6 +53,7 @@ def read(*rnames):
extras_require=dict(
test=[
'zope.testing',
'zope.testrunner',
'mock',
],
),
Expand All @@ -62,5 +68,7 @@ def read(*rnames):
entry_points='''
[paste.filter_app_factory]
longrequest= cipher.longrequest.longrequest:make_filter
[distutils.commands]
ftest = zope.testrunner.eggsupport:ftest
'''
)
15 changes: 9 additions & 6 deletions src/cipher/longrequest/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class ILongRequestEvent(zope.interface.Interface):
required=False)


@zope.interface.implementer(ILongRequestEvent)
class LongRequestEvent(object):
zope.interface.implements(ILongRequestEvent)

def __init__(self, thread_id, duration, uri, worker_environ, zope_request):
self.thread_id = thread_id
Expand All @@ -63,24 +63,27 @@ class ILongRequestEventOver1(ILongRequestEvent):
pass


@zope.interface.implementer(ILongRequestEventOver1)
class LongRequestEventOver1(LongRequestEvent):
zope.interface.implements(ILongRequestEventOver1)
pass


class ILongRequestEventOver2(ILongRequestEvent):
pass


@zope.interface.implementer(ILongRequestEventOver2)
class LongRequestEventOver2(LongRequestEvent):
zope.interface.implements(ILongRequestEventOver2)
pass


class ILongRequestEventOver3(ILongRequestEvent):
pass


@zope.interface.implementer(ILongRequestEventOver3)
class LongRequestEventOver3(LongRequestEvent):
zope.interface.implements(ILongRequestEventOver3)
pass


class ILongRequestFinishedEvent(zope.interface.Interface):
Expand All @@ -97,8 +100,8 @@ class ILongRequestFinishedEvent(zope.interface.Interface):
required=False)


@zope.interface.implementer(ILongRequestFinishedEvent)
class LongRequestFinishedEvent(object):
zope.interface.implements(ILongRequestFinishedEvent)

def __init__(self, thread_id, duration, uri):
self.thread_id = thread_id
Expand All @@ -115,8 +118,8 @@ class ILongRequestTickEvent(zope.interface.Interface):
thread_pool = zope.interface.Attribute("Thread pool")


@zope.interface.implementer(ILongRequestTickEvent)
class LongRequestTickEvent(object):
zope.interface.implements(ILongRequestTickEvent)

def __init__(self, thread_pool):
self.thread_pool = thread_pool
17 changes: 13 additions & 4 deletions src/cipher/longrequest/longrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

from __future__ import absolute_import

import ConfigParser
try:
from configparser import RawConfigParser
except ImportError:
from ConfigParser import RawConfigParser
import copy
import logging
import threading
Expand Down Expand Up @@ -323,9 +326,15 @@ def getAllThreadInfo(omitThreads=()):
def getThreadTraceback(thread_id):
try:
frame = sys._current_frames()[thread_id]
buf = io.BytesIO()
if sys.version_info[0] == 2:
buf = io.BytesIO()
else:
buf = io.StringIO()
traceback.print_stack(frame, file=buf)
return buf.getvalue().decode('utf-8').rstrip()
if sys.version_info[0] == 2:
return buf.getvalue().decode('utf-8').rstrip()
else:
return buf.getvalue()
except KeyError:
# if thread is already finished
return ' ???'
Expand Down Expand Up @@ -459,7 +468,7 @@ def __repr__(self):


def make_filter(app, global_conf, forceStart=False):
config = ConfigParser.RawConfigParser()
config = RawConfigParser()
config.optionxform = str
config.read(global_conf['__file__'])

Expand Down

0 comments on commit 0c23354

Please sign in to comment.