def qualifed_classname(cls): if cls is None: return 'None' if isinstance(cls, scio.client.AnyType): # special case, these are instances not subclasses return 'Client._types.AnyType' if cls.__name__ in dir(scio.client): return "client.%s" % cls.__name__ return static.safe_id(cls.__name__)
def typeinfo(name, typecls): info = {} info['name'] = name info['deps'] = [] # classes this class absolutely depends on info['class_name'] = static.safe_id(typecls.__name__) # is this class just an alias to another class? # eg 'char' being another name for StringType info['is_alias'] = name != typecls.__name__ info['qualified_name'] = svc_qual_classname(typecls) info['bases'] = [dep_class(x, info['deps']) for x in typecls.__bases__] info['refs'] = [] # other type classes I refer to info['unresolved'] = set() # class references not resolved by sorting info['fields'] = fields = [] if hasattr(typecls, '_schema'): info['schema'] = typecls._schema quoted_fields = ('xsd_type', '_tag', '_namespace', '_values', '_type_attr', '_type_value', '_abstract', 'any_attribute') for field in quoted_fields: if field in typecls.__dict__: fields.append((field, repr(getattr(typecls, field)))) children = [] if hasattr(typecls, '_children'): for ch in typecls._children: children.append(static.safe_id(ch.name)) fields.append((static.safe_id(ch.name), Attr(ch.name, Ref(dep_class(ch.type, info['refs'])), ch.min, ch.max, ch.namespace))) if children: fields.append(('_children', '[%s]' % ', '.join(children))) attributes = [] if hasattr(typecls, '_attributes'): for ch in typecls._attributes: attributes.append(static.safe_id(ch.name)) fields.append((static.safe_id(ch.name), Attr(ch.name, Ref(dep_class(ch.type, info['refs'])), ch.min, ch.max, ch.namespace))) if attributes: fields.append(('_attributes', '[%s]' % ', '.join(attributes))) if hasattr(typecls, '_substitutions'): subs = {} for name, scls in typecls._substitutions.items(): subs[name] = Ref(dep_class(scls, info['refs'])) if subs: fields.append(('_substitutions', subs)) type_fields = ('_content_type', '_arrayType') for field in type_fields: if hasattr(typecls, field) and getattr(typecls, field) is not None: info[field] = Ref(dep_class(getattr(typecls, field), info['refs'])) fields.append((field, info[field])) # enum values if hasattr(typecls, '_values'): for val in typecls._values: fields.append((static.safe_id(val), repr(val))) return info
def typeinfo(name, typecls): info = {} info['name'] = name info['deps'] = [] # classes this class absolutely depends on info['class_name'] = static.safe_id(typecls.__name__) # is this class just an alias to another class? # eg 'char' being another name for StringType info['is_alias'] = name != typecls.__name__ info['qualified_name'] = svc_qual_classname(typecls) info['bases'] = [dep_class(x, info['deps']) for x in typecls.__bases__] info['refs'] = [] # other type classes I refer to info['unresolved'] = set() # class references not resolved by sorting info['fields'] = fields = [] if hasattr(typecls, '_schema'): info['schema'] = typecls._schema quoted_fields = ('xsd_type', '_tag', '_namespace', '_values', '_type_attr', '_type_value', '_abstract', 'any_attribute') for field in quoted_fields: if field in typecls.__dict__: fields.append((field, repr(getattr(typecls, field)))) children = [] if hasattr(typecls, '_children'): for ch in typecls._children: children.append(static.safe_id(ch.name)) fields.append((static.safe_id(ch.name), Attr(ch.name, Ref(dep_class(ch.type, info['refs'])), ch.min, ch.max, ch.namespace)) ) if children: fields.append(('_children', '[%s]' % ', '.join(children))) attributes = [] if hasattr(typecls, '_attributes'): for ch in typecls._attributes: attributes.append(static.safe_id(ch.name)) fields.append((static.safe_id(ch.name), Attr(ch.name, Ref(dep_class(ch.type, info['refs'])), ch.min, ch.max, ch.namespace)) ) if attributes: fields.append(('_attributes', '[%s]' % ', '.join(attributes))) if hasattr(typecls, '_substitutions'): subs = {} for name, scls in typecls._substitutions.items(): subs[name] = Ref(dep_class(scls, info['refs'])) if subs: fields.append(('_substitutions', subs)) type_fields = ('_content_type', '_arrayType') for field in type_fields: if hasattr(typecls, field) and getattr(typecls, field) is not None: info[field] = Ref(dep_class(getattr(typecls, field), info['refs'])) fields.append((field, info[field])) # enum values if hasattr(typecls, '_values'): for val in typecls._values: fields.append((static.safe_id(val), repr(val))) return info
def test_enum_restriction_not_first_element(): zf = M['zf'].Client() print zf.type.ApiAccessMask._values assert zf.type.ApiAccessMask._values for val in zf.type.ApiAccessMask._values: assert getattr(zf.type.ApiAccessMask, safe_id(val)) == val