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.iteritems():
- if isinstance(value, StringTypes):
+ if isinstance(value, StringType):
if (attributes and key in attributes) or not attributes:
print tab * counter + "%s: %s" % (key, value)
elif isinstance(value, list):
import sys
import os, os.path
import tempfile
-from types import StringTypes, ListType
from argparse import ArgumentParser
from sfa.util.sfalogging import logger
import time
-from types import StringTypes
from collections import defaultdict
from sfa.util.sfatime import utcparse, datetime_to_epoch
from __future__ import print_function
-import types
# for get_key_from_incoming_ip
import tempfile
import os
def Resolve(self, api, xrns, type=None, details=False):
dbsession = api.dbsession()
- if not isinstance(xrns, types.ListType):
+ if not isinstance(xrns, list):
# try to infer type if not set and we get a single input
if not type:
type = Xrn(xrns).get_type()
pub_key=getattr(record,'reg-keys',None)
if pub_key is not None:
# use only first key in record
- if pub_key and isinstance(pub_key, types.ListType): pub_key = pub_key[0]
+ if pub_key and isinstance(pub_key, list): pub_key = pub_key[0]
pkey = convert_public_key(pub_key)
email = getattr(record,'email',None)
elif isinstance (record, RegUser):
# create RegKey objects for incoming keys
if hasattr(record,'reg-keys'):
- keys=getattr(record,'reg-keys')
+ keys = getattr(record, 'reg-keys')
# some people send the key as a string instead of a list of strings
- if isinstance(keys,types.StringTypes): keys=[keys]
- logger.debug ("creating {} keys for user {}".format(len(keys), record.hrn))
+ # note for python2/3 : no need to consider unicode in a key
+ if isinstance(keys, str):
+ keys = [keys]
+ logger.debug("creating {} keys for user {}".format(len(keys), record.hrn))
record.reg_keys = [ RegKey (key) for key in keys ]
# update testbed-specific data if needed
if type == 'user':
if getattr(new_record, 'keys', None):
new_key = new_record.keys
- if isinstance (new_key, types.ListType):
+ if isinstance (new_key, list):
new_key = new_key[0]
# take new_key into account
-import types
-
from sfa.util.xrn import Xrn, urn_to_hrn
from sfa.util.method import Method
if 'details' in options: details=options['details']
else: details=False
type = None
- if not isinstance(xrns, types.ListType):
+ if not isinstance(xrns, list):
type = Xrn(xrns).get_type()
xrns=[xrns]
hrns = [urn_to_hrn(xrn)[0] for xrn in xrns]
-from types import StringTypes
from collections import defaultdict
from sfa.util.sfatime import utcparse, datetime_to_epoch
from sfa.util.xrn import get_authority
-from types import StringTypes
+
+from sfa.util.py23 import StringType
def get_peer(pldriver, hrn):
# Because of myplc native federation, we first need to determine if this
# check if we are already peered with this site_authority, if so
peers = pldriver.shell.GetPeers( {}, ['peer_id', 'peername', 'shortname', 'hrn_root'])
for peer_record in peers:
- names = [name.lower() for name in peer_record.values() if isinstance(name, StringTypes)]
+ names = [name.lower() for name in peer_record.values() if isinstance(name, StringType)]
if site_authority in names:
peer = peer_record['shortname']
import time
-from types import StringTypes
from collections import defaultdict
from sfa.util.sfatime import utcparse, datetime_to_epoch
-from types import StringTypes
-
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from types import StringTypes
from datetime import datetime
from sqlalchemy import or_, and_
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 type: self.type=type
if hrn: self.hrn=hrn
if gid:
- if isinstance(gid, StringTypes): self.gid=gid
+ if isinstance(gid, StringType): self.gid=gid
else: self.gid=gid.save_to_string(save_parents=True)
if authority: self.authority=authority
if peer_authority: self.peer_authority=peer_authority
@validates ('gid')
def validate_gid (self, key, gid):
if gid is None: return
- elif isinstance(gid, StringTypes): return gid
+ elif isinstance(gid, StringType): return gid
else: return gid.save_to_string(save_parents=True)
def validate_datetime (self, key, incoming):
# Copyright (C) 2006 The Trustees of Princeton University
#
-from types import NoneType, IntType, LongType, FloatType, StringTypes, DictType, TupleType, ListType
+from types import NoneType, IntType, LongType, FloatType, DictType, TupleType, ListType
from sfa.util.faults import SfaAPIError
+from sfa.util.py23 import StringType
+
class Parameter:
"""
Typed value wrapper. Use in accepts and returns to document method
return "boolean"
elif arg_type == FloatType:
return "double"
- elif arg_type in StringTypes:
+ elif issubclass(arg_type, StringType):
return "string"
elif arg_type == ListType or arg_type == TupleType:
return "array"
from __future__ import print_function
from sfa.util.sfatime import utcparse, datetime_to_string
-from types import StringTypes
from datetime import datetime
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:
def load_from_dict (self, d):
for (k,v) in d.iteritems():
# experimental
- if isinstance(v, StringTypes) and v.lower() in ['true']:
+ if isinstance(v, StringType) and v.lower() in ['true']:
v = True
- if isinstance(v, StringTypes) and v.lower() in ['false']:
+ if isinstance(v, StringType) and v.lower() in ['false']:
v = False
setattr(self, k, v)
# SfaAPI authentication
#
import sys
-from types import StringTypes
from sfa.util.faults import InsufficientRights, MissingCallerGID, \
MissingTrustedRoots, PermissionError, BadRequestHash, \
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
if xrns is None: xrns = []
error = (None, None)
def log_invalid_cred(cred):
- if not isinstance (cred, StringTypes):
+ if not isinstance (cred, StringType):
logger.info("cannot validate credential %s - expecting a string"%cred)
error = ('TypeMismatch',
"checkCredentials: expected a string, received {} -- {}"
import os, os.path
import subprocess
-from types import StringTypes
import datetime
from StringIO import StringIO
from tempfile import mkstemp
from xml.dom.minidom import Document, parseString
+from sfa.util.py23 import StringType
+
HAVELXML = False
try:
from lxml import etree
self.version = None
if cred:
- if isinstance(cred, StringTypes):
+ if isinstance(cred, StringType):
string = cred
self.type = Credential.SFA_CREDENTIAL_TYPE
self.version = '3'
str = file(filename).read()
# if this is a legacy credential, write error and bail out
- if isinstance (str, StringTypes) and str.strip().startswith("-----"):
+ if isinstance (str, StringType) and str.strip().startswith("-----"):
logger.error("Legacy credentials not supported any more - giving up with %s..."%str[:10])
return
else:
#
import time
-from types import IntType, LongType, StringTypes
+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
# Strings are a special case. Accept either unicode or str
# types if a string is expected.
- if expected_type in StringTypes and isinstance(value, StringTypes):
+ if issubclass(expected_type, StringType) and isinstance(value, StringType):
pass
# Integers and long integers are also special types. Accept
name)
# If a minimum or maximum (length, value) has been specified
- if expected_type in StringTypes:
+ if issubclass(expected_type, StringType):
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))
--- /dev/null
+try:
+ StringType = basestring
+except:
+ StringType = str
#----------------------------------------------------------------------
from __future__ import print_function
-from types import StringTypes
import time
import datetime
import dateutil.parser
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, StringTypes):
+ if isinstance(input, StringType):
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, StringTypes):
+ elif isinstance (input, StringType):
t = dateutil.parser.parse(input)
if t.utcoffset() is not None:
t = t.utcoffset() + t.replace(tzinfo=None)
#!/usr/bin/python
-from types import StringTypes
from lxml import etree
from StringIO import StringIO
from sfa.util.faults import InvalidXML
from sfa.rspecs.elements.element import Element
+from sfa.util.py23 import StringType
+
# helper functions to help build xpaths
class XpathFilter:
@staticmethod
d=d.copy()
# looks like iteritems won't stand side-effects
for k in d.keys():
- if not isinstance(d[k],StringTypes):
+ if not isinstance(d[k], StringType):
del d[k]
element.attrib.update(d)
import os, time
+from sfa.util.py23 import StringType
+
class Command:
commandline_options = []
help = "Add a new rule"
# Strings are a special case. Accept either unicode or str
# types if a string is expected.
- if expected_type in StringTypes and isinstance(value, StringTypes):
+ if issubclass(expected_type, StringType) and isinstance(value, StringType):
pass
# Integers and long integers are also special types. Accept
name)
# If a minimum or maximum (length, value) has been specified
- if expected_type in StringTypes:
+ if issubclass(expected_type, StringType):
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))
#!/usr/bin/env python
# -*- coding:utf-8 -*-
-import types
-
from sfa.storage.model import *
from sfa.storage.alchemy import *
from sfa.trust.gid import create_uuid
pub_key=getattr(record,'reg_keys',None)
if len(pub_key) > 0:
# use only first key in record
- if pub_key and isinstance(pub_key, types.ListType): pub_key = pub_key[0]
+ if pub_key and isinstance(pub_key, list): pub_key = pub_key[0]
pub_key = pub_key.key
pkey = convert_public_key(pub_key)
urn = Xrn (xrn=record.hrn, type='user').get_urn()
from sfa.storage.parameter import Parameter, Mixed
+from sfa.util.py23 import StringType
+
plc_ns="http://www.planet-lab.org/sfa"
class SoapError(Exception):
return "xsd:boolean"
elif arg_type == FloatType:
return "xsd:double"
- elif arg_type in StringTypes:
+ elif issubclass(arg_type, StringType):
return "xsd:string"
else:
pdb.set_trace()