Skip to content
Browse files

Experimental python 3 support

  • Loading branch information...
1 parent 9d42ac2 commit eb737105942fa632ec1610aeb0c8a4e51fd27e59 @tzicatl tzicatl committed
Showing with 64 additions and 54 deletions.
  1. +4 −4 pyramid_handlers/__init__.py
  2. +52 −48 pyramid_handlers/tests.py
  3. +8 −2 setup.py
View
8 pyramid_handlers/__init__.py
@@ -91,8 +91,8 @@ def scan_handler(config, handler, route_name, action_decorator,
if autoexpose:
try:
autoexpose = re.compile(autoexpose).match
- except (re.error, TypeError), why:
- raise ConfigurationError(why[0])
+ except (re.error, TypeError) as why:
+ raise ConfigurationError(why.args[0])
for method_name, method in inspect.getmembers(handler, inspect.ismethod):
configs = getattr(method, '__exposed__', [])
if autoexpose and not configs:
@@ -168,8 +168,8 @@ def __init__(self, action):
self.action = action
try:
self.action_re = re.compile(action + '$')
- except (re.error, TypeError), why:
- raise ConfigurationError(why[0])
+ except (re.error, TypeError) as why:
+ raise ConfigurationError(why.args[0])
def __call__(self, context, request):
matchdict = request.matchdict
View
100 pyramid_handlers/tests.py
@@ -1,6 +1,9 @@
+import sys
import unittest
from pyramid import testing
+PY3 = sys.version_info[0] == 3
+
class Test_add_handler(unittest.TestCase):
def _makeOne(self, autocommit=True):
from pyramid.config import Configurator
@@ -399,7 +402,7 @@ def aview(self): pass
config.add_handler('h1', '/h1', handler=AHandler)
try:
config.commit()
- except Exception, why:
+ except Exception as why:
c = list(self._conflictFunctions(why))
self.assertEqual(c[0], 'test_conflict_add_handler')
self.assertEqual(c[1], 'test_conflict_add_handler')
@@ -491,53 +494,54 @@ def wrapped():
self.assertTrue(result is wrapped)
self.assertEqual(result.__exposed__, [None, {'a':1, 'b':2}])
-class TestHandlerDirective(unittest.TestCase):
- def setUp(self):
- self.config = testing.setUp(autocommit=False)
- _ctx = self.config._ctx
- if _ctx is None: # pragma: no cover ; will never be true under 1.2a5+
- self.config._ctx = self.config._make_context()
-
- def tearDown(self):
- testing.tearDown()
-
- def _callFUT(self, *arg, **kw):
- from pyramid_handlers.zcml import handler
- return handler(*arg, **kw)
-
- def test_it(self):
- from pyramid_handlers import action
- from zope.interface import Interface
- from pyramid.interfaces import IView
- from pyramid.interfaces import IViewClassifier
- from pyramid.interfaces import IRouteRequest
- reg = self.config.registry
- context = DummyZCMLContext(self.config)
- class Handler(object): # pragma: no cover
- def __init__(self, request):
- self.request = request
- action(renderer='json')
- def one(self):
- return 'OK'
- action(renderer='json')
- def two(self):
- return 'OK'
- self._callFUT(context, 'name', '/:action', Handler)
- actions = extract_actions(context.actions)
- _execute_actions(actions)
- request_type = reg.getUtility(IRouteRequest, 'name')
- wrapped = reg.adapters.lookup(
- (IViewClassifier, request_type, Interface), IView, name='')
- self.assertTrue(wrapped)
-
- def test_pattern_is_None(self):
- from pyramid.exceptions import ConfigurationError
-
- context = self.config._ctx
- class Handler(object):
- pass
- self.assertRaises(ConfigurationError, self._callFUT,
- context, 'name', None, Handler)
+if not PY3:
+ class TestHandlerDirective(unittest.TestCase):
+ def setUp(self):
+ self.config = testing.setUp(autocommit=False)
+ _ctx = self.config._ctx
+ if _ctx is None: # pragma: no cover ; will never be true under 1.2a5+
+ self.config._ctx = self.config._make_context()
+
+ def tearDown(self):
+ testing.tearDown()
+
+ def _callFUT(self, *arg, **kw):
+ from pyramid_handlers.zcml import handler
+ return handler(*arg, **kw)
+
+ def test_it(self):
+ from pyramid_handlers import action
+ from zope.interface import Interface
+ from pyramid.interfaces import IView
+ from pyramid.interfaces import IViewClassifier
+ from pyramid.interfaces import IRouteRequest
+ reg = self.config.registry
+ context = DummyZCMLContext(self.config)
+ class Handler(object): # pragma: no cover
+ def __init__(self, request):
+ self.request = request
+ action(renderer='json')
+ def one(self):
+ return 'OK'
+ action(renderer='json')
+ def two(self):
+ return 'OK'
+ self._callFUT(context, 'name', '/:action', Handler)
+ actions = extract_actions(context.actions)
+ _execute_actions(actions)
+ request_type = reg.getUtility(IRouteRequest, 'name')
+ wrapped = reg.adapters.lookup(
+ (IViewClassifier, request_type, Interface), IView, name='')
+ self.assertTrue(wrapped)
+
+ def test_pattern_is_None(self):
+ from pyramid.exceptions import ConfigurationError
+
+ context = self.config._ctx
+ class Handler(object):
+ pass
+ self.assertRaises(ConfigurationError, self._callFUT,
+ context, 'name', None, Handler)
class Test_includeme(unittest.TestCase):
View
10 setup.py
@@ -13,6 +13,7 @@
##############################################################################
import os
+import sys
import platform
from setuptools import setup, find_packages
@@ -28,11 +29,14 @@
'pyramid>=1.0a10',
]
+PY3 = sys.version_info[0] == 3
if platform.system() == 'Java':
tests_require = install_requires + ['pyramid_zcml']
else:
- tests_require= install_requires + ['pyramid_zcml', 'Sphinx', 'docutils',
- 'repoze.sphinx.autointerface']
+ if not PY3:
+ tests_require= install_requires + ['pyramid_zcml', 'Sphinx', 'docutils',]
+ else:
+ tests_require= install_requires + ['Sphinx', 'docutils',]
setup(name='pyramid_handlers',
version='0.4',
@@ -45,6 +49,8 @@
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI",
"License :: Repoze Public License",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 2"
],
keywords='web wsgi pylons pyramid',
author="Chris McDonough, Agendaless Consulting",

0 comments on commit eb73710

Please sign in to comment.
Something went wrong with that request. Please try again.