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:]
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):
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
import getpass
-from sfa.util.py23 import xmlrpc_client
+import xmlrpc.client
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
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
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)
##
# 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
# 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)
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
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)
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
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': [
from urllib.parse import urlparse
from sfa.util.sfalogging import logger
-from sfa.util.py23 import xmlrpc_client
+import xmlrpc.client
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):
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
{}, ['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']
from sfa.rspecs.rspec import RSpec
from sfa.rspecs.version_manager import VersionManager
-from sfa.util.py23 import StringIO
+from io import StringIO
xslt = '''<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>
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:
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]
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):
"""
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()
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
# 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
####################
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:
# 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:
"""
# 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
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):
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
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)
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)
from types import NoneType, IntType, LongType, FloatType, DictType, TupleType, ListType
from sfa.util.faults import SfaAPIError
-from sfa.util.py23 import StringType
-
class Parameter:
"""
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"
from sfa.trust.gid import GID
from sfa.util.sfalogging import logger
-from sfa.util.py23 import StringType
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)
from xml.dom.minidom import Document, parseString
-from sfa.util.py23 import StringIO
+from io import StringIO
HAVELXML = False
try:
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
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))
# 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
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
##
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)
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()
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
self.version = None
if cred:
- if isinstance(cred, StringType):
+ if isinstance(cred, str):
string = cred
self.type = Credential.SFA_CREDENTIAL_TYPE
self.version = '3'
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 {}..."
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()
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
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.
dict = {}
if data:
if data.lower().startswith('uri:http://<params>'):
- dict = xmlrpc_client.loads(data[11:])[0][0]
+ dict = xmlrpc.client.loads(data[11:])[0][0]
else:
spl = data.split(', ')
for val in spl:
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)
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 = {}
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:
#import tempfile
from io import StringIO
from sfa.util.xml import XML
-from sfa.util.py23 import ConfigParser
+import configparser
default_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)
if filename:
try:
self.config.read(filename)
- except ConfigParser.MissingSectionHeaderError:
+ except configparser.MissingSectionHeaderError:
if filename.endswith('.xml'):
self.load_xml(filename)
else:
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):
@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):
#
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):
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):
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
# 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
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(
+++ /dev/null
-# 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
import re
from sfa.util.sfalogging import logger
-from sfa.util.py23 import StringType
SFATIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
# 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:
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)
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
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
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
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)
import os, time
-from sfa.util.py23 import StringType
class Command:
commandline_options = []
# 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
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))
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):
# 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)