Skip to content

Commit

Permalink
Port other scripts to Py3
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Mar 29, 2015
1 parent a30386e commit 453c57c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
39 changes: 22 additions & 17 deletions bench/wzbench.py
Expand Up @@ -20,6 +20,11 @@
from timeit import default_timer as timer
from types import FunctionType

PY2 = sys.version_info[0] == 2

if not PY2:
xrange = range


# create a new module where we later store all the werkzeug attributes.
wz = type(sys)('werkzeug_nonlazy')
Expand Down Expand Up @@ -171,7 +176,7 @@ def main():

def init_compare():
"""Initializes the comparison feature."""
print 'Initializing comparison feature'
print('Initializing comparison feature')
subprocess.Popen(['hg', 'clone', '..', 'a']).wait()
subprocess.Popen(['hg', 'clone', '..', 'b']).wait()

Expand All @@ -182,9 +187,9 @@ def compare(node1, node2):
print >> sys.stderr, 'error: comparison feature not initialized'
sys.exit(4)

print '=' * 80
print 'WERKZEUG INTERNAL BENCHMARK -- COMPARE MODE'.center(80)
print '-' * 80
print('=' * 80)
print('WERKZEUG INTERNAL BENCHMARK -- COMPARE MODE'.center(80))
print('-' * 80)

def _error(msg):
print >> sys.stderr, 'error:', msg
Expand Down Expand Up @@ -217,8 +222,8 @@ def _hg_update(repo, node):
d1 = run('a', no_header=True)
d2 = run('b', no_header=True)

print 'DIRECT COMPARISON'.center(80)
print '-' * 80
print('DIRECT COMPARISON'.center(80))
print('-' * 80)
for key in sorted(d1):
delta = d1[key] - d2[key]
if abs(1 - d1[key] / d2[key]) < TOLERANCE or \
Expand All @@ -227,24 +232,24 @@ def _hg_update(repo, node):
else:
delta = '%+.4f (%+d%%)' % \
(delta, round(d2[key] / d1[key] * 100 - 100))
print '%36s %.4f %.4f %s' % \
(format_func(key), d1[key], d2[key], delta)
print '-' * 80
print('%36s %.4f %.4f %s' %
(format_func(key), d1[key], d2[key], delta))
print('-' * 80)


def run(path, no_header=False):
path = os.path.abspath(path)
wz_version, hg_tag = load_werkzeug(path)
result = {}
if not no_header:
print '=' * 80
print 'WERKZEUG INTERNAL BENCHMARK'.center(80)
print '-' * 80
print 'Path: %s' % path
print 'Version: %s' % wz_version
print('=' * 80)
print('WERKZEUG INTERNAL BENCHMARK'.center(80))
print('-' * 80)
print('Path: %s' % path)
print('Version: %s' % wz_version)
if hg_tag is not None:
print 'HG Tag: %s' % hg_tag
print '-' * 80
print('HG Tag: %s' % hg_tag)
print('-' * 80)
for key, value in sorted(globals().items()):
if key.startswith('time_'):
before = globals().get('before_' + key[5:])
Expand All @@ -254,7 +259,7 @@ def run(path, no_header=False):
after = globals().get('after_' + key[5:])
if after:
after()
print '-' * 80
print('-' * 80)
return result


Expand Down
4 changes: 2 additions & 2 deletions werkzeug/_internal.py
Expand Up @@ -16,7 +16,7 @@
from itertools import chain

from werkzeug._compat import iter_bytes, text_type, BytesIO, int_to_byte, \
range_type
range_type, integer_types


_logger = None
Expand Down Expand Up @@ -157,7 +157,7 @@ def _date_to_unix(arg):
"""
if isinstance(arg, datetime):
arg = arg.utctimetuple()
elif isinstance(arg, (int, long, float)):
elif isinstance(arg, integer_types + (float,)):
return int(arg)
year, month, day, hour, minute, second = arg[:6]
days = date(year, month, 1).toordinal() - _epoch_ord + day - 1
Expand Down
2 changes: 1 addition & 1 deletion werkzeug/debug/tbtools.py
Expand Up @@ -443,7 +443,7 @@ def render_source(self):
def eval(self, code, mode='single'):
"""Evaluate code in the context of the frame."""
if isinstance(code, string_types):
if PY2 and isinstance(code, unicode):
if PY2 and isinstance(code, unicode): # noqa
code = UTF8_COOKIE + code.encode('utf-8')
code = compile(code, '<interactive>', mode)
return eval(code, self.globals, self.locals)
Expand Down
6 changes: 3 additions & 3 deletions werkzeug/local.py
Expand Up @@ -326,7 +326,7 @@ def __bool__(self):

def __unicode__(self):
try:
return unicode(self._get_current_object())
return unicode(self._get_current_object()) # noqa
except RuntimeError:
return repr(self)

Expand Down Expand Up @@ -365,7 +365,7 @@ def __delslice__(self, i, j):
__ne__ = lambda x, o: x._get_current_object() != o
__gt__ = lambda x, o: x._get_current_object() > o
__ge__ = lambda x, o: x._get_current_object() >= o
__cmp__ = lambda x, o: cmp(x._get_current_object(), o)
__cmp__ = lambda x, o: cmp(x._get_current_object(), o) # noqa
__hash__ = lambda x: hash(x._get_current_object())
__call__ = lambda x, *a, **kw: x._get_current_object()(*a, **kw)
__len__ = lambda x: len(x._get_current_object())
Expand All @@ -392,7 +392,7 @@ def __delslice__(self, i, j):
__invert__ = lambda x: ~(x._get_current_object())
__complex__ = lambda x: complex(x._get_current_object())
__int__ = lambda x: int(x._get_current_object())
__long__ = lambda x: long(x._get_current_object())
__long__ = lambda x: long(x._get_current_object()) # noqa
__float__ = lambda x: float(x._get_current_object())
__oct__ = lambda x: oct(x._get_current_object())
__hex__ = lambda x: hex(x._get_current_object())
Expand Down

0 comments on commit 453c57c

Please sign in to comment.