Skip to content

Commit 5adbcd9

Browse files
committed
Run 2to3 -x unicode -x basestring
$ 2to3 -x unicode -x basestring --write --nobackups --no-diffs --doctests_only pystache $ 2to3 -x unicode -x basestring --write --nobackups --no-diffs pystache
1 parent f9ca07a commit 5adbcd9

17 files changed

+57
-51
lines changed

pystache/commands/render.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from sys import exc_info
2323
ex_type, ex_value, tb = exc_info()
2424
new_ex = Exception("%s: %s" % (ex_type.__name__, ex_value))
25-
raise new_ex.__class__, new_ex, tb
25+
raise new_ex.__class__(new_ex).with_traceback(tb)
2626

2727
# The optparse module is deprecated in Python 2.7 in favor of argparse.
2828
# However, argparse is not available in Python 2.6 and earlier.
@@ -88,7 +88,7 @@ def main(sys_argv=sys.argv):
8888
context = json.loads(context)
8989

9090
rendered = renderer.render(template, context)
91-
print rendered
91+
print(rendered)
9292

9393

9494
if __name__=='__main__':

pystache/context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
from pystache.common import PystacheError
18+
import collections
1819

1920

2021
# This equals '__builtin__' in Python 2 and 'builtins' in Python 3.
@@ -69,7 +70,7 @@ def _get_value(context, key):
6970
else:
7071
# TODO: consider using EAFP here instead.
7172
# http://docs.python.org/glossary.html#term-eafp
72-
if callable(attr):
73+
if isinstance(attr, collections.Callable):
7374
return attr()
7475
return attr
7576

pystache/parsed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def get_unicode(node):
4444
if type(node) is unicode:
4545
return node
4646
return node.render(engine, context)
47-
parts = map(get_unicode, self._parse_tree)
47+
parts = list(map(get_unicode, self._parse_tree))
4848
s = ''.join(parts)
4949

5050
return unicode(s)

pystache/parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from pystache import defaults
1111
from pystache.parsed import ParsedTemplate
12+
import collections
1213

1314

1415
END_OF_LINE_CHARACTERS = [u'\r', u'\n']
@@ -31,7 +32,7 @@ def parse(template, delimiters=None):
3132
Examples:
3233
3334
>>> parsed = parse(u"Hey {{#who}}{{name}}!{{/who}}")
34-
>>> print str(parsed).replace('u', '') # This is a hack to get the test to pass both in Python 2 and 3.
35+
>>> print(str(parsed).replace('u', '')) # This is a hack to get the test to pass both in Python 2 and 3.
3536
['Hey ', _SectionNode(key='who', index_begin=12, index_end=21, parsed=[_EscapeNode(key='name'), '!'])]
3637
3738
"""
@@ -193,7 +194,7 @@ def render(self, engine, context):
193194

194195
parts = []
195196
for val in values:
196-
if callable(val):
197+
if isinstance(val, collections.Callable):
197198
# Lambdas special case section rendering and bypass pushing
198199
# the data value onto the context stack. From the spec--
199200
#
@@ -376,3 +377,4 @@ def _make_section_node(self, template, tag_type, tag_key, parsed_section,
376377
return _InvertedNode(tag_key, parsed_section)
377378

378379
raise Exception("Invalid symbol for section tag: %s" % repr(tag_type))
380+

pystache/renderengine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from pystache.common import is_string
1111
from pystache.parser import parse
12+
import collections
1213

1314

1415
def context_get(stack, name):
@@ -104,7 +105,7 @@ def fetch_string(self, context, name):
104105
"""
105106
val = self.resolve_context(context, name)
106107

107-
if callable(val):
108+
if isinstance(val, collections.Callable):
108109
# Return because _render_value() is already a string.
109110
return self._render_value(val(), context)
110111

pystache/renderer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Renderer(object):
3232
>>> partials = {'partial': 'Hello, {{thing}}!'}
3333
>>> renderer = Renderer(partials=partials)
3434
>>> # We apply print to make the test work in Python 3 after 2to3.
35-
>>> print renderer.render('{{>partial}}', {'thing': 'world'})
35+
>>> print(renderer.render('{{>partial}}', {'thing': 'world'}))
3636
Hello, world!
3737
3838
To customize string coercion (e.g. to render False values as ''), one can
@@ -458,3 +458,4 @@ def render(self, template, *context, **kwargs):
458458
# Otherwise, we assume the template is an object.
459459

460460
return self._render_object(template, *context, **kwargs)
461+

pystache/tests/benchmark.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ def main(sys_argv):
7676
args = sys_argv[1:]
7777
count = int(args[0])
7878

79-
print "Benchmarking: %sx" % count
80-
print
79+
print("Benchmarking: %sx" % count)
80+
print()
8181

8282
for example in examples:
8383

8484
test = make_test_function(example)
8585

8686
t = Timer(test,)
87-
print min(t.repeat(repeat=3, number=count))
87+
print(min(t.repeat(repeat=3, number=count)))
8888

89-
print "Done"
89+
print("Done")
9090

9191

9292
if __name__ == '__main__':

pystache/tests/common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def _find_files(root_dir, should_include):
7272
# http://docs.python.org/library/os.html#os.walk
7373
for dir_path, dir_names, file_names in os.walk(root_dir):
7474
new_paths = [os.path.join(dir_path, file_name) for file_name in file_names]
75-
new_paths = filter(is_module, new_paths)
76-
new_paths = filter(should_include, new_paths)
75+
new_paths = list(filter(is_module, new_paths))
76+
new_paths = list(filter(should_include, new_paths))
7777
paths.extend(new_paths)
7878

7979
return paths
@@ -183,7 +183,7 @@ def assertException(self, exception_type, msg, callable, *args, **kwds):
183183
try:
184184
callable(*args, **kwds)
185185
raise Exception("Expected exception: %s: %s" % (exception_type, repr(msg)))
186-
except exception_type, err:
186+
except exception_type as err:
187187
self.assertEqual(str(err), msg)
188188

189189

@@ -228,10 +228,10 @@ class Attachable(object):
228228
"""
229229
def __init__(self, **kwargs):
230230
self.__args__ = kwargs
231-
for arg, value in kwargs.iteritems():
231+
for arg, value in kwargs.items():
232232
setattr(self, arg, value)
233233

234234
def __repr__(self):
235235
return "%s(%s)" % (self.__class__.__name__,
236236
", ".join("%s=%s" % (k, repr(v))
237-
for k, v in self.__args__.iteritems()))
237+
for k, v in self.__args__.items()))

pystache/tests/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def main(sys_argv):
8888
8989
"""
9090
# TODO: use logging module
91-
print "pystache: running tests: argv: %s" % repr(sys_argv)
91+
print("pystache: running tests: argv: %s" % repr(sys_argv))
9292

9393
should_source_exist = False
9494
spec_test_dir = None

pystache/tests/spectesting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from sys import exc_info
3838
ex_type, ex_value, tb = exc_info()
3939
new_ex = Exception("%s: %s" % (ex_type.__name__, ex_value))
40-
raise new_ex.__class__, new_ex, tb
40+
raise new_ex.__class__(new_ex).with_traceback(tb)
4141
file_extension = 'json'
4242
parser = json
4343
else:
@@ -62,7 +62,7 @@ def get_spec_tests(spec_test_dir):
6262
6363
"""
6464
# TODO: use logging module instead.
65-
print "pystache: spec tests: using %s" % _get_parser_info()
65+
print("pystache: spec tests: using %s" % _get_parser_info())
6666

6767
cases = []
6868

@@ -133,7 +133,7 @@ def _convert_children(node):
133133
return
134134
# Otherwise, node is a dict, so attempt the conversion.
135135

136-
for key in node.keys():
136+
for key in list(node.keys()):
137137
val = node[key]
138138

139139
if not isinstance(val, dict) or val.get('__tag__') != 'code':
@@ -160,7 +160,7 @@ def _deserialize_spec_test(data, file_path):
160160
# PyYAML seems to leave ASCII strings as byte strings.
161161
expected = unicode(data['expected'])
162162
# TODO: switch to using dict.get().
163-
partials = data.has_key('partials') and data['partials'] or {}
163+
partials = 'partials' in data and data['partials'] or {}
164164
template = data['template']
165165
test_name = data['name']
166166

0 commit comments

Comments
 (0)