More miscellaneous PY3 compatability issues.
This commit is contained in:
@@ -102,7 +102,14 @@ class CommandRunner(object):
|
|||||||
return self.manager.commands
|
return self.manager.commands
|
||||||
|
|
||||||
|
|
||||||
class BaseCommand(object):
|
class BaseCommandMeta(type):
|
||||||
|
|
||||||
|
@property
|
||||||
|
def summary(cls):
|
||||||
|
return cls.__doc__.strip().splitlines()[0].rstrip('.')
|
||||||
|
|
||||||
|
|
||||||
|
class BaseCommandParent(object):
|
||||||
"""
|
"""
|
||||||
A base interface for Pecan commands.
|
A base interface for Pecan commands.
|
||||||
|
|
||||||
@@ -130,11 +137,6 @@ class BaseCommand(object):
|
|||||||
print(args.extra_arg)
|
print(args.extra_arg)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class __metaclass__(type):
|
|
||||||
@property
|
|
||||||
def summary(cls):
|
|
||||||
return cls.__doc__.strip().splitlines()[0].rstrip('.')
|
|
||||||
|
|
||||||
arguments = ({
|
arguments = ({
|
||||||
'name': 'config_file',
|
'name': 'config_file',
|
||||||
'help': 'a Pecan configuration file',
|
'help': 'a Pecan configuration file',
|
||||||
@@ -148,3 +150,5 @@ class BaseCommand(object):
|
|||||||
def load_app(self):
|
def load_app(self):
|
||||||
from pecan import load_app
|
from pecan import load_app
|
||||||
return load_app(self.args.config_file)
|
return load_app(self.args.config_file)
|
||||||
|
|
||||||
|
BaseCommand = BaseCommandMeta('BaseCommand', (BaseCommandParent,), {})
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ class Pecan(object):
|
|||||||
valid_args = valid_args[len(args):]
|
valid_args = valid_args[len(args):]
|
||||||
|
|
||||||
# handle wildcard arguments
|
# handle wildcard arguments
|
||||||
if filter(None, remainder):
|
if [i for i in remainder if i]:
|
||||||
if not argspec[1]:
|
if not argspec[1]:
|
||||||
abort(404)
|
abort(404)
|
||||||
args.extend(remainder)
|
args.extend(remainder)
|
||||||
@@ -422,7 +422,7 @@ class Pecan(object):
|
|||||||
# handle generic controllers
|
# handle generic controllers
|
||||||
im_self = None
|
im_self = None
|
||||||
if cfg.get('generic'):
|
if cfg.get('generic'):
|
||||||
im_self = controller.im_self
|
im_self = six.get_method_self(controller)
|
||||||
handlers = cfg['generic_handlers']
|
handlers = cfg['generic_handlers']
|
||||||
controller = handlers.get(req.method, handlers['DEFAULT'])
|
controller = handlers.get(req.method, handlers['DEFAULT'])
|
||||||
cfg = _cfg(controller)
|
cfg = _cfg(controller)
|
||||||
@@ -533,8 +533,14 @@ class Pecan(object):
|
|||||||
testing_variables['controller_output'] = result
|
testing_variables['controller_output'] = result
|
||||||
|
|
||||||
# set the body content
|
# set the body content
|
||||||
if isinstance(result, unicode):
|
if six.PY3:
|
||||||
resp.unicode_body = result
|
resp.text = result if isinstance(result, str) else str(
|
||||||
|
result,
|
||||||
|
'utf-8',
|
||||||
|
'strict'
|
||||||
|
)
|
||||||
|
elif isinstance(result, six.text_type):
|
||||||
|
resp.text = result
|
||||||
else:
|
else:
|
||||||
resp.body = result
|
resp.body = result
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from pecan.compat import bytes_
|
||||||
from .recursive import ForwardRequestException, RecursionLoop
|
from .recursive import ForwardRequestException, RecursionLoop
|
||||||
|
|
||||||
|
|
||||||
@@ -31,9 +32,9 @@ class StatusPersist(object):
|
|||||||
[('Content-type', 'text/plain')],
|
[('Content-type', 'text/plain')],
|
||||||
sys.exc_info()
|
sys.exc_info()
|
||||||
)
|
)
|
||||||
return [
|
return [bytes_(
|
||||||
'Error: %s. (Error page could not be fetched)' % self.status
|
'Error: %s. (Error page could not be fetched)' % self.status
|
||||||
]
|
)]
|
||||||
|
|
||||||
|
|
||||||
class ErrorDocumentMiddleware(object):
|
class ErrorDocumentMiddleware(object):
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import mimetypes
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import gmtime
|
from time import gmtime
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
class FileWrapper(object):
|
class FileWrapper(object):
|
||||||
"""This class can be used to convert a :class:`file`-like object into
|
"""This class can be used to convert a :class:`file`-like object into
|
||||||
@@ -42,6 +44,10 @@ class FileWrapper(object):
|
|||||||
raise StopIteration()
|
raise StopIteration()
|
||||||
|
|
||||||
|
|
||||||
|
if six.PY3:
|
||||||
|
FileWrapper.__next__ = FileWrapper.next
|
||||||
|
|
||||||
|
|
||||||
def wrap_file(environ, file, buffer_size=8192):
|
def wrap_file(environ, file, buffer_size=8192):
|
||||||
"""Wraps a file. This uses the WSGI server's file wrapper if available
|
"""Wraps a file. This uses the WSGI server's file wrapper if available
|
||||||
or otherwise the generic :class:`FileWrapper`.
|
or otherwise the generic :class:`FileWrapper`.
|
||||||
@@ -64,7 +70,7 @@ def _dump_date(d, delim):
|
|||||||
d = gmtime()
|
d = gmtime()
|
||||||
elif isinstance(d, datetime):
|
elif isinstance(d, datetime):
|
||||||
d = d.utctimetuple()
|
d = d.utctimetuple()
|
||||||
elif isinstance(d, (int, long, float)):
|
elif isinstance(d, (int, float)):
|
||||||
d = gmtime(d)
|
d = gmtime(d)
|
||||||
return '%s, %02d%s%s%s%s %02d:%02d:%02d GMT' % (
|
return '%s, %02d%s%s%s%s %02d:%02d:%02d GMT' % (
|
||||||
('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')[d.tm_wday],
|
('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')[d.tm_wday],
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ class TestScaffoldUtils(PecanTestCase):
|
|||||||
|
|
||||||
def test_destination_directory_already_exists(self):
|
def test_destination_directory_already_exists(self):
|
||||||
from pecan.scaffolds import copy_dir
|
from pecan.scaffolds import copy_dir
|
||||||
from cStringIO import StringIO
|
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
copy_dir(
|
copy_dir(
|
||||||
(
|
(
|
||||||
|
|||||||
Reference in New Issue
Block a user