StringTypes has gone
[plcapi.git] / PLC / GPG.py
index 1dcc0cf..4a99884 100644 (file)
@@ -9,10 +9,9 @@
 #
 
 import os
-import xmlrpclib
+import xmlrpc.client
 import shutil
-from types import StringTypes
-from StringIO import StringIO
+from io import StringIO
 from subprocess import Popen, PIPE, call
 from tempfile import NamedTemporaryFile, mkdtemp
 from lxml import etree
@@ -26,10 +25,10 @@ def canonicalize(args, methodname = None, methodresponse = False):
     True).
     """
 
-    xml = xmlrpclib.dumps(args, methodname, methodresponse, encoding = 'utf-8', allow_none = 1)
+    xml = xmlrpc.client.dumps(args, methodname, methodresponse, encoding = 'utf-8', allow_none = 1)
     dom = etree.fromstring(xml)
     canonical=etree.tostring(dom)
-    # pre-f20 version was using Canonicalize from PyXML 
+    # pre-f20 version was using Canonicalize from PyXML
     # from xml.dom.ext import Canonicalize
     # Canonicalize(), though it claims to, does not encode unicode
     # nodes to UTF-8 properly and throws an exception unless you write
@@ -59,7 +58,7 @@ def gpg_export(keyring, armor = True):
     shutil.rmtree(homedir)
 
     if rc:
-        raise PLCAuthenticationFailure, "GPG export failed with return code %d: %s" % (rc, err)
+        raise PLCAuthenticationFailure("GPG export failed with return code %d: %s" % (rc, err))
 
     return export
 
@@ -76,7 +75,7 @@ def gpg_sign(args, secret_keyring, keyring, methodname = None, methodresponse =
     """
 
     # Accept either an opaque string blob or a Python tuple
-    if isinstance(args, StringTypes):
+    if isinstance(args, str):
         message = args
     elif isinstance(args, tuple):
         message = canonicalize(args, methodname, methodresponse)
@@ -107,7 +106,7 @@ def gpg_sign(args, secret_keyring, keyring, methodname = None, methodresponse =
     shutil.rmtree(homedir)
 
     if rc:
-        raise PLCAuthenticationFailure, "GPG signing failed with return code %d: %s" % (rc, err)
+        raise PLCAuthenticationFailure("GPG signing failed with return code %d: %s" % (rc, err))
 
     return signature
 
@@ -123,7 +122,7 @@ def gpg_verify(args, key, signature = None, methodname = None, methodresponse =
     """
 
     # Accept either an opaque string blob or a Python tuple
-    if isinstance(args, StringTypes):
+    if isinstance(args, str):
         message = args
     else:
         message = canonicalize(args, methodname, methodresponse)
@@ -173,6 +172,6 @@ def gpg_verify(args, key, signature = None, methodname = None, methodresponse =
         keyfile.close()
 
     if rc:
-        raise PLCAuthenticationFailure, "GPG verification failed with return code %d: %s" % (rc, err)
+        raise PLCAuthenticationFailure("GPG verification failed with return code %d: %s" % (rc, err))
 
     return message