Skip to content

Commit aa12697

Browse files
committed
Merge pull request kivy#361 from a358003542/master
for some python3 compatibility
2 parents b1c6417 + 83f5ad6 commit aa12697

26 files changed

+1584
-1442
lines changed

src/build.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def render(template, dest, **kwargs):
6868
template = environment.get_template(template)
6969
text = template.render(**kwargs)
7070

71-
f = file(dest, 'wb')
71+
f = open(dest, 'wb')#
7272
f.write(text.encode('utf-8'))
7373
f.close()
7474

@@ -183,7 +183,7 @@ def select(fn):
183183
tf = tarfile.open(tfn, 'w:gz', format=tarfile.USTAR_FORMAT)
184184
dirs = []
185185
for fn, afn in files:
186-
print '%s: %s' % (tfn, fn)
186+
print('%s: %s' % (tfn, fn))
187187
dn = dirname(afn)
188188
if dn not in dirs:
189189
# create every dirs first if not exist yet
@@ -224,7 +224,8 @@ def make_package(args):
224224

225225
args.numeric_version = str(version_code)
226226

227-
args.name = args.name.decode('utf-8')
227+
if sys.version_info[0] == 2:
228+
args.name = args.name.decode('utf-8')
228229
if args.icon_name:
229230
args.icon_name = args.icon_name.decode('utf-8')
230231

@@ -306,8 +307,8 @@ def make_package(args):
306307
subprocess.call([ANDROID, 'update', 'project', '-p', '.', '-t',
307308
'android-{}'.format(args.sdk_version)])
308309
except (OSError, IOError):
309-
print 'An error occured while calling', ANDROID, 'update'
310-
print 'Your PATH must include android tools.'
310+
print('An error occured while calling', ANDROID, 'update')
311+
print('Your PATH must include android tools.')
311312
sys.exit(-1)
312313

313314
# Delete the old assets.
@@ -346,7 +347,7 @@ def make_package(args):
346347
if args.add_jar:
347348
for jarname in args.add_jar:
348349
if not os.path.exists(jarname):
349-
print 'Requested jar does not exist: {}'.format(jarname)
350+
print('Requested jar does not exist: {}'.format(jarname))
350351
sys.exit(-1)
351352
shutil.copy(jarname, 'libs')
352353

@@ -355,8 +356,8 @@ def make_package(args):
355356
for arg in args.command:
356357
subprocess.check_call([ANT, arg])
357358
except (OSError, IOError):
358-
print 'An error occured while calling', ANT
359-
print 'Did you install ant on your system ?'
359+
print('An error occured while calling', ANT)
360+
print('Did you install ant on your system ?')
360361
sys.exit(-1)
361362

362363
if __name__ == '__main__':

src/buildlib/jinja2.egg/jinja2/__init__.py

100755100644
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727
:license: BSD, see LICENSE for more details.
2828
"""
2929
__docformat__ = 'restructuredtext en'
30-
try:
31-
__version__ = __import__('pkg_resources') \
32-
.get_distribution('Jinja2').version
33-
except:
34-
__version__ = 'unknown'
30+
__version__ = '2.7.2'
3531

3632
# high level interface
3733
from jinja2.environment import Environment, Template
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
jinja2._compat
4+
~~~~~~~~~~~~~~
5+
6+
Some py2/py3 compatibility support based on a stripped down
7+
version of six so we don't have to depend on a specific version
8+
of it.
9+
10+
:copyright: Copyright 2013 by the Jinja team, see AUTHORS.
11+
:license: BSD, see LICENSE for details.
12+
"""
13+
import sys
14+
15+
PY2 = sys.version_info[0] == 2
16+
PYPY = hasattr(sys, 'pypy_translation_info')
17+
_identity = lambda x: x
18+
19+
20+
if not PY2:
21+
unichr = chr
22+
range_type = range
23+
text_type = str
24+
string_types = (str,)
25+
26+
iterkeys = lambda d: iter(d.keys())
27+
itervalues = lambda d: iter(d.values())
28+
iteritems = lambda d: iter(d.items())
29+
30+
import pickle
31+
from io import BytesIO, StringIO
32+
NativeStringIO = StringIO
33+
34+
def reraise(tp, value, tb=None):
35+
if value.__traceback__ is not tb:
36+
raise value.with_traceback(tb)
37+
raise value
38+
39+
ifilter = filter
40+
imap = map
41+
izip = zip
42+
intern = sys.intern
43+
44+
implements_iterator = _identity
45+
implements_to_string = _identity
46+
encode_filename = _identity
47+
get_next = lambda x: x.__next__
48+
49+
else:
50+
unichr = unichr
51+
text_type = unicode
52+
range_type = xrange
53+
string_types = (str, unicode)
54+
55+
iterkeys = lambda d: d.iterkeys()
56+
itervalues = lambda d: d.itervalues()
57+
iteritems = lambda d: d.iteritems()
58+
59+
import cPickle as pickle
60+
from cStringIO import StringIO as BytesIO, StringIO
61+
NativeStringIO = BytesIO
62+
63+
exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')
64+
65+
from itertools import imap, izip, ifilter
66+
intern = intern
67+
68+
def implements_iterator(cls):
69+
cls.next = cls.__next__
70+
del cls.__next__
71+
return cls
72+
73+
def implements_to_string(cls):
74+
cls.__unicode__ = cls.__str__
75+
cls.__str__ = lambda x: x.__unicode__().encode('utf-8')
76+
return cls
77+
78+
get_next = lambda x: x.next
79+
80+
def encode_filename(filename):
81+
if isinstance(filename, unicode):
82+
return filename.encode('utf-8')
83+
return filename
84+
85+
try:
86+
next = next
87+
except NameError:
88+
def next(it):
89+
return it.next()
90+
91+
92+
def with_metaclass(meta, *bases):
93+
# This requires a bit of explanation: the basic idea is to make a
94+
# dummy metaclass for one level of class instanciation that replaces
95+
# itself with the actual metaclass. Because of internal type checks
96+
# we also need to make sure that we downgrade the custom metaclass
97+
# for one level to something closer to type (that's why __call__ and
98+
# __init__ comes back from type etc.).
99+
#
100+
# This has the advantage over six.with_metaclass in that it does not
101+
# introduce dummy classes into the final MRO.
102+
class metaclass(meta):
103+
__call__ = type.__call__
104+
__init__ = type.__init__
105+
def __new__(cls, name, this_bases, d):
106+
if this_bases is None:
107+
return type.__new__(cls, name, (), d)
108+
return meta(name, bases, d)
109+
return metaclass('temporary_class', None, {})
110+
111+
112+
try:
113+
from collections import Mapping as mapping_types
114+
except ImportError:
115+
import UserDict
116+
mapping_types = (UserDict.UserDict, UserDict.DictMixin, dict)
117+
118+
119+
# common types. These do exist in the special types module too which however
120+
# does not exist in IronPython out of the box. Also that way we don't have
121+
# to deal with implementation specific stuff here
122+
class _C(object):
123+
def method(self): pass
124+
def _func():
125+
yield None
126+
function_type = type(_func)
127+
generator_type = type(_func())
128+
method_type = type(_C().method)
129+
code_type = type(_C.method.__code__)
130+
try:
131+
raise TypeError()
132+
except TypeError:
133+
_tb = sys.exc_info()[2]
134+
traceback_type = type(_tb)
135+
frame_type = type(_tb.tb_frame)
136+
137+
138+
try:
139+
from urllib.parse import quote_from_bytes as url_quote
140+
except ImportError:
141+
from urllib import quote as url_quote
142+
143+
144+
try:
145+
from thread import allocate_lock
146+
except ImportError:
147+
try:
148+
from threading import Lock as allocate_lock
149+
except ImportError:
150+
from dummy_thread import allocate_lock

0 commit comments

Comments
 (0)