[python-debian/master 03/36] Use Python 3-style print function.

Colin Watson cjwatson at canonical.com
Mon Oct 8 07:41:19 UTC 2012


---
 lib/debian/arfile.py         |    4 +++-
 lib/debian/deb822.py         |    8 +++++---
 lib/debian/debfile.py        |    4 +++-
 lib/debian/debian_support.py |   16 +++++++++-------
 lib/debian/debtags.py        |    4 +++-
 lib/debian/doc-debtags       |   34 ++++++++++++++++++----------------
 6 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/lib/debian/arfile.py b/lib/debian/arfile.py
index c9cb87a..4fbddae 100644
--- a/lib/debian/arfile.py
+++ b/lib/debian/arfile.py
@@ -15,6 +15,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from __future__ import print_function
+
 GLOBAL_HEADER = "!<arch>\n"
 GLOBAL_HEADER_LENGTH = len(GLOBAL_HEADER)
 
@@ -311,4 +313,4 @@ if __name__ == '__main__':
     # test
     # ar r test.ar <file1> <file2> .. <fileN>
     a = ArFile("test.ar")
-    print "\n".join(a.getnames())
+    print("\n".join(a.getnames()))
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index a1a49ce..b3be552 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -22,6 +22,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+from __future__ import print_function
+
 from deprecation import function_deprecated_by
 
 try:
@@ -824,9 +826,9 @@ class PkgRelation(object):
                     d['arch'] = parse_archs(parts['archs'])
                 return d
             else:
-                print >> sys.stderr, \
-                        'deb822.py: WARNING: cannot parse package' \
-                        ' relationship "%s", returning it raw' % raw
+                print('deb822.py: WARNING: cannot parse package' \
+                      ' relationship "%s", returning it raw' % raw,
+                      file=sys.stderr)
                 return { 'name': raw, 'version': None, 'arch': None }
 
         tl_deps = cls.__comma_sep_RE.split(raw.strip()) # top-level deps
diff --git a/lib/debian/debfile.py b/lib/debian/debfile.py
index a2a62f6..a43af5e 100644
--- a/lib/debian/debfile.py
+++ b/lib/debian/debfile.py
@@ -15,6 +15,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from __future__ import print_function
+
 import gzip
 import tarfile
 
@@ -278,5 +280,5 @@ if __name__ == '__main__':
     import sys
     deb = DebFile(filename=sys.argv[1])
     tgz = deb.control.tgz()
-    print tgz.getmember('control')
+    print(tgz.getmember('control'))
 
diff --git a/lib/debian/debian_support.py b/lib/debian/debian_support.py
index 9f065ff..b761094 100644
--- a/lib/debian/debian_support.py
+++ b/lib/debian/debian_support.py
@@ -18,6 +18,8 @@
 
 """This module implements facilities to deal with Debian-specific metadata."""
 
+from __future__ import print_function
+
 import os
 import re
 import hashlib
@@ -499,7 +501,7 @@ def update_file(remote, local, verbose=None):
         local_file = file(local)
     except IOError:
         if verbose:
-            print "update_file: no local copy, downloading full file"
+            print("update_file: no local copy, downloading full file")
         return download_file(remote, local)
 
     lines = local_file.readlines()
@@ -520,11 +522,11 @@ def update_file(remote, local, verbose=None):
         # FIXME: urllib does not raise a proper exception, so we parse
         # the error message.
         if verbose:
-            print "update_file: could not interpret patch index file"
+            print("update_file: could not interpret patch index file")
         return download_file(remote, local)
     except IOError:
         if verbose:
-            print "update_file: could not download patch index file"
+            print("update_file: could not download patch index file")
         return download_file(remote, local)
 
     for fields in index_fields:
@@ -533,7 +535,7 @@ def update_file(remote, local, verbose=None):
                 (remote_hash, remote_size) = re_whitespace.split(value)
                 if local_hash == remote_hash:
                     if verbose:
-                        print "update_file: local file is up-to-date"
+                        print("update_file: local file is up-to-date")
                     return lines
                 continue
 
@@ -561,15 +563,15 @@ def update_file(remote, local, verbose=None):
                 continue
             
             if verbose:
-                print "update_file: field %r ignored" % field
+                print("update_file: field %r ignored" % field)
         
     if not patches_to_apply:
         if verbose:
-            print "update_file: could not find historic entry", local_hash
+            print("update_file: could not find historic entry", local_hash)
         return download_file(remote, local)
 
     for patch_name in patches_to_apply:
-        print "update_file: downloading patch %r" % patch_name
+        print("update_file: downloading patch %r" % patch_name)
         patch_contents = download_gunzip_lines(remote + '.diff/' + patch_name
                                           + '.gz')
         if read_lines_sha1(patch_contents ) != patch_hashes[patch_name]:
diff --git a/lib/debian/debtags.py b/lib/debian/debtags.py
index 526394d..2e9379e 100644
--- a/lib/debian/debtags.py
+++ b/lib/debian/debtags.py
@@ -15,6 +15,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from __future__ import print_function
+
 import re, cPickle
 
 from deprecation import function_deprecated_by
@@ -96,7 +98,7 @@ def output(db):
 	for pkg, tags in db.items():
 		# Using % here seems awkward to me, but if I use calls to
 		# sys.stdout.write it becomes a bit slower
-		print "%s:" % (pkg), ", ".join(tags)
+		print("%s:" % (pkg), ", ".join(tags))
 
 
 def relevance_index_function(full, sub):
diff --git a/lib/debian/doc-debtags b/lib/debian/doc-debtags
index fecc77f..37a1178 100755
--- a/lib/debian/doc-debtags
+++ b/lib/debian/doc-debtags
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import print_function
+
 import debtags
 import sys
 import inspect
@@ -15,10 +17,10 @@ def document (callable):
 	if callable.__doc__ != None:
 		print_indented(2, callable.__name__)
 		print_indented(4, inspect.getdoc(callable))
-		print
+		print()
 
 
-print """debtags.py README
+print("""debtags.py README
 =================
 
 The Debtags python module provides support for accessing and manipulating
@@ -41,24 +43,24 @@ Classes
 =======
 
 There is only one class: debtags.DB:
-"""
+""")
 
 document (debtags.DB)
 
-print """
+print("""
 The methods of debtags.DB are:
-"""
+""")
 
 for m in dir(debtags.DB):
 	if m[0:2] != '__' and callable(getattr(debtags.DB, m)):
 		document(getattr(debtags.DB, m))
 
-print """Iteration
+print("""Iteration
 =========
 
 debtags.DB provides various iteration methods to iterate the collection either
 in a package-centered or in a tag-centered way:
-"""
+""")
 
 document(debtags.DB.iter_packages)
 document(debtags.DB.iter_packages_tags)
@@ -66,7 +68,7 @@ document(debtags.DB.iter_tags)
 document(debtags.DB.iter_tags_packages)
 
 
-print """Sample usage
+print("""Sample usage
 ============
 
 This example reads the system debtags database and performs a simple tag
@@ -76,10 +78,10 @@ search::
     
     db = debtags.DB()
     db.read(open("/var/lib/debtags/package-tags", "r"))
-    print db.package_count(), "packages in the database"
-    print "Image editors:"
+    print(db.package_count(), "packages in the database")
+    print("Image editors:")
     for pkg in db.packages_of_tags(set(("use::editing", "works-with::image:raster"))):
-    	print " *", pkg
+    	print(" *", pkg)
 
 This example computes the set of tags that belong to all the packages in a
 list, then shows all the other packages that have those tags:
@@ -89,10 +91,10 @@ list, then shows all the other packages that have those tags:
     db = debtags.DB()
     db.read(open("/var/lib/debtags/package-tags", "r"))
     tags = db.tags_of_packages(("gimp", "krita"))
-    print "Common tags:"
+    print("Common tags:")
     for tag in tags:
-	print " *", tag
-    print "Packages similar to gimp and krita:"
+	print(" *", tag)
+    print("Packages similar to gimp and krita:")
     for pkg in db.packages_of_tags(tags):
-	print " *", pkg
-"""
+	print(" *", pkg)
+""")
-- 
1.7.2.5





More information about the pkg-python-debian-commits mailing list