From 6405f8ed1a9754d64ed1a5a9476dc681dec42ef9 Mon Sep 17 00:00:00 2001
From: Yuchen Pei <me@ypei.me>
Date: Thu, 24 Dec 2020 11:35:23 +0100
Subject: [PATCH] Updating the python files using 2to3.

---
 export.py          | 14 +++++++-------
 export_json.py     |  4 ++--
 json_to_wiki.py    |  6 +++---
 license_summary.py |  2 +-
 load_changelog.py  |  4 ++--
 load_copyright.py  | 16 ++++++++--------
 load_packages.py   |  2 +-
 load_sources.py    |  2 +-
 pkg_summary.py     |  4 ++--
 9 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/export.py b/export.py
index bf45e5e..672548d 100644
--- a/export.py
+++ b/export.py
@@ -42,7 +42,7 @@ def today():
 
 def warn(*x):
     for s in ('warning:',) + x + ('\n',):
-        print >>sys.stderr, s,
+        print(s, end=' ', file=sys.stderr)
 
 class ExportFailure(Exception):
     pass
@@ -66,7 +66,7 @@ class PkgData(object):
         cl_store.close()
 
 def nouni(s):
-    return s.encode('utf8') if isinstance(s, unicode) else s
+    return s.encode('utf8') if isinstance(s, str) else s
 
 class Template(object):
     def __init__(self, name, values):
@@ -165,7 +165,7 @@ def srcpkg_extract_licenses(header, filess, licenses, cl_date, cl_uploader):
         canon = lmap.get(ldesc.lower(), 'Other')
         # XXX: Should maybe bail if there's no copyright field.
         cp = ''.join(
-            u'Copyright %s' % line.lstrip()
+            'Copyright %s' % line.lstrip()
             for line in files.dropna().get('Copyright', '').splitlines())
         cp = cp.encode('utf8')
         txt = txt.encode('utf8')
@@ -280,7 +280,7 @@ def export_srcpkgs(data, name, srcpkg_names):
         ('Source link',
             'http://packages.debian.org/sid/' + srcpkg_names[0]),
         ('Source packages',
-             ', '.join('%s %s' % (k, v) for (k, v) in versions.iteritems())),
+             ', '.join('%s %s' % (k, v) for (k, v) in versions.items())),
         ('Date', today())])
 
     people = []
@@ -386,12 +386,12 @@ def export_all(data):
 def export_all_to_directory(data, outputdir):
     def _export():
         for (name, templates) in export_all(data):
-            print (name.encode('utf8') if isinstance(name, unicode) else name)
+            print((name.encode('utf8') if isinstance(name, str) else name))
 
             try:
                 # Force errors.
                 templates = list(templates)
-            except ExportFailure, e:
+            except ExportFailure as e:
                 warn('export failed: %s: %s' % (name.encode('utf-8').strip(), e.message.encode('utf-8').strip()))
 
             yield(name, templates)
@@ -411,7 +411,7 @@ def main():
         templates = export_srcpkgs(data, uname, srcpkgs)
 
         for template in templates:
-            print template
+            print(template)
     else:
         raise RuntimeError()
 
diff --git a/export_json.py b/export_json.py
index e4f0d3d..ee4cd98 100644
--- a/export_json.py
+++ b/export_json.py
@@ -26,7 +26,7 @@ def main():
         try:
             # Force errors.
             templates = list(templates)
-        except export.ExportFailure, e:
+        except export.ExportFailure as e:
             export.warn('export failed: %s: %s' % (name.encode('utf-8').strip(), e.message.encode('utf-8').strip()))
 
         for template in templates:
@@ -36,7 +36,7 @@ def main():
 
         if page != []:
             #name=page[0][1]['Name']
-            print name
+            print(name)
             fn=filename(name, 'json')
             data = json.dumps(page, sort_keys=True, indent=4, separators=(',', ': '))
             output('output/'+fn, data)
diff --git a/json_to_wiki.py b/json_to_wiki.py
index e5e91f9..27c2b24 100644
--- a/json_to_wiki.py
+++ b/json_to_wiki.py
@@ -10,13 +10,13 @@ def main():
     everything = json.load(sys.stdin)
 
     def _export():
-        for (name, valuess) in everything.iteritems():
-            print name
+        for (name, valuess) in everything.items():
+            print(name)
             templates = []
 
             for (tname, values) in valuess:
                 template = export.Template(
-                    tname.decode('utf8'), values.items())
+                    tname.decode('utf8'), list(values.items()))
                 templates.append(template)
 
             yield (name, templates)
diff --git a/license_summary.py b/license_summary.py
index 177e756..47311df 100644
--- a/license_summary.py
+++ b/license_summary.py
@@ -21,5 +21,5 @@ if __name__ == '__main__':
     licenses = list(histogram(cpf['_license']))
 
     for (k, v) in sorted(licenses, key=lambda x: x[1], reverse=True):
-        print '%-40s %6d' % (k.encode('utf8'), v)
+        print('%-40s %6d' % (k.encode('utf8'), v))
 
diff --git a/load_changelog.py b/load_changelog.py
index eb65772..48a24c2 100644
--- a/load_changelog.py
+++ b/load_changelog.py
@@ -29,14 +29,14 @@ def main():
     versions = []
     for path in subprocess.check_output("find metadata.ftp-master.debian.org -name stable_changelog".split()).strip().split():
         pkgname = get_pkgname(path)
-        print pkgname, path
+        print(pkgname, path)
         data = import_one(pkgname, file(path))
 
         if data is not None:
             versions.append(data)
             
     versions = pd.concat(versions)
-    print versions
+    print(versions)
     store = pd.HDFStore('cl.h5')
     store['cl_versions'] = versions
     store.close()
diff --git a/load_copyright.py b/load_copyright.py
index 838d907..693bb63 100644
--- a/load_copyright.py
+++ b/load_copyright.py
@@ -19,10 +19,10 @@ def read_copyright(fh):
     paras = debian.deb822.Deb822.iter_paragraphs(fh)
 
     try:
-        header = paras.next()
+        header = next(paras)
 
         header = dict(header)
-        paras = [(p.keys()[0], dict(p)) for p in paras]
+        paras = [(list(p.keys())[0], dict(p)) for p in paras]
     except (KeyError, TypeError, StopIteration):
         raise BadFormat('not in DEP-5 format?')
         return
@@ -70,10 +70,10 @@ def import_one(pkgname, fh):
     try:
         (header, files, licences) = read_copyright(fh)
     except BadFormat:
-        print 'info: not readable'
+        print('info: not readable')
         return None
-    except ValueError, e:
-        print 'err:', e
+    except ValueError as e:
+        print('err:', e)
         #print 'err:', repr(e)
         return None
 
@@ -86,7 +86,7 @@ def import_one(pkgname, fh):
         # Make spaces breakable (!).
         # Conceivably other characters need replacing.
         header['Upstream-Name'] = \
-            header['Upstream-Name'].replace(u'\xa0', ' ')
+            header['Upstream-Name'].replace('\xa0', ' ')
             #copy_summary['Upstream-Name'].replace('\xc2\xa0', ' ')
         if '@' in header['Upstream-Name']:
             header['Upstream-Name'] = pkgname
@@ -122,7 +122,7 @@ def main():
 
     for path in subprocess.check_output("find metadata.ftp-master.debian.org -name stable_copyright".split()).strip().split():
         pkgname = get_pkgname(path)
-        print pkgname, path
+        print(pkgname, path)
         data = import_one(pkgname, file(path))
 
         if data is not None:
@@ -131,7 +131,7 @@ def main():
             files.append(file_)
             licenses.append(license)
 
-        print
+        print()
 
     summaries = pd.concat(summaries)
     files = pd.concat(files)
diff --git a/load_packages.py b/load_packages.py
index 0209b59..8efba64 100644
--- a/load_packages.py
+++ b/load_packages.py
@@ -24,7 +24,7 @@ if __name__ == '__main__':
     df = pd.DataFrame([pkg(p) for p in packages])
     store = pd.HDFStore('pkg.h5')
 
-    print df
+    print(df)
 
     store = pd.HDFStore('pkg.h5')
     store['packages'] = df
diff --git a/load_sources.py b/load_sources.py
index f420796..b7c4b7f 100644
--- a/load_sources.py
+++ b/load_sources.py
@@ -28,7 +28,7 @@ if __name__ == '__main__':
     df = pd.DataFrame([pkg(p) for p in packages])
     store = pd.HDFStore('pkg.h5')
 
-    print df
+    print(df)
 
     store = pd.HDFStore('pkg.h5')
     store['sources'] = df
diff --git a/pkg_summary.py b/pkg_summary.py
index e262a41..0086dc1 100644
--- a/pkg_summary.py
+++ b/pkg_summary.py
@@ -5,5 +5,5 @@ import pandas as pd
 
 if __name__ == '__main__':
     store = pd.HDFStore('pkg.h5')
-    print store.handle
-    print store['packages']
+    print(store.handle)
+    print(store['packages'])
-- 
2.33.1

