def make_absolute(cls, base_uri, ref): if is_str(ref) and ref.startswith('#'): real_base_uri = base_uri if real_base_uri.endswith('#'): real_base_uri = base_uri[:-1] return "%s%s" % (real_base_uri, ref) return ref
def __init__(self, enum_dict, **kwargs): super(Enum, self).__init__(**kwargs) self.keys_to_names = enum_dict self.names_to_keys = {} for k, v in enum_dict.items(): if not is_str(v): raise Exception("Enum names must be strings") if v in self.names_to_keys: raise Exception("Duplicate enum value: %s" % k) self.names_to_keys[v] = k
def get_default_value(cls, py_default_value): if py_default_value is None: return None if is_str(py_default_value): key = 'string' elif type(py_default_value) == int: key = 'integer' elif type(py_default_value) == float: key = 'double' else: raise Exception("value %s of type %s could not be turned into ast.LiteralValue" % (py_default_value, type(py_default_value))) return ast.Literal(literal_value=ast.LiteralValue(**{key: py_default_value}))
def validate(self, value): # check type of value if not is_str(value): str_value = "<nonprintable value>" try: str_value = str(value) except: pass msg = "Expecting type string, got %s instead (value was %s)" % ( str(type(value)), str_value) raise ValueTypeException(msg) self.run_custom_validators(value)