Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced .iteritems() with six.iteritems() for Python 2 and 3 compat #274

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pdfminer/cmapdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def use_cmap(self, cmap):
assert isinstance(cmap, CMap), str(type(cmap))

def copy(dst, src):
for (k, v) in src.iteritems():
for (k, v) in six.iteritems(src):
if isinstance(v, dict):
d = {}
dst[k] = d
Expand All @@ -110,7 +110,7 @@ def dump(self, out=sys.stdout, code2cid=None, code=None):
if code2cid is None:
code2cid = self.code2cid
code = ()
for (k, v) in sorted(code2cid.iteritems()):
for (k, v) in sorted(six.iteritems(code2cid)):
c = code+(k,)
if isinstance(v, int):
out.write('code %r = cid %d\n' % (c, v))
Expand Down Expand Up @@ -148,7 +148,7 @@ def get_unichr(self, cid):
return self.cid2unichr[cid]

def dump(self, out=sys.stdout):
for (k, v) in sorted(self.cid2unichr.iteritems()):
for (k, v) in sorted(six.iteritems(self.cid2unichr)):
out.write('cid %d = unicode %r\n' % (k, v))
return

Expand Down
2 changes: 1 addition & 1 deletion pdfminer/pdfdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def begin_tag(self, tag, props=None):
s = ''
if isinstance(props, dict):
s = ''.join(' %s="%s"' % (utils.enc(k), utils.enc(str(v))) for (k, v)
in sorted(props.iteritems()))
in sorted(six.iteritems(props)))
out_s = '<%s%s>' % (utils.enc(tag.name), s)
self.outfp.write(utils.make_compat_bytes(out_s))
self._stack.append(tag)
Expand Down
2 changes: 1 addition & 1 deletion pdfminer/pdffont.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def create_unicode_map(self):
assert False, str(('Unhandled', fmttype))
# create unicode map
unicode_map = FileUnicodeMap()
for (char, gid) in char2gid.iteritems():
for (char, gid) in six.iteritems(char2gid):
unicode_map.add_cid2unichr(gid, char)
return unicode_map

Expand Down
2 changes: 1 addition & 1 deletion pdfminer/pdftypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def resolve_all(x, default=None):
if isinstance(x, list):
x = [resolve_all(v, default=default) for v in x]
elif isinstance(x, dict):
for (k, v) in x.iteritems():
for (k, v) in six.iteritems(x):
x[k] = resolve_all(v, default=default)
return x

Expand Down
4 changes: 3 additions & 1 deletion tools/conv_afm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import sys
import fileinput

import six #Python 2+3 compatibility

def main(argv):
fonts = {}
for line in fileinput.input():
Expand Down Expand Up @@ -33,7 +35,7 @@ def main(argv):
props[k] = tuple(map(float, f[1:5]))
print ('# -*- python -*-')
print ('FONT_METRICS = {')
for (fontname,(props,chars)) in fonts.iteritems():
for (fontname,(props,chars)) in six.iteritems(fonts):
print (' %r: %r,' % (fontname, (props,chars)))
print ('}')
return 0
Expand Down
3 changes: 2 additions & 1 deletion tools/pdf2html.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import HTMLConverter, TextConverter
from pdfminer.layout import LAParams

import six #Python 2+3 compatibility

# quote HTML metacharacters
def q(x):
Expand All @@ -35,7 +36,7 @@ def q(x):
Q = re.compile(r'[^a-zA-Z0-9_.-=]')
def url(base, **kw):
r = []
for (k,v) in kw.iteritems():
for (k,v) in six.iteritems(kw):
v = Q.sub(lambda m: '%%%02X' % ord(m.group(0)), encoder(q(v), 'replace')[0])
r.append('%s=%s' % (k, v))
return base+'&'.join(r)
Expand Down