Skip to content

Commit

Permalink
Correcting not Py3-compatible syntax
Browse files Browse the repository at this point in the history
In Python 3:
* 'dict_values' object has no attribute 'sort'
* 'generator' object has no attribute 'next'
 --> Corresponding method calls replaced with cross-version builtins.
* data read from class files is 'bytes'
 --> 'str' changed to 'bytes', as the latter is present in Py2 as well
* xrange() is not present
 --> replaced with range() (as done everywhere else in 4a6cd21)
* iterkeys(), iteritems() are not present
 --> replaced with keys(), items()
  • Loading branch information
KonstantinShemyak committed Oct 11, 2018
1 parent a3522ab commit 86b47e3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion javatools/classinfo.py
Expand Up @@ -257,7 +257,7 @@ def cli_print_classinfo(options, info):
# generator skips them.
cpool = info.cpool

for i in xrange(1, len(cpool.consts)):
for i in range(1, len(cpool.consts)):
t, v = cpool.pretty_const(i)
if t:
# skipping the None consts, which would be the entries
Expand Down
2 changes: 1 addition & 1 deletion javatools/dirutils.py
Expand Up @@ -137,7 +137,7 @@ def _gen_from_dircmp(dc, lpath, rpath):
yield (BOTH, join(relpath(dc.left, lpath), f))

subdirs = dc.subdirs.values()
subdirs.sort()
subdirs = sorted(subdirs)
for sub in subdirs:
for event in _gen_from_dircmp(sub, lpath, rpath):
yield event
Expand Down
10 changes: 5 additions & 5 deletions javatools/distinfo.py
Expand Up @@ -91,9 +91,9 @@ def _collect_requires_provides(self):

for entry in self.get_jars():
ji = self.get_jarinfo(entry)
for sym, data in ji.get_requires().iteritems():
for sym, data in ji.get_requires().items():
req.setdefault(sym, []).append((REQ_BY_JAR, entry, data))
for sym, data in ji.get_provides().iteritems():
for sym, data in ji.get_provides().items():
prov.setdefault(sym, []).append((PROV_BY_JAR, entry, data))
p.add(sym)
ji.close()
Expand All @@ -107,7 +107,7 @@ def _collect_requires_provides(self):
for sym in ci.get_provides(private=True):
p.add(sym)

req = dict((k, v) for k, v in req.iteritems() if k not in p)
req = dict((k, v) for k, v in req.items() if k not in p)

self._requires = req
self._provides = prov
Expand All @@ -123,7 +123,7 @@ def get_requires(self, ignored=tuple()):

d = self._requires
if ignored:
d = dict((k, v) for k, v in d.iteritems()
d = dict((k, v) for k, v in d.items()
if not fnmatches(k, *ignored))
return d

Expand All @@ -139,7 +139,7 @@ def get_provides(self, ignored=tuple()):

d = self._provides
if ignored:
d = dict((k, v) for k, v in d.iteritems()
d = dict((k, v) for k, v in d.items()
if not fnmatches(k, *ignored))
return d

Expand Down
10 changes: 5 additions & 5 deletions javatools/jarinfo.py
Expand Up @@ -110,7 +110,7 @@ def _collect_requires_provides(self):
for sym in ci.get_provides(private=True):
p.add(sym)

req = dict((k, v) for k, v in req.iteritems() if k not in p)
req = dict((k, v) for k, v in req.items() if k not in p)

self._requires = req
self._provides = prov
Expand All @@ -122,7 +122,7 @@ def get_requires(self, ignored=tuple()):

d = self._requires
if ignored:
d = dict((k, v) for k, v in d.iteritems()
d = dict((k, v) for k, v in d.items()
if not fnmatches(k, *ignored))
return d

Expand All @@ -133,7 +133,7 @@ def get_provides(self, ignored=tuple()):

d = self._provides
if ignored:
d = dict((k, v) for k, v in d.iteritems()
d = dict((k, v) for k, v in d.items()
if not fnmatches(k, *ignored))
return d

Expand Down Expand Up @@ -230,7 +230,7 @@ def cli_jar_classes(options, jarinfo):
def cli_jar_provides(options, jarinfo):
print("jar provides:")

for provided in sorted(jarinfo.get_provides().iterkeys()):
for provided in sorted(jarinfo.get_provides().keys()):
if not fnmatches(provided, *options.api_ignore):
print(" ", provided)
print()
Expand All @@ -239,7 +239,7 @@ def cli_jar_provides(options, jarinfo):
def cli_jar_requires(options, jarinfo):
print("jar requires:")

for required in sorted(jarinfo.get_requires().iterkeys()):
for required in sorted(jarinfo.get_requires().keys()):
if not fnmatches(required, *options.api_ignore):
print(" ", required)
print()
Expand Down
2 changes: 1 addition & 1 deletion javatools/manifest.py
Expand Up @@ -356,7 +356,7 @@ def parse(self, data):
# the first section is the main one for the manifest. It's
# also where we will check for our newline separator
sections = parse_sections(data)
self.load(sections.next())
self.load(next(sections))

# and all following sections are considered sub-sections
for section in sections:
Expand Down
2 changes: 1 addition & 1 deletion javatools/pack.py
Expand Up @@ -344,7 +344,7 @@ def unpack(data):
unpacker:`
"""

if isinstance(data, (str, buffer)):
if isinstance(data, (bytes, buffer)):
return BufferUnpacker(data)

elif hasattr(data, "read"):
Expand Down

0 comments on commit 86b47e3

Please sign in to comment.