src/modules/server/repository.py
changeset 3234 3a90dc0b66c9
parent 3171 525f5bdb3f62
child 3245 d04bb3ca0128
--- a/src/modules/server/repository.py	Tue Jun 30 11:44:33 2015 -0700
+++ b/src/modules/server/repository.py	Wed Jul 01 16:20:01 2015 -0700
@@ -29,14 +29,15 @@
 import os
 import os.path
 import shutil
+import six
 import stat
 import sys
 import tempfile
-import urllib
 import zlib
-
 import M2Crypto as m2
 
+from six.moves.urllib.parse import unquote
+
 import pkg.actions as actions
 import pkg.catalog as catalog
 import pkg.client.api_errors as apx
@@ -62,6 +63,8 @@
 import pkg.pkgsubprocess as subprocess
 import pkg.version
 
+from pkg.pkggzip import PkgGzipFile
+
 CURRENT_REPO_VERSION = 4
 
 REPO_QUARANTINE_DIR = "pkg5-quarantine"
@@ -85,7 +88,6 @@
       VERIFY_DEPENDENCY,
 ])
 
-from pkg.pkggzip import PkgGzipFile
 
 class RepositoryError(Exception):
         """Base exception class for all Repository exceptions."""
@@ -95,12 +97,6 @@
                 if args:
                         self.data = args[0]
 
-        def __unicode__(self):
-                # To workaround python issues 6108 and 2517, this provides a
-                # a standard wrapper for this class' exceptions so that they
-                # have a chance of being stringified correctly.
-                return str(self)
-
         def __str__(self):
                 return str(self.data)
 
@@ -542,8 +538,8 @@
                 directory and the name of the manifest file, and returns an FMRI
                 constructed from the information in those components."""
 
-                v = pkg.version.Version(urllib.unquote(ver), None)
-                f = fmri.PkgFmri(urllib.unquote(os.path.basename(pkgpath)))
+                v = pkg.version.Version(unquote(ver), None)
+                f = fmri.PkgFmri(unquote(os.path.basename(pkgpath)))
                 f.version = v
                 return f
 
@@ -1689,7 +1685,7 @@
                                 for name in slist:
                                         # Stem must be decoded before use.
                                         try:
-                                                pname = urllib.unquote(name)
+                                                pname = unquote(name)
                                         except Exception:
                                                 # Assume error is result of
                                                 # unexpected file in directory;
@@ -1709,7 +1705,7 @@
 
                                                 # Version must be decoded before
                                                 # use.
-                                                pver = urllib.unquote(ver)
+                                                pver = unquote(ver)
                                                 try:
                                                         pfmri = fmri.PkgFmri(
                                                             "@".join((pname,
@@ -2305,7 +2301,7 @@
 
                         # Stem must be decoded before use.
                         try:
-                                pname = urllib.unquote(name)
+                                pname = unquote(name)
                         except Exception:
                                 # Assume error is result of an
                                 # unexpected file in the directory. We
@@ -2321,7 +2317,7 @@
                                 path = os.path.join(pdir, ver)
                                 # Version must be decoded before
                                 # use.
-                                pver = urllib.unquote(ver)
+                                pver = unquote(ver)
                                 try:
                                         pfmri = fmri.PkgFmri("@".join((pname,
                                             pver)),
@@ -3056,7 +3052,7 @@
                         finally:
                                 # This ensures that the original exception and
                                 # traceback are used.
-                                raise exc_value, None, exc_tb
+                                six.reraise(exc_value, None, exc_tb)
 
         def remove_publisher(self, pfxs, repo_path, synch=False):
                 """Removes a repository storage area and configuration
@@ -3491,7 +3487,7 @@
                 """
 
                 def merge(src, dest):
-                        for k, v in src.iteritems():
+                        for k, v in six.iteritems(src):
                                 if k in dest:
                                         dest[k].extend(v)
                                 else:
@@ -4346,7 +4342,7 @@
         raised.  Other errors can raise exceptions of class ApiException.
         """
 
-        if isinstance(repo_uri, basestring):
+        if isinstance(repo_uri, six.string_types):
                 repo_uri = publisher.RepositoryURI(misc.parse_uri(repo_uri))
 
         path = repo_uri.get_pathname()
@@ -4384,7 +4380,7 @@
 
                 # ...and this file (which can be empty).
                 try:
-                        with file(os.path.join(path, "cfg_cache"), "wb") as cf:
+                        with open(os.path.join(path, "cfg_cache"), "wb") as cf:
                                 cf.write("\n")
                 except EnvironmentError as e:
                         if e.errno == errno.EACCES: