From 04acd3228e5911d36d0cd58dc35b9319fc558e17 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 29 Mar 2019 16:43:00 +0100 Subject: [PATCH] remove py23 compat layer --- clientbin/getNodes.py | 5 +---- config/sfa-config-tty | 3 --- sfa/client/manifolduploader.py | 6 +++--- sfa/client/sfaserverproxy.py | 26 +++++++++++++------------- sfa/client/sfi.py | 2 +- sfa/dummy/dummy_testbed_api_client.py | 4 ++-- sfa/dummy/dummyshell.py | 4 ++-- sfa/planetlab/peers.py | 5 +---- sfa/rspecs/pg_rspec_converter.py | 2 +- sfa/rspecs/version_manager.py | 3 +-- sfa/rspecs/versions/pgv2.py | 3 +-- sfa/server/threadedserver.py | 4 ++-- sfa/server/xmlrpcapi.py | 10 +++++----- sfa/storage/model.py | 5 ++--- sfa/storage/parameter.py | 4 +--- sfa/storage/record.py | 5 ++--- sfa/trust/abac_credential.py | 2 +- sfa/trust/auth.py | 3 +-- sfa/trust/certificate.py | 9 +++------ sfa/trust/credential.py | 10 +++++----- sfa/trust/gid.py | 4 ++-- sfa/trust/sfaticket.py | 6 +++--- sfa/trust/speaksfor_util.py | 2 +- sfa/util/config.py | 12 ++++++------ sfa/util/faults.py | 10 +++++----- sfa/util/method.py | 5 ++--- sfa/util/py23.py | 10 ---------- sfa/util/sfatime.py | 5 ++--- sfa/util/xml.py | 9 ++++----- sfatables/commands/moo.py | 5 ++--- tests/testCert.py | 4 ++-- 31 files changed, 77 insertions(+), 110 deletions(-) delete mode 100644 sfa/util/py23.py diff --git a/clientbin/getNodes.py b/clientbin/getNodes.py index aa0a4b15..69abf484 100644 --- a/clientbin/getNodes.py +++ b/clientbin/getNodes.py @@ -5,9 +5,6 @@ import os from optparse import OptionParser from pprint import pprint -from sfa.util.py23 import StringType - - def create_parser(): command = sys.argv[0] argv = sys.argv[1:] @@ -37,7 +34,7 @@ def print_dict(rdict, options, counter=1): if not isinstance(rdict, dict): raise "%s not a dict" % rdict for (key, value) in rdict.items(): - if isinstance(value, StringType): + if isinstance(value, str): if (attributes and key in attributes) or not attributes: print(tab * counter + "%s: %s" % (key, value)) elif isinstance(value, list): diff --git a/config/sfa-config-tty b/config/sfa-config-tty index c97b963b..f7c234b5 100755 --- a/config/sfa-config-tty +++ b/config/sfa-config-tty @@ -3,11 +3,8 @@ import os import sys import re -#import time import traceback -#import types import readline -#from io import StringIO from optparse import OptionParser from sfa.util.version import version_tag diff --git a/sfa/client/manifolduploader.py b/sfa/client/manifolduploader.py index c469b357..8d1d74eb 100755 --- a/sfa/client/manifolduploader.py +++ b/sfa/client/manifolduploader.py @@ -34,7 +34,7 @@ except: import getpass -from sfa.util.py23 import xmlrpc_client +import xmlrpc.client class ManifoldUploader: @@ -91,11 +91,11 @@ class ManifoldUploader: # if not self._proxy: # url=self.url() # self.logger.info("Connecting manifold url %s"%url) - # self._proxy = xmlrpc_client.ServerProxy(url, allow_none = True) + # self._proxy = xmlrpc.client.ServerProxy(url, allow_none = True) # return self._proxy url = self.url() self.logger.debug("Connecting manifold url %s" % url) - proxy = xmlrpc_client.ServerProxy(url, allow_none=True, + proxy = xmlrpc.client.ServerProxy(url, allow_none=True, **turn_off_server_verify) return proxy diff --git a/sfa/client/sfaserverproxy.py b/sfa/client/sfaserverproxy.py index 73aefc8c..457a1d25 100644 --- a/sfa/client/sfaserverproxy.py +++ b/sfa/client/sfaserverproxy.py @@ -7,8 +7,8 @@ try: except: turn_off_server_verify = {} -from sfa.util.py23 import xmlrpc_client -from sfa.util.py23 import http_client +import xmlrpc.client +import http.client try: from sfa.util.sfalogging import logger @@ -27,12 +27,12 @@ class ServerException(Exception): pass -class ExceptionUnmarshaller(xmlrpc_client.Unmarshaller): +class ExceptionUnmarshaller(xmlrpc.client.Unmarshaller): def close(self): try: - return xmlrpc_client.Unmarshaller.close(self) - except xmlrpc_client.Fault as e: + return xmlrpc.client.Unmarshaller.close(self) + except xmlrpc.client.Fault as e: raise ServerException(e.faultString) ## @@ -43,10 +43,10 @@ class ExceptionUnmarshaller(xmlrpc_client.Unmarshaller): # targetting only python-2.7 we can get rid of some older code -class XMLRPCTransport(xmlrpc_client.Transport): +class XMLRPCTransport(xmlrpc.client.Transport): def __init__(self, key_file=None, cert_file=None, timeout=None): - xmlrpc_client.Transport.__init__(self) + xmlrpc.client.Transport.__init__(self) self.timeout = timeout self.key_file = key_file self.cert_file = cert_file @@ -55,7 +55,7 @@ class XMLRPCTransport(xmlrpc_client.Transport): # create a HTTPS connection object from a host descriptor # host may be a string, or a (host, x509-dict) tuple host, extra_headers, x509 = self.get_host_info(host) - conn = http_client.HTTPSConnection(host, None, key_file=self.key_file, + conn = http.client.HTTPSConnection(host, None, key_file=self.key_file, cert_file=self.cert_file, **turn_off_server_verify) @@ -80,23 +80,23 @@ class XMLRPCTransport(xmlrpc_client.Transport): def getparser(self): unmarshaller = ExceptionUnmarshaller() - parser = xmlrpc_client.ExpatParser(unmarshaller) + parser = xmlrpc.client.ExpatParser(unmarshaller) return parser, unmarshaller -class XMLRPCServerProxy(xmlrpc_client.ServerProxy): +class XMLRPCServerProxy(xmlrpc.client.ServerProxy): def __init__(self, url, transport, allow_none=True, verbose=False): # remember url for GetVersion # xxx not sure this is still needed as SfaServerProxy has this too self.url = url - xmlrpc_client.ServerProxy.__init__(self, url, transport, allow_none=allow_none, + xmlrpc.client.ServerProxy.__init__(self, url, transport, allow_none=allow_none, verbose=verbose, **turn_off_server_verify) def __getattr__(self, attr): logger.debug("xml-rpc %s method:%s" % (self.url, attr)) - return xmlrpc_client.ServerProxy.__getattr__(self, attr) + return xmlrpc.client.ServerProxy.__getattr__(self, attr) # the object on which we can send methods that get sent over xmlrpc @@ -109,7 +109,7 @@ class SfaServerProxy: self.certfile = certfile self.verbose = verbose self.timeout = timeout - # an instance of xmlrpc_client.ServerProxy + # an instance of xmlrpc.client.ServerProxy transport = XMLRPCTransport(keyfile, certfile, timeout) self.serverproxy = XMLRPCServerProxy( url, transport, allow_none=True, verbose=verbose) diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index ac2a5532..bafabe87 100644 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -35,7 +35,7 @@ from sfa.util.config import Config from sfa.util.version import version_core from sfa.util.cache import Cache from sfa.util.printable import printable -from sfa.util.py23 import StringIO +from io import StringIO from sfa.storage.record import Record diff --git a/sfa/dummy/dummy_testbed_api_client.py b/sfa/dummy/dummy_testbed_api_client.py index 9df51442..8d412ef0 100644 --- a/sfa/dummy/dummy_testbed_api_client.py +++ b/sfa/dummy/dummy_testbed_api_client.py @@ -2,10 +2,10 @@ from datetime import datetime import time -from sfa.util.py23 import xmlrpc_client +import xmlrpc.client dummy_url = "http://localhost:8080" -dummy_api = xmlrpc_client.ServerProxy(dummy_url) +dummy_api = xmlrpc.client.ServerProxy(dummy_url) # Add a user: my_user_id = dummy_api.AddUser({'email': 'john.doe@test.net', 'user_name': 'john.doe', 'keys': [ diff --git a/sfa/dummy/dummyshell.py b/sfa/dummy/dummyshell.py index e330d28a..d590ad16 100644 --- a/sfa/dummy/dummyshell.py +++ b/sfa/dummy/dummyshell.py @@ -3,7 +3,7 @@ import socket from urllib.parse import urlparse from sfa.util.sfalogging import logger -from sfa.util.py23 import xmlrpc_client +import xmlrpc.client class DummyShell: @@ -21,7 +21,7 @@ class DummyShell: def __init__(self, config): url = config.SFA_DUMMY_URL - self.proxy = xmlrpc_client.ServerProxy( + self.proxy = xmlrpc.client.ServerProxy( url, verbose=False, allow_none=True) def __getattr__(self, name): diff --git a/sfa/planetlab/peers.py b/sfa/planetlab/peers.py index 083ea9d6..cb6b14cc 100644 --- a/sfa/planetlab/peers.py +++ b/sfa/planetlab/peers.py @@ -1,8 +1,5 @@ from sfa.util.xrn import get_authority -from sfa.util.py23 import StringType - - def get_peer(pldriver, hrn): # Because of myplc native federation, we first need to determine if this # slice belongs to out local plc or a myplc peer. We will assume it @@ -19,7 +16,7 @@ def get_peer(pldriver, hrn): {}, ['peer_id', 'peername', 'shortname', 'hrn_root']) for peer_record in peers: names = [name.lower() for name in list(peer_record.values()) - if isinstance(name, StringType)] + if isinstance(name, str)] if site_authority in names: peer = peer_record['shortname'] diff --git a/sfa/rspecs/pg_rspec_converter.py b/sfa/rspecs/pg_rspec_converter.py index c0eaad75..6fb55def 100755 --- a/sfa/rspecs/pg_rspec_converter.py +++ b/sfa/rspecs/pg_rspec_converter.py @@ -6,7 +6,7 @@ from sfa.util.xrn import Xrn, urn_to_hrn from sfa.rspecs.rspec import RSpec from sfa.rspecs.version_manager import VersionManager -from sfa.util.py23 import StringIO +from io import StringIO xslt = ''' diff --git a/sfa/rspecs/version_manager.py b/sfa/rspecs/version_manager.py index b4daf424..ac832622 100644 --- a/sfa/rspecs/version_manager.py +++ b/sfa/rspecs/version_manager.py @@ -4,7 +4,6 @@ import os from sfa.util.faults import InvalidRSpec, UnsupportedRSpecVersion from sfa.rspecs.version import RSpecVersion from sfa.util.sfalogging import logger -from sfa.util.py23 import StringType class VersionManager: @@ -55,7 +54,7 @@ class VersionManager: if isinstance(version, dict): retval = self._get_version(version.get('type'), version.get( 'version'), version.get('content_type')) - elif isinstance(version, StringType): + elif isinstance(version, str): version_parts = version.split(' ') num_parts = len(version_parts) type = version_parts[0] diff --git a/sfa/rspecs/versions/pgv2.py b/sfa/rspecs/versions/pgv2.py index 17a18e08..8d5c2473 100644 --- a/sfa/rspecs/versions/pgv2.py +++ b/sfa/rspecs/versions/pgv2.py @@ -8,7 +8,6 @@ from sfa.rspecs.elements.versions.pgv2Node import PGv2Node from sfa.rspecs.elements.versions.pgv2SliverType import PGv2SliverType from sfa.rspecs.elements.versions.pgv2Lease import PGv2Lease from sfa.util.sfalogging import logger -from sfa.util.py23 import StringType class PGv2(RSpecVersion): @@ -213,7 +212,7 @@ class PGv2(RSpecVersion): """ from sfa.rspecs.rspec import RSpec # just copy over all the child elements under the root element - if isinstance(in_rspec, StringType): + if isinstance(in_rspec, str): in_rspec = RSpec(in_rspec) nodes = in_rspec.version.get_nodes() diff --git a/sfa/server/threadedserver.py b/sfa/server/threadedserver.py index d5c47bf4..ae55c07e 100644 --- a/sfa/server/threadedserver.py +++ b/sfa/server/threadedserver.py @@ -21,7 +21,7 @@ from sfa.util.config import Config from sfa.util.cache import Cache from sfa.trust.certificate import Certificate from sfa.trust.trustedroots import TrustedRoots -from sfa.util.py23 import xmlrpc_client +import xmlrpc.client # don't hard code an api class anymore here from sfa.generic import Generic @@ -207,7 +207,7 @@ class SecureXMLRPCServer(http.server.HTTPServer, xmlrpc.server.SimpleXMLRPCDispa # can't use format_exc() as it is not available in jython yet # (even in trunk). type, value, tb = sys.exc_info() - raise xmlrpc_client.Fault(1, ''.join( + raise xmlrpc.client.Fault(1, ''.join( traceback.format_exception(type, value, tb))) # override this one from the python 2.7 code diff --git a/sfa/server/xmlrpcapi.py b/sfa/server/xmlrpcapi.py index 54fb745e..d89021df 100644 --- a/sfa/server/xmlrpcapi.py +++ b/sfa/server/xmlrpcapi.py @@ -17,7 +17,7 @@ except ImportError: #################### from sfa.util.faults import SfaInvalidAPIMethod, SfaAPIError, SfaFault from sfa.util.sfalogging import logger -from sfa.util.py23 import xmlrpc_client +import xmlrpc.client #################### # See "2.2 Characters" in the XML specification: @@ -91,7 +91,7 @@ def xmlrpclib_dump(self, value, write): # You can't hide from me! # Note: not quite sure if this will still cause # the expected behaviour under python3 -xmlrpc_client.Marshaller._Marshaller__dump = xmlrpclib_dump +xmlrpc.client.Marshaller._Marshaller__dump = xmlrpclib_dump class XmlrpcApi: @@ -145,9 +145,9 @@ class XmlrpcApi: """ # Parse request into method name and arguments try: - interface = xmlrpc_client + interface = xmlrpc.client self.protocol = 'xmlrpc' - (args, method) = xmlrpc_client.loads(data) + (args, method) = xmlrpc.client.loads(data) if method in method_map: method = method_map[method] methodresponse = True @@ -185,7 +185,7 @@ class XmlrpcApi: if self.protocol == 'xmlrpc': if not isinstance(result, SfaFault): result = (result,) - response = xmlrpc_client.dumps( + response = xmlrpc.client.dumps( result, methodresponse=True, encoding=self.encoding, allow_none=1) elif self.protocol == 'soap': if isinstance(result, Exception): diff --git a/sfa/storage/model.py b/sfa/storage/model.py index a2e3bd49..b46c7022 100644 --- a/sfa/storage/model.py +++ b/sfa/storage/model.py @@ -13,7 +13,6 @@ from sfa.storage.record import Record from sfa.util.sfalogging import logger from sfa.util.sfatime import utcparse, datetime_to_string from sfa.util.xml import XML -from sfa.util.py23 import StringType from sfa.trust.gid import GID @@ -105,7 +104,7 @@ class RegRecord(Base, AlchemyObj): if hrn: self.hrn = hrn if gid: - if isinstance(gid, StringType): + if isinstance(gid, str): self.gid = gid else: self.gid = gid.save_to_string(save_parents=True) @@ -143,7 +142,7 @@ class RegRecord(Base, AlchemyObj): def validate_gid(self, key, gid): if gid is None: return - elif isinstance(gid, StringType): + elif isinstance(gid, str): return gid else: return gid.save_to_string(save_parents=True) diff --git a/sfa/storage/parameter.py b/sfa/storage/parameter.py index 1545cac4..bd9d3b54 100644 --- a/sfa/storage/parameter.py +++ b/sfa/storage/parameter.py @@ -8,8 +8,6 @@ from types import NoneType, IntType, LongType, FloatType, DictType, TupleType, ListType from sfa.util.faults import SfaAPIError -from sfa.util.py23 import StringType - class Parameter: """ @@ -94,7 +92,7 @@ def xmlrpc_type(arg): return "boolean" elif arg_type == FloatType: return "double" - elif issubclass(arg_type, StringType): + elif issubclass(arg_type, str): return "string" elif arg_type == ListType or arg_type == TupleType: return "array" diff --git a/sfa/storage/record.py b/sfa/storage/record.py index ac391a17..b88b02a0 100644 --- a/sfa/storage/record.py +++ b/sfa/storage/record.py @@ -6,7 +6,6 @@ from sfa.util.xml import XML from sfa.trust.gid import GID from sfa.util.sfalogging import logger -from sfa.util.py23 import StringType class Record: @@ -58,9 +57,9 @@ class Record: def load_from_dict(self, d): for (k, v) in d.items(): # experimental - if isinstance(v, StringType) and v.lower() in ['true']: + if isinstance(v, str) and v.lower() in ['true']: v = True - if isinstance(v, StringType) and v.lower() in ['false']: + if isinstance(v, str) and v.lower() in ['false']: v = False setattr(self, k, v) diff --git a/sfa/trust/abac_credential.py b/sfa/trust/abac_credential.py index 3534c00d..51e86483 100644 --- a/sfa/trust/abac_credential.py +++ b/sfa/trust/abac_credential.py @@ -29,7 +29,7 @@ from sfa.util.sfatime import SFATIME_FORMAT from xml.dom.minidom import Document, parseString -from sfa.util.py23 import StringIO +from io import StringIO HAVELXML = False try: diff --git a/sfa/trust/auth.py b/sfa/trust/auth.py index b481bbd0..e250c423 100644 --- a/sfa/trust/auth.py +++ b/sfa/trust/auth.py @@ -8,7 +8,6 @@ from sfa.util.faults import InsufficientRights, MissingCallerGID, \ ConnectionKeyGIDMismatch, SfaPermissionDenied, CredentialNotVerifiable, \ Forbidden, BadArgs from sfa.util.sfalogging import logger -from sfa.util.py23 import StringType from sfa.util.config import Config from sfa.util.xrn import Xrn, get_authority @@ -70,7 +69,7 @@ class Auth: def log_invalid_cred(cred, exception): if isinstance(cred, dict) and 'geni_value' in cred: cred = cred['geni_value'] - if not isinstance(cred, StringType): + if not isinstance(cred, str): logger.info( "{}: cannot validate credential {}" .format(exception, cred)) diff --git a/sfa/trust/certificate.py b/sfa/trust/certificate.py index 81742262..d0d36d53 100644 --- a/sfa/trust/certificate.py +++ b/sfa/trust/certificate.py @@ -57,8 +57,6 @@ import OpenSSL # M2Crypto is imported on the fly to minimize crashes # import M2Crypto -from sfa.util.py23 import PY3 - from sfa.util.faults import (CertExpired, CertMissingParent, CertNotSignedByParent) from sfa.util.sfalogging import logger @@ -276,8 +274,7 @@ class Keypair: def get_m2_pubkey(self): import M2Crypto if not self.m2key: - self.m2key = M2Crypto.EVP.load_key_string( - self.as_pem().encode(encoding="utf-8")) + self.m2key = M2Crypto.EVP.load_key_string(self.as_pem()) return self.m2key ## @@ -475,7 +472,7 @@ class Certificate: return "" string = OpenSSL.crypto.dump_certificate( OpenSSL.crypto.FILETYPE_PEM, self.x509) - if PY3 and isinstance(string, bytes): + if isinstance(string, bytes): string = string.decode() if save_parents and self.parent: string = string + self.parent.save_to_string(save_parents) @@ -492,7 +489,7 @@ class Certificate: f = filep else: f = open(filename, 'w') - if PY3 and isinstance(string, bytes): + if isinstance(string, bytes): string = string.decode() f.write(string) f.close() diff --git a/sfa/trust/credential.py b/sfa/trust/credential.py index 307ed950..92c114e3 100644 --- a/sfa/trust/credential.py +++ b/sfa/trust/credential.py @@ -36,7 +36,7 @@ import datetime from tempfile import mkstemp from xml.dom.minidom import Document, parseString -from sfa.util.py23 import PY3, StringType, StringIO +from io import StringIO from xml.parsers.expat import ExpatError @@ -276,7 +276,7 @@ class Credential(object): self.version = None if cred: - if isinstance(cred, StringType): + if isinstance(cred, str): string = cred self.type = Credential.SFA_CREDENTIAL_TYPE self.version = '3' @@ -293,7 +293,7 @@ class Credential(object): str = infile.read() # if this is a legacy credential, write error and bail out - if isinstance(str, StringType) and str.strip().startswith("-----"): + if isinstance(str, str) and str.strip().startswith("-----"): logger.error( "Legacy credentials not supported any more " "- giving up with {}..." @@ -639,7 +639,7 @@ class Credential(object): f = filep else: f = open(filename, "w") - if PY3 and isinstance(self.xml, bytes): + if isinstance(self.xml, bytes): self.xml = self.xml.decode() f.write(self.xml) f.close() @@ -647,7 +647,7 @@ class Credential(object): def save_to_string(self, save_parents=True): if not self.xml: self.encode() - if PY3 and isinstance(self.xml, bytes): + if isinstance(self.xml, bytes): self.xml = self.xml.decode() return self.xml diff --git a/sfa/trust/gid.py b/sfa/trust/gid.py index 7387902d..7450b4d3 100644 --- a/sfa/trust/gid.py +++ b/sfa/trust/gid.py @@ -28,13 +28,13 @@ import uuid +import xmlrpc.client from sfa.trust.certificate import Certificate from sfa.util.faults import GidInvalidParentHrn, GidParentHrn from sfa.util.xrn import hrn_to_urn, urn_to_hrn, hrn_authfor_hrn from sfa.util.sfalogging import logger -from sfa.util.py23 import xmlrpc_client ## # Create a new uuid. Returns the UUID as a string. @@ -176,7 +176,7 @@ class GID(Certificate): dict = {} if data: if data.lower().startswith('uri:http://'): - dict = xmlrpc_client.loads(data[11:])[0][0] + dict = xmlrpc.client.loads(data[11:])[0][0] else: spl = data.split(', ') for val in spl: diff --git a/sfa/trust/sfaticket.py b/sfa/trust/sfaticket.py index 1401b645..0be88b8f 100644 --- a/sfa/trust/sfaticket.py +++ b/sfa/trust/sfaticket.py @@ -29,7 +29,7 @@ from sfa.trust.certificate import Certificate from sfa.trust.gid import GID -from sfa.util.py23 import xmlrpc_client +import xmlrpc.client # Ticket is tuple: # (gidCaller, gidObject, attributes, rspec, delegate) @@ -102,13 +102,13 @@ class SfaTicket(Certificate): if self.gidObject: dict["gidObject"] = self.gidObject.save_to_string( save_parents=True) - str = "URI:" + xmlrpc_client.dumps((dict,), allow_none=True) + str = "URI:" + xmlrpc.client.dumps((dict,), allow_none=True) self.set_data(str) def decode(self): data = self.get_data() if data: - dict = xmlrpc_client.loads(self.get_data()[4:])[0][0] + dict = xmlrpc.client.loads(self.get_data()[4:])[0][0] else: dict = {} diff --git a/sfa/trust/speaksfor_util.py b/sfa/trust/speaksfor_util.py index 7019e3c3..7afde6ec 100644 --- a/sfa/trust/speaksfor_util.py +++ b/sfa/trust/speaksfor_util.py @@ -40,7 +40,7 @@ from sfa.trust.abac_credential import ABACCredential, ABACElement from sfa.trust.credential_factory import CredentialFactory from sfa.trust.gid import GID from sfa.util.sfalogging import logger -from sfa.util.py23 import StringIO +from io import StringIO # Routine to validate that a speaks-for credential # says what it claims to say: diff --git a/sfa/util/config.py b/sfa/util/config.py index 67e81c42..04b2b2d6 100644 --- a/sfa/util/config.py +++ b/sfa/util/config.py @@ -8,7 +8,7 @@ import time #import tempfile from io import StringIO from sfa.util.xml import XML -from sfa.util.py23 import ConfigParser +import configparser default_config = \ """ @@ -28,7 +28,7 @@ class Config: def __init__(self, config_file='/etc/sfa/sfa_config'): self._files = [] self.config_path = os.path.dirname(config_file) - self.config = ConfigParser.ConfigParser() + self.config = configparser.ConfigParser() self.filename = config_file if not os.path.isfile(self.filename): self.create(self.filename) @@ -56,7 +56,7 @@ DO NOT EDIT. This file was automatically generated at if filename: try: self.config.read(filename) - except ConfigParser.MissingSectionHeaderError: + except configparser.MissingSectionHeaderError: if filename.endswith('.xml'): self.load_xml(filename) else: @@ -107,7 +107,7 @@ DO NOT EDIT. This file was automatically generated at section_name = section.lower() var_name = varname.replace(section_name, "")[1:] if strict and not self.config.has_option(section_name, var_name): - raise ConfigParser.NoOptionError(var_name, section_name) + raise configparser.NoOptionError(var_name, section_name) return (section_name, var_name) def set_attributes(self): @@ -190,10 +190,10 @@ DO NOT EDIT. This file was automatically generated at @staticmethod def is_ini(config_file): try: - c = ConfigParser.ConfigParser() + c = configparser.ConfigParser() c.read(config_file) return True - except ConfigParser.MissingSectionHeaderError: + except configparser.MissingSectionHeaderError: return False def dump(self, sections=None): diff --git a/sfa/util/faults.py b/sfa/util/faults.py index ea62bad2..07ec10d5 100644 --- a/sfa/util/faults.py +++ b/sfa/util/faults.py @@ -25,15 +25,15 @@ # from sfa.util.genicode import GENICODE -from sfa.util.py23 import xmlrpc_client +import xmlrpc.client -class SfaFault(xmlrpc_client.Fault): +class SfaFault(xmlrpc.client.Fault): def __init__(self, faultCode, faultString, extra=None): if extra: faultString += ": " + str(extra) - xmlrpc_client.Fault.__init__(self, faultCode, faultString) + xmlrpc.client.Fault.__init__(self, faultCode, faultString) class Forbidden(SfaFault): @@ -360,11 +360,11 @@ class SliverDoesNotExist(SfaFault): return repr(self.value) -class BadRequestHash(xmlrpc_client.Fault): +class BadRequestHash(xmlrpc.client.Fault): def __init__(self, hash=None, extra=None): faultString = "bad request hash: " + str(hash) - xmlrpc_client.Fault.__init__(self, GENICODE.ERROR, faultString) + xmlrpc.client.Fault.__init__(self, GENICODE.ERROR, faultString) class MissingTrustedRoots(SfaFault): diff --git a/sfa/util/method.py b/sfa/util/method.py index e99d55a8..b3d7d1a7 100644 --- a/sfa/util/method.py +++ b/sfa/util/method.py @@ -8,7 +8,6 @@ from types import IntType, LongType import textwrap from sfa.util.sfalogging import logger -from sfa.util.py23 import StringType from sfa.util.faults import SfaFault, SfaInvalidAPIMethod, SfaInvalidArgumentCount, SfaInvalidArgument from sfa.storage.parameter import Parameter, Mixed, python_type, xmlrpc_type @@ -239,7 +238,7 @@ class Method: # Strings are a special case. Accept either unicode or str # types if a string is expected. - if issubclass(expected_type, StringType) and isinstance(value, StringType): + if issubclass(expected_type, str) and isinstance(value, str): pass # Integers and long integers are also special types. Accept @@ -254,7 +253,7 @@ class Method: name) # If a minimum or maximum (length, value) has been specified - if issubclass(expected_type, StringType): + if issubclass(expected_type, str): if min is not None and \ len(value.encode(self.api.encoding)) < min: raise SfaInvalidArgument( diff --git a/sfa/util/py23.py b/sfa/util/py23.py deleted file mode 100644 index cb2e1e2a..00000000 --- a/sfa/util/py23.py +++ /dev/null @@ -1,10 +0,0 @@ -# our own simplistic replacement for six -import sys -PY3 = sys.version_info[0] == 3 - -StringType = str -from io import StringIO - -import xmlrpc.client as xmlrpc_client -import http.client as http_client -import configparser as ConfigParser diff --git a/sfa/util/sfatime.py b/sfa/util/sfatime.py index 6793ad57..aab06635 100644 --- a/sfa/util/sfatime.py +++ b/sfa/util/sfatime.py @@ -29,7 +29,6 @@ import calendar import re from sfa.util.sfalogging import logger -from sfa.util.py23 import StringType SFATIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" @@ -59,7 +58,7 @@ For safety this can also handle inputs that are either timestamps, or datetimes # prepare the input for the checks below by # casting strings ('1327098335') to ints - if isinstance(input, StringType): + if isinstance(input, str): try: input = int(input) except ValueError: @@ -75,7 +74,7 @@ For safety this can also handle inputs that are either timestamps, or datetimes if isinstance(input, datetime.datetime): #logger.info ("argument to utcparse already a datetime - doing nothing") return input - elif isinstance(input, StringType): + elif isinstance(input, str): t = dateutil.parser.parse(input) if t.utcoffset() is not None: t = t.utcoffset() + t.replace(tzinfo=None) diff --git a/sfa/util/xml.py b/sfa/util/xml.py index d9e23d56..9f43b96f 100755 --- a/sfa/util/xml.py +++ b/sfa/util/xml.py @@ -3,8 +3,7 @@ from lxml import etree from sfa.util.faults import InvalidXML from sfa.rspecs.elements.element import Element -from sfa.util.py23 import StringType -from sfa.util.py23 import StringIO +from io import StringIO # helper functions to help build xpaths @@ -174,7 +173,7 @@ class XML: self.namespaces = namespaces self.default_namespace = None self.schema = None - if isinstance(xml, StringType): + if isinstance(xml, str): self.parse_xml(xml) if isinstance(xml, XmlElement): self.root = xml @@ -238,7 +237,7 @@ class XML: if isinstance(val, dict): child_element = etree.SubElement(element, key) self.parse_dict(val, key, child_element) - elif isinstance(val, StringType): + elif isinstance(val, str): child_element = etree.SubElement( element, key).text = val @@ -252,7 +251,7 @@ class XML: d = d.copy() # looks like iteritems won't stand side-effects for k in list(d.keys()): - if not isinstance(d[k], StringType): + if not isinstance(d[k], str): del d[k] element.attrib.update(d) diff --git a/sfatables/commands/moo.py b/sfatables/commands/moo.py index 3860e3cd..8104b243 100644 --- a/sfatables/commands/moo.py +++ b/sfatables/commands/moo.py @@ -1,6 +1,5 @@ import os, time -from sfa.util.py23 import StringType class Command: commandline_options = [] @@ -154,7 +153,7 @@ class Command: # Strings are a special case. Accept either unicode or str # types if a string is expected. - if issubclass(expected_type, StringType) and isinstance(value, StringType): + if issubclass(expected_type, str) and isinstance(value, str): pass # Integers and long integers are also special types. Accept @@ -169,7 +168,7 @@ class Command: name) # If a minimum or maximum (length, value) has been specified - if issubclass(expected_type, StringType): + if issubclass(expected_type, str): if min is not None and \ len(value.encode(self.api.encoding)) < min: raise SfaInvalidArgument("%s must be at least %d bytes long" % (name, min)) diff --git a/tests/testCert.py b/tests/testCert.py index 1d00d274..39c64d3f 100755 --- a/tests/testCert.py +++ b/tests/testCert.py @@ -1,6 +1,6 @@ import unittest from sfa.trust.certificate import Certificate, Keypair -from sfa.util.py23 import xmlrpc_client +import xmlrpc.client class TestCert(unittest.TestCase): def setUp(self): @@ -42,7 +42,7 @@ class TestCert(unittest.TestCase): # try something a bit more complicated, like an xmlrpc encoding of # some parameters cert = Certificate(subject="test") - data = xmlrpc_client.dumps((1, "foo", ["a", "b"], {"c": "d", "e": "f"}, True)) + data = xmlrpc.client.dumps((1, "foo", ["a", "b"], {"c": "d", "e": "f"}, True)) cert.set_data(data) self.assertEqual(cert.get_data(), data) -- 2.45.2