def checkSimpleType(value): if checkString(value): return True elif isinstance(value, SIMPLE_TYPES): return True elif isinstance(value, (int, long)): if not (MIN_INT <= value <= MAX_INT): raise TransportError("long int (%s) exceeds XML-RPC limits" % value) return True else: raise TransportError("Unserializable type: %s" % typeName(value))
def getter(self, rule, name, identifiers): if not isinstance(identifiers, (tuple, list)): raise TypeError("Attribute %r value is a tuple or list, not a %s" % (name, typeName(identifiers))) if not identifiers: if self.optional: return set() else: return None items = set() library = getattr(rule.ruleset, self.library_name) for identifier in identifiers: item = library[identifier] items.add(item) return items
def __init__(self, default=None, optional=False, const=False, xml="attr"): if default is not None: if (self.type is not None) \ and not isinstance(default, self.type): raise TypeError( "The attribute type is %s, whereas the default value type is %s" % ( self.type.__name__, typeName(default))) self.default = default elif not const: self.default = None else: raise ValueError("Constant attribute without value") if optional: self.optional = optional else: self.optional = (self.default is not None) self.const = const self.xml = xml self.index = Attribute._index Attribute._index += 1
def getList(getter, data): if not isinstance(data, (list, tuple)): raise TypeError("Expected a tuple or a list, got a %s" % typeName(data)) return [getter(item) for item in data]
def _getEnabled(value): if not isinstance(value, bool): raise ValueError("Expected a boolean value for ON/OFF state, got %s" % typeName(value)) return value
def checkComplexType(result): result_type = type(result) if result_type in (tuple, list): for item in result: checkComplexType(item) elif result_type is dict: for key, value in result.iteritems(): if not checkString(key): raise TransportError("A dictionary key have to be a string, not a %s" % typeName(key)) checkComplexType(value) else: checkSimpleType(result)