Skip to content

Commit 89d8dab

Browse files
committed
2to3
1 parent 707532f commit 89d8dab

File tree

146 files changed

+594
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+594
-600
lines changed

source_py3/python_toolbox/_bootstrap/bootstrap_py2exe/python26_site.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
import sys
6262
import os
63-
import __builtin__
63+
import builtins
6464

6565
# Prefixes for site-packages; add additional prefixes like /usr/local here
6666
PREFIXES = [sys.prefix, sys.exec_prefix]
@@ -79,7 +79,7 @@ def makepath(*paths):
7979

8080
def abs__file__():
8181
"""Set all module' __file__ attribute to an absolute path"""
82-
for m in sys.modules.values():
82+
for m in list(sys.modules.values()):
8383
if hasattr(m, '__loader__'):
8484
continue # don't mess with a PEP 302-supplied __file__
8585
try:
@@ -152,7 +152,7 @@ def addpackage(sitedir, name, known_paths):
152152
if line.startswith("#"):
153153
continue
154154
if line.startswith(("import ", "import\t")):
155-
exec line
155+
exec(line)
156156
continue
157157
line = line.rstrip()
158158
dir, dircase = makepath(sitedir, line)
@@ -332,8 +332,8 @@ def __call__(self, code=None):
332332
except:
333333
pass
334334
raise SystemExit(code)
335-
__builtin__.quit = Quitter('quit')
336-
__builtin__.exit = Quitter('exit')
335+
builtins.quit = Quitter('quit')
336+
builtins.exit = Quitter('exit')
337337

338338

339339
class _Printer(object):
@@ -384,32 +384,32 @@ def __call__(self):
384384
while 1:
385385
try:
386386
for i in range(lineno, lineno + self.MAXLINES):
387-
print self.__lines[i]
387+
print(self.__lines[i])
388388
except IndexError:
389389
break
390390
else:
391391
lineno += self.MAXLINES
392392
key = None
393393
while key is None:
394-
key = raw_input(prompt)
394+
key = input(prompt)
395395
if key not in ('', 'q'):
396396
key = None
397397
if key == 'q':
398398
break
399399

400400
def setcopyright():
401401
"""Set 'copyright' and 'credits' in __builtin__"""
402-
__builtin__.copyright = _Printer("copyright", sys.copyright)
402+
builtins.copyright = _Printer("copyright", sys.copyright)
403403
if sys.platform[:4] == 'java':
404-
__builtin__.credits = _Printer(
404+
builtins.credits = _Printer(
405405
"credits",
406406
"Jython is maintained by the Jython developers (www.jython.org).")
407407
else:
408-
__builtin__.credits = _Printer("credits", """\
408+
builtins.credits = _Printer("credits", """\
409409
Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
410410
for supporting Python development. See www.python.org for more information.""")
411411
here = os.path.dirname(os.__file__)
412-
__builtin__.license = _Printer(
412+
builtins.license = _Printer(
413413
"license", "See http://www.python.org/%.3s/license.html" % sys.version,
414414
["LICENSE.txt", "LICENSE"],
415415
[os.path.join(here, os.pardir), here, os.curdir])
@@ -429,7 +429,7 @@ def __call__(self, *args, **kwds):
429429
return pydoc.help(*args, **kwds)
430430

431431
def sethelper():
432-
__builtin__.help = _Helper()
432+
builtins.help = _Helper()
433433

434434
def aliasmbcs():
435435
"""On Windows, some default encodings are not provided by Python,
@@ -476,8 +476,7 @@ def execsitecustomize():
476476
if sys.flags.verbose:
477477
sys.excepthook(*sys.exc_info())
478478
else:
479-
print >>sys.stderr, \
480-
"'import sitecustomize' failed; use -v for traceback"
479+
print("'import sitecustomize' failed; use -v for traceback", file=sys.stderr)
481480

482481

483482
def execusercustomize():
@@ -490,8 +489,7 @@ def execusercustomize():
490489
if sys.flags.verbose:
491490
sys.excepthook(*sys.exc_info())
492491
else:
493-
print>>sys.stderr, \
494-
"'import usercustomize' failed; use -v for traceback"
492+
print("'import usercustomize' failed; use -v for traceback", file=sys.stderr)
495493

496494

497495
def main():
@@ -541,15 +539,15 @@ def _script():
541539
"""
542540
args = sys.argv[1:]
543541
if not args:
544-
print "sys.path = ["
542+
print("sys.path = [")
545543
for dir in sys.path:
546-
print " %r," % (dir,)
547-
print "]"
548-
print "USER_BASE: %r (%s)" % (USER_BASE,
549-
"exists" if os.path.isdir(USER_BASE) else "doesn't exist")
550-
print "USER_SITE: %r (%s)" % (USER_SITE,
551-
"exists" if os.path.isdir(USER_SITE) else "doesn't exist")
552-
print "ENABLE_USER_SITE: %r" % ENABLE_USER_SITE
544+
print(" %r," % (dir,))
545+
print("]")
546+
print("USER_BASE: %r (%s)" % (USER_BASE,
547+
"exists" if os.path.isdir(USER_BASE) else "doesn't exist"))
548+
print("USER_SITE: %r (%s)" % (USER_SITE,
549+
"exists" if os.path.isdir(USER_SITE) else "doesn't exist"))
550+
print("ENABLE_USER_SITE: %r" % ENABLE_USER_SITE)
553551
sys.exit(0)
554552

555553
buffer = []
@@ -559,7 +557,7 @@ def _script():
559557
buffer.append(USER_SITE)
560558

561559
if buffer:
562-
print os.pathsep.join(buffer)
560+
print(os.pathsep.join(buffer))
563561
if ENABLE_USER_SITE:
564562
sys.exit(0)
565563
elif ENABLE_USER_SITE is False:
@@ -570,7 +568,7 @@ def _script():
570568
sys.exit(3)
571569
else:
572570
import textwrap
573-
print textwrap.dedent(help % (sys.argv[0], os.pathsep))
571+
print(textwrap.dedent(help % (sys.argv[0], os.pathsep)))
574572
sys.exit(10)
575573

576574
if __name__ == '__main__':

source_py3/python_toolbox/address_tools/object_to_string.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def get_address(obj, shorten=False, root=None, namespace={}):
148148
if isinstance(obj, types.ModuleType):
149149
address = obj.__name__
150150
elif isinstance(obj, types.MethodType):
151-
address = '.'.join((obj.__module__, obj.im_class.__name__,
151+
address = '.'.join((obj.__module__, obj.__self__.__class__.__name__,
152152
obj.__name__))
153153
else:
154154
address= '.'.join((obj.__module__, obj.__name__))
@@ -182,9 +182,9 @@ def get_address(obj, shorten=False, root=None, namespace={}):
182182
if root or namespace:
183183

184184
# Ensuring `root` and `namespace` are actual objects:
185-
if isinstance(root, basestring):
185+
if isinstance(root, str):
186186
root = get_object_by_address(root)
187-
if isinstance(namespace, basestring):
187+
if isinstance(namespace, str):
188188
namespace = get_object_by_address(namespace)
189189

190190

@@ -195,23 +195,23 @@ def get_address(obj, shorten=False, root=None, namespace={}):
195195

196196
def my_filter(key, value):
197197
name = getattr(value, '__name__', '')
198-
return isinstance(name, basestring) and name.endswith(key)
198+
return isinstance(name, str) and name.endswith(key)
199199

200200
namespace_dict = dict_tools.filter_items(
201201
original_namespace_dict,
202202
my_filter
203203
)
204204

205-
namespace_dict_keys = namespace_dict.keys()
206-
namespace_dict_values = namespace_dict.values()
205+
namespace_dict_keys = list(namespace_dict.keys())
206+
namespace_dict_values = list(namespace_dict.values())
207207

208208

209209
# Split to address parts:
210210
address_parts = address.split('.')
211211
# e.g., `['python_toolbox', 'misc', 'step_copy', 'StepCopy']`.
212212

213213
heads = ['.'.join(address_parts[:i]) for i in
214-
xrange(1, len(address_parts) + 1)]
214+
range(1, len(address_parts) + 1)]
215215
# `heads` is something like: `['python_toolbox',
216216
# 'python_toolbox.caching', 'python_toolbox.caching.cached_type',
217217
# 'python_toolbox.cached_type.CachedType']`

source_py3/python_toolbox/address_tools/string_to_object.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ def get_object_by_address(address, root=None, namespace={}):
101101

102102
if root:
103103
# First for `root`:
104-
if isinstance(root, basestring):
104+
if isinstance(root, str):
105105
root = get_object_by_address(root)
106106
root_short_name = root.__name__.rsplit('.', 1)[-1]
107107

108108
if namespace:
109109
# And then for `namespace`:
110-
if isinstance(namespace, basestring):
110+
if isinstance(namespace, str):
111111
namespace = get_object_by_address(namespace)
112112

113113
parent_object, namespace_dict = _get_parent_and_dict_from_namespace(

source_py3/python_toolbox/arguments_profile.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from python_toolbox.nifty_collections import OrderedDict
1313
from python_toolbox import dict_tools
1414
from python_toolbox import comparison_tools
15+
import collections
1516

1617

1718
class ArgumentsProfile(object):
@@ -92,7 +93,7 @@ def __init__(self, function, *args, **kwargs):
9293
`*args` and `**kwargs` are the arguments that go into the `function`.
9394
'''
9495

95-
if not callable(function):
96+
if not isinstance(function, collections.Callable):
9697
raise Exception('%s is not a callable object.' % function)
9798
self.function = function
9899

@@ -159,7 +160,7 @@ def __init__(self, function, *args, **kwargs):
159160
else []
160161

161162
# `dict` that maps from argument name to default value:
162-
defaults = OrderedDict(zip(defaultful_args, s_defaults))
163+
defaults = OrderedDict(list(zip(defaultful_args, s_defaults)))
163164

164165
defaultful_args_differing_from_defaults = set((
165166
defaultful_arg for defaultful_arg in defaultful_args
@@ -230,7 +231,7 @@ def __init__(self, function, *args, **kwargs):
230231
# Now we iterate on the candidates to find out which one has the
231232
# lowest price:
232233

233-
for candidate in xrange(n_defaultful_args + 1):
234+
for candidate in range(n_defaultful_args + 1):
234235

235236
defaultful_args_to_specify_positionally = \
236237
defaultful_args[:candidate]
@@ -246,10 +247,10 @@ def __init__(self, function, *args, **kwargs):
246247
# The `2 * candidate` addend is to account for the ", " parts
247248
# between the arguments.
248249

249-
defaultful_args_to_specify_by_keyword = filter(
250+
defaultful_args_to_specify_by_keyword = list(filter(
250251
defaultful_args_differing_from_defaults.__contains__,
251252
defaultful_args[candidate:]
252-
)
253+
))
253254

254255
price_for_defaultful_args_specified_by_keyword = \
255256
2 * len(defaultful_args_to_specify_by_keyword) + \
@@ -288,11 +289,11 @@ def __init__(self, function, *args, **kwargs):
288289

289290
# Finished iterating on candidates! Time to pick our winner.
290291

291-
minimum_price = min(total_price_for_n_dasp_candidate.itervalues())
292+
minimum_price = min(total_price_for_n_dasp_candidate.values())
292293

293294
leading_candidates = [
294295
candidate for candidate in
295-
total_price_for_n_dasp_candidate.iterkeys() if
296+
total_price_for_n_dasp_candidate.keys() if
296297
total_price_for_n_dasp_candidate[candidate] == minimum_price
297298
]
298299

@@ -327,10 +328,10 @@ def __init__(self, function, *args, **kwargs):
327328

328329
# Now we add those specified by keyword:
329330

330-
defaultful_args_to_specify_by_keyword = filter(
331+
defaultful_args_to_specify_by_keyword = list(filter(
331332
defaultful_args_differing_from_defaults.__contains__,
332333
defaultful_args[n_defaultful_args_to_specify_positionally:]
333-
)
334+
))
334335
for defaultful_arg in defaultful_args_to_specify_by_keyword:
335336
self.kwargs[defaultful_arg] = getcallargs_result[defaultful_arg]
336337

@@ -356,20 +357,20 @@ def __init__(self, function, *args, **kwargs):
356357
# according to canonical ordering. So we need to sort them first.
357358

358359
unsorted_star_kwargs_names = \
359-
getcallargs_result[s_star_kwargs].keys()
360+
list(getcallargs_result[s_star_kwargs].keys())
360361
sorted_star_kwargs_names = sorted(
361362
unsorted_star_kwargs_names,
362363
key=comparison_tools.underscore_hating_key
363364
)
364365

365366
sorted_star_kwargs = OrderedDict(
366-
zip(
367+
list(zip(
367368
sorted_star_kwargs_names,
368369
dict_tools.get_list(
369370
getcallargs_result[s_star_kwargs],
370371
sorted_star_kwargs_names
371372
)
372-
)
373+
))
373374
)
374375

375376

@@ -426,17 +427,17 @@ def get(self, argument_name, default=None):
426427

427428
def keys(self):
428429
'''Get all the argument names.'''
429-
return self._arguments.keys()
430+
return list(self._arguments.keys())
430431

431432

432433
def values(self):
433434
'''Get all the argument values.'''
434-
return self._arguments.values()
435+
return list(self._arguments.values())
435436

436437

437438
def items(self):
438439
'''Get a tuple of all the `(argument_name, argument_value)` item.'''
439-
return self._arguments.items()
440+
return list(self._arguments.items())
440441

441442

442443
def __iter__(self):
@@ -446,17 +447,17 @@ def __iter__(self):
446447

447448
def iterkeys(self):
448449
'''Iterate on the argument names according to their order.'''
449-
return self._arguments.iterkeys()
450+
return iter(self._arguments.keys())
450451

451452

452453
def itervalues(self):
453454
'''Iterate on the argument value according to their order.'''
454-
return self._arguments.itervalues()
455+
return iter(self._arguments.values())
455456

456457

457458
def iteritems(self):
458459
'''Iterate on `(argument_name, argument_value)` items by order.'''
459-
return self._arguments.iteritems()
460+
return iter(self._arguments.items())
460461

461462

462463
def __contains__(self, argument_name):

source_py3/python_toolbox/binary_search/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def binary_search_by_index(sequence, function, value, rounding=CLOSEST):
3131
'''
3232
if function is None:
3333
function = lambda x: x
34-
my_range = xrange(len(sequence))
34+
my_range = range(len(sequence))
3535
fixed_function = lambda index: function(sequence[index])
3636
result = binary_search(my_range, fixed_function, value, rounding)
3737
return result

source_py3/python_toolbox/caching/cached_property.py

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

1010
from python_toolbox import decorator_tools
1111
from python_toolbox import misc_tools
12+
import collections
1213

1314

1415
class CachedProperty(misc_tools.OwnNameDiscoveringDescriptor):
@@ -46,7 +47,7 @@ def __init__(self, getter_or_value, doc=None, name=None,
4647
class; this will save a bit of processing later.
4748
'''
4849
misc_tools.OwnNameDiscoveringDescriptor.__init__(self, name=name)
49-
if callable(getter_or_value) and not force_value_not_getter:
50+
if isinstance(getter_or_value, collections.Callable) and not force_value_not_getter:
5051
self.getter = getter_or_value
5152
else:
5253
self.getter = lambda thing: getter_or_value

source_py3/python_toolbox/caching/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ def decorator(function):
101101
def remove_expired_entries():
102102
almost_cutting_point = \
103103
binary_search.binary_search_by_index(
104-
cached._cache.keys(),
104+
list(cached._cache.keys()),
105105
sorting_key_function,
106106
_get_now(),
107107
rounding=binary_search.LOW
108108
)
109109
if almost_cutting_point is not None:
110110
cutting_point = almost_cutting_point + 1
111-
for key in cached._cache.keys()[:cutting_point]:
111+
for key in list(cached._cache.keys())[:cutting_point]:
112112
del cached._cache[key]
113113

114114

0 commit comments

Comments
 (0)