def __init__(self, name, procedures, classes, enumerations, documentation, sort): super(Service, self).__init__() self.name = name self.fullname = name self.documentation = documentation self.cref = 'T:%s' % name members = [] cprocedures = defaultdict(lambda: dict()) properties = defaultdict(lambda: dict()) for pname,info in procedures.iteritems(): if Attributes.is_a_procedure(info['attributes']): members.append(Procedure(name, pname, **info)) elif Attributes.is_a_property_accessor(info['attributes']): propname = Attributes.get_property_name(info['attributes']) if Attributes.is_a_property_getter(info['attributes']): properties[propname]['getter'] = Procedure(name, pname, **info) else: properties[propname]['setter'] = Procedure(name, pname, **info) elif Attributes.is_a_class_member(info['attributes']): cname = Attributes.get_class_name(info['attributes']) cprocedures[cname][pname] = info for propname,prop in properties.iteritems(): members.append(Property(name, propname, **prop)) self.classes = {cname: Class(name, cname, cprocedures[cname], sort=sort, **cinfo) for (cname,cinfo) in classes.iteritems()} self.enumerations = {ename: Enumeration(name, ename, sort=sort, **einfo) for (ename,einfo) in enumerations.iteritems()} self.members = OrderedDict((member.name, member) for member in sorted(members, key=sort))
def __init__(self, name, procedures, classes, enumerations, documentation): super(Service, self).__init__() self.name = name self.fullname = name self.documentation = documentation self.cref = 'T:%s' % name self.members = {} for pname,info in procedures.items(): if Attributes.is_a_procedure(info['attributes']): proc = Procedure(name, pname, **info) self.members[proc.name] = proc properties = {} for pname,info in procedures.items(): if Attributes.is_a_property_accessor(info['attributes']): propname = Attributes.get_property_name(info['attributes']) if propname not in properties: properties[propname] = {} if Attributes.is_a_property_getter(info['attributes']): properties[propname]['getter'] = Procedure(name, pname, **info) else: properties[propname]['setter'] = Procedure(name, pname, **info) for propname,prop in properties.items(): prop = Property(name, propname, **prop) self.members[prop.name] = prop self.classes = {} for cname,cinfo in classes.items(): cprocedures = dict(filter( lambda (name,info): Attributes.is_a_class_member(info['attributes']) and \ Attributes.get_class_name(info['attributes']) == cname, procedures.items())) self.classes[cname] = Class(name, cname, cprocedures, **cinfo) self.enumerations = dict([(ename,Enumeration(name, ename, **einfo)) for ename,einfo in enumerations.items()])
def create_service(client, service): """ Create a new service type """ cls = type(str(service.name), (ServiceBase,), {'_client': client, '_name': service.name}) # Add class types to service for cls2 in service.classes: cls._add_service_class(cls2) # Add enumeration types to service for enum in service.enumerations: cls._add_service_enumeration(enum) # Add procedures for procedure in service.procedures: if Attributes.is_a_procedure(procedure.attributes): cls._add_service_procedure(procedure) # Add properties properties = defaultdict(lambda: [None,None]) for procedure in service.procedures: if Attributes.is_a_property_accessor(procedure.attributes): name = Attributes.get_property_name(procedure.attributes) if Attributes.is_a_property_getter(procedure.attributes): properties[name][0] = procedure else: properties[name][1] = procedure for name, procedures in properties.items(): cls._add_service_property(name, procedures[0], procedures[1]) # Add class methods for procedure in service.procedures: if Attributes.is_a_class_method(procedure.attributes): class_name = Attributes.get_class_name(procedure.attributes) method_name = Attributes.get_class_method_name(procedure.attributes) cls._add_service_class_method(class_name, method_name, procedure) # Add static class methods for procedure in service.procedures: if Attributes.is_a_class_static_method(procedure.attributes): class_name = Attributes.get_class_name(procedure.attributes) method_name = Attributes.get_class_method_name(procedure.attributes) cls._add_service_class_static_method(class_name, method_name, procedure) # Add class properties properties = defaultdict(lambda: [None,None]) for procedure in service.procedures: if Attributes.is_a_class_property_accessor(procedure.attributes): class_name = Attributes.get_class_name(procedure.attributes) property_name = Attributes.get_class_property_name(procedure.attributes) key = (class_name, property_name) if Attributes.is_a_class_property_getter(procedure.attributes): properties[key][0] = procedure else: properties[key][1] = procedure for (class_name, property_name), procedures in properties.items(): cls._add_service_class_property(class_name, property_name, procedures[0], procedures[1]) return cls()
def test_is_a_property_accessor(self): self.assertFalse(Attributes.is_a_property_accessor([])) self.assertTrue(Attributes.is_a_property_accessor(['Property.Get(PropertyName)'])) self.assertTrue(Attributes.is_a_property_accessor(['Property.Set(PropertyName)'])) self.assertFalse(Attributes.is_a_property_accessor(['Class.Method(ServiceName.ClassName,MethodName)'])) self.assertFalse(Attributes.is_a_property_accessor(['Class.StaticMethod(ServiceName.ClassName,MethodName)'])) self.assertFalse(Attributes.is_a_property_accessor(['Class.Property.Get(ServiceName.ClassName,PropertyName)'])) self.assertFalse(Attributes.is_a_property_accessor(['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
def __init__(self, name, procedures, classes, enumerations, exceptions, documentation, sort): super(Service, self).__init__() self.name = name self.fullname = name self.documentation = documentation self.cref = 'T:%s' % name members = [] cprocedures = defaultdict(dict) properties = defaultdict(dict) for pname, info in procedures.iteritems(): del info['id'] if 'game_scenes' in info: info['game_scenes'] = ', '.join( x.replace('_', ' ').title() for x in info['game_scenes']) else: info['game_scenes'] = 'All' if Attributes.is_a_procedure(pname): members.append(Procedure(name, pname, **info)) elif Attributes.is_a_property_accessor(pname): propname = Attributes.get_property_name(pname) if Attributes.is_a_property_getter(pname): properties[propname]['getter'] = Procedure( name, pname, **info) else: properties[propname]['setter'] = Procedure( name, pname, **info) elif Attributes.is_a_class_member(pname): cname = Attributes.get_class_name(pname) cprocedures[cname][pname] = info for propname, prop in properties.iteritems(): members.append(Property(name, propname, **prop)) self.classes = { cname: Class(name, cname, cprocedures[cname], sort=sort, **cinfo) for (cname, cinfo) in classes.iteritems() } self.enumerations = { ename: Enumeration(name, ename, sort=sort, **einfo) for (ename, einfo) in enumerations.iteritems() } self.exceptions = { ename: ExceptionNode(name, ename, **einfo) for (ename, einfo) in exceptions.iteritems() } self.members = OrderedDict( (member.name, member) for member in sorted(members, key=sort))
def test_is_a_property_accessor(self): self.assertFalse(Attributes.is_a_property_accessor([])) self.assertTrue(Attributes.is_a_property_accessor( ['Property.Get(PropertyName)'])) self.assertTrue(Attributes.is_a_property_accessor( ['Property.Set(PropertyName)'])) self.assertFalse(Attributes.is_a_property_accessor( ['Class.Method(ServiceName.ClassName,MethodName)'])) self.assertFalse(Attributes.is_a_property_accessor( ['Class.StaticMethod(ServiceName.ClassName,MethodName)'])) self.assertFalse(Attributes.is_a_property_accessor( ['Class.Property.Get(ServiceName.ClassName,PropertyName)'])) self.assertFalse(Attributes.is_a_property_accessor( ['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
def __init__(self, name, procedures, classes, enumerations, documentation, sort): super(Service, self).__init__() self.name = name self.fullname = name self.documentation = documentation self.cref = 'T:%s' % name members = [] cprocedures = defaultdict(dict) properties = defaultdict(dict) for pname, info in procedures.iteritems(): if Attributes.is_a_procedure(info['attributes']): members.append(Procedure(name, pname, **info)) elif Attributes.is_a_property_accessor(info['attributes']): propname = Attributes.get_property_name(info['attributes']) if Attributes.is_a_property_getter(info['attributes']): properties[propname]['getter'] = Procedure( name, pname, **info) else: properties[propname]['setter'] = Procedure( name, pname, **info) elif Attributes.is_a_class_member(info['attributes']): cname = Attributes.get_class_name(info['attributes']) cprocedures[cname][pname] = info for propname, prop in properties.iteritems(): members.append(Property(name, propname, **prop)) self.classes = { cname: Class(name, cname, cprocedures[cname], sort=sort, **cinfo) for (cname, cinfo) in classes.iteritems() } self.enumerations = { ename: Enumeration(name, ename, sort=sort, **einfo) for (ename, einfo) in enumerations.iteritems() } self.members = OrderedDict( (member.name, member) for member in sorted(members, key=sort))
def create_service(client, service): """ Create a new service type """ cls = type( str(service.name), (ServiceBase,), { '_client': client, '_name': service.name, '__doc__': _parse_documentation(service.documentation) } ) # Add class types to service for cls2 in service.classes: cls._add_service_class(cls2) # Add enumeration types to service for enum in service.enumerations: cls._add_service_enumeration(enum) # Add procedures for procedure in service.procedures: if Attributes.is_a_procedure(procedure.attributes): cls._add_service_procedure(procedure) # Add properties properties = defaultdict(lambda: [None, None]) for procedure in service.procedures: if Attributes.is_a_property_accessor(procedure.attributes): name = Attributes.get_property_name(procedure.attributes) if Attributes.is_a_property_getter(procedure.attributes): properties[name][0] = procedure else: properties[name][1] = procedure for name, procedures in properties.items(): cls._add_service_property(name, procedures[0], procedures[1]) # Add class methods for procedure in service.procedures: if Attributes.is_a_class_method(procedure.attributes): class_name = Attributes.get_class_name(procedure.attributes) method_name = Attributes.get_class_method_name(procedure.attributes) cls._add_service_class_method(class_name, method_name, procedure) # Add static class methods for procedure in service.procedures: if Attributes.is_a_class_static_method(procedure.attributes): class_name = Attributes.get_class_name(procedure.attributes) method_name = Attributes.get_class_method_name(procedure.attributes) cls._add_service_class_static_method(class_name, method_name, procedure) # Add class properties properties = defaultdict(lambda: [None, None]) for procedure in service.procedures: if Attributes.is_a_class_property_accessor(procedure.attributes): class_name = Attributes.get_class_name(procedure.attributes) property_name = Attributes.get_class_property_name(procedure.attributes) key = (class_name, property_name) if Attributes.is_a_class_property_getter(procedure.attributes): properties[key][0] = procedure else: properties[key][1] = procedure for (class_name, property_name), procedures in properties.items(): cls._add_service_class_property(class_name, property_name, procedures[0], procedures[1]) return cls()