[Piuparts-commits] [piuparts] 04/05: make urllib statements py3 compatible

Holger Levsen holger at moszumanska.debian.org
Mon Apr 27 15:12:49 UTC 2015


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit ebfc6c159a0ed3b5264e3d235c636c76cf6e5d7e
Author: Börni <boerni at gmail.com>
Date:   Sun Apr 19 17:22:18 2015 +0200

    make urllib statements py3 compatible
---
 piuparts.py             | 12 ++++++++----
 piupartslib/__init__.py | 13 ++++++++++---
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/piuparts.py b/piuparts.py
index 6b6720b..c0f5297 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -50,11 +50,15 @@ import stat
 import re
 import pickle
 import subprocess
-import urllib
 import uuid
 from signal import alarm, signal, SIGALRM, SIGTERM, SIGKILL
 
 try:
+    import urllib.parse as urllib_parse  # py3
+except ImportError:
+    from urllib import quote as urllib_parse  # py2
+
+try:
     from debian import deb822
 except ImportError:
     from debian_bundle import deb822
@@ -1689,7 +1693,7 @@ class VirtServ(Chroot):
                 if not isinstance(a, type(())):
                     return a
                 (a,) = a
-                return urllib.quote(a)
+                return urllib_parse(a)
             cmd = ' '.join(map(maybe_quote, cmd))
         logging.debug('adt-virt >> %s', cmd)
         print(cmd, file=self._vs.stdin)
@@ -1773,7 +1777,7 @@ class VirtServ(Chroot):
             exec 2>&1
             exec "$@"
                 ''', '<command>']
-        ca = ','.join(map(urllib.quote, prefix + cmdl))
+        ca = ','.join(map(urllib_parse, prefix + cmdl))
         stdout = '%s/cmd-stdout' % self._scratch
         stderr = '%s/cmd-stderr-base' % self._scratch
         cmd = ['execute', ca,
@@ -1875,7 +1879,7 @@ class VirtServ(Chroot):
                         break
                     if len(splut) >= 8:
                         self._fail('aaargh wrong output from find: %s' %
-                                   urllib.quote(line), repr(splut))
+                                   urllib_parse(line), repr(splut))
                     l = f.readline()
                     if not l:
                         if not line:
diff --git a/piupartslib/__init__.py b/piupartslib/__init__.py
index 6863ea3..d48644d 100644
--- a/piupartslib/__init__.py
+++ b/piupartslib/__init__.py
@@ -20,8 +20,15 @@
 
 import bz2
 import zlib
-import urllib2
 
+try:
+    # py3
+    from urllib.error import HTTPError
+    from urllib.request import urlopen
+except ImportError:
+    # py2
+    from urllib2 import HTTPError
+    from urllib2 import urlopen
 
 from . import conf
 from . import dependencyparser
@@ -82,8 +89,8 @@ def open_packages_url(url):
     socket = None
     for ext in ['.bz2', '.gz']:
         try:
-            socket = urllib2.urlopen(url + ext)
-        except urllib2.HTTPError as httperror:
+            socket = urlopen(url + ext)
+        except HTTPError as httperror:
             pass
         else:
             break

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list