def test_is_a_property_setter(self): self.assertFalse(Attributes.is_a_property_setter([])) self.assertFalse(Attributes.is_a_property_setter(['Property.Get(PropertyName)'])) self.assertTrue(Attributes.is_a_property_setter(['Property.Set(PropertyName)'])) self.assertFalse(Attributes.is_a_property_setter(['Class.Method(ServiceName.ClassName,MethodName)'])) self.assertFalse(Attributes.is_a_property_setter(['Class.StaticMethod(ServiceName.ClassName,MethodName)'])) self.assertFalse(Attributes.is_a_property_setter(['Class.Property.Get(ServiceName.ClassName,PropertyName)'])) self.assertFalse(Attributes.is_a_property_setter(['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
def test_is_a_property_setter(self): self.assertFalse(Attributes.is_a_property_setter([])) self.assertFalse(Attributes.is_a_property_setter( ['Property.Get(PropertyName)'])) self.assertTrue(Attributes.is_a_property_setter( ['Property.Set(PropertyName)'])) self.assertFalse(Attributes.is_a_property_setter( ['Class.Method(ServiceName.ClassName,MethodName)'])) self.assertFalse(Attributes.is_a_property_setter( ['Class.StaticMethod(ServiceName.ClassName,MethodName)'])) self.assertFalse(Attributes.is_a_property_setter( ['Class.Property.Get(ServiceName.ClassName,PropertyName)'])) self.assertFalse(Attributes.is_a_property_setter( ['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
def generate_context(self): procedures = {} properties = {} classes = {} enumerations = {} exceptions = {} for name, cls in self._defs['classes'].items(): classes[name] = { 'methods': {}, 'static_methods': {}, 'properties': {}, 'documentation': self.parse_documentation(cls['documentation']) } for name, enumeration in self._defs['enumerations'].items(): enumerations[name] = { 'values': [{ 'name': self.parse_name(x['name']), 'value': x['value'], 'documentation': self.parse_documentation( x['documentation']) } for x in enumeration['values']], 'documentation': self.parse_documentation( enumeration['documentation']) } for name, exception in self._defs['exceptions'].items(): exceptions[name] = { 'documentation': self.parse_documentation( exception['documentation']) } for name, procedure in self._defs['procedures'].items(): if Attributes.is_a_procedure(name): procedures[self.parse_name(name)] = { 'procedure': procedure, 'remote_name': name, 'parameters': self.generate_context_parameters(procedure), 'return_type': self.parse_return_type( self.get_return_type(procedure)), 'documentation': self.parse_documentation( procedure['documentation']) } elif Attributes.is_a_property_getter(name): property_name = self.parse_name( Attributes.get_property_name(name)) if property_name not in properties: properties[property_name] = { 'type': self.parse_return_type( self.get_return_type(procedure)), 'getter': None, 'setter': None, 'documentation': self.parse_documentation( procedure['documentation']) } properties[property_name]['getter'] = { 'procedure': procedure, 'remote_name': name } elif Attributes.is_a_property_setter(name): property_name = self.parse_name( Attributes.get_property_name(name)) params = self.generate_context_parameters(procedure) if property_name not in properties: properties[property_name] = { 'type': params[0]['type'], 'getter': None, 'setter': None, 'documentation': self.parse_documentation( procedure['documentation']) } properties[property_name]['setter'] = { 'procedure': procedure, 'remote_name': name } elif Attributes.is_a_class_method(name): class_name = Attributes.get_class_name(name) method_name = self.parse_name( Attributes.get_class_member_name(name)) params = self.generate_context_parameters(procedure) classes[class_name]['methods'][method_name] = { 'procedure': procedure, 'remote_name': name, 'parameters': params[1:], 'return_type': self.parse_return_type( self.get_return_type(procedure)), 'documentation': self.parse_documentation( procedure['documentation']) } elif Attributes.is_a_class_static_method(name): class_name = Attributes.get_class_name(name) method_name = self.parse_name( Attributes.get_class_member_name(name)) classes[class_name]['static_methods'][method_name] = { 'procedure': procedure, 'remote_name': name, 'parameters': self.generate_context_parameters(procedure), 'return_type': self.parse_return_type( self.get_return_type(procedure)), 'documentation': self.parse_documentation( procedure['documentation']) } elif Attributes.is_a_class_property_getter(name): class_name = Attributes.get_class_name(name) property_name = self.parse_name( Attributes.get_class_member_name(name)) if property_name not in classes[class_name]['properties']: classes[class_name]['properties'][property_name] = { 'type': self.parse_return_type( self.get_return_type(procedure)), 'getter': None, 'setter': None, 'documentation': self.parse_documentation( procedure['documentation']) } classes[class_name]['properties'][property_name]['getter'] = { 'procedure': procedure, 'remote_name': name } elif Attributes.is_a_class_property_setter(name): class_name = Attributes.get_class_name(name) property_name = self.parse_name( Attributes.get_class_member_name(name)) if property_name not in classes[class_name]['properties']: params = self.generate_context_parameters(procedure) classes[class_name]['properties'][property_name] = { 'type': params[1]['type'], 'getter': None, 'setter': None, 'documentation': self.parse_documentation( procedure['documentation']) } classes[class_name]['properties'][property_name]['setter'] = { 'procedure': procedure, 'remote_name': name } def sort(objs): if isinstance(objs, dict): return collections.OrderedDict( sorted([(x, sort(y)) for x, y in objs.items()], key=lambda x: x[0])) return objs return { 'service_name': self._service, 'procedures': sort(procedures), 'properties': sort(properties), 'classes': sort(classes), 'enumerations': sort(enumerations), 'exceptions': sort(exceptions) }
def generate_context(self): context = { 'service_name': self._service, 'service_id': self._defs['id'], 'procedures': {}, 'properties': {}, 'classes': {}, 'enumerations': {}, 'exceptions': {} } for name, cls in self._get_defs('classes'): context['classes'][name] = { 'methods': {}, 'static_methods': {}, 'properties': {}, 'documentation': self.parse_documentation( cls['documentation']) } for name, enumeration in self._get_defs('enumerations'): context['enumerations'][name] = { 'values': [{ 'name': self.parse_name(x['name']), 'value': x['value'], 'documentation': self.parse_documentation( x['documentation']) } for x in enumeration['values']], 'documentation': self.parse_documentation( enumeration['documentation']) } for name, exception in self._get_defs('exceptions'): context['exceptions'][name] = { 'documentation': self.parse_documentation( exception['documentation']) } for name, procedure in self._get_defs('procedures'): if Attributes.is_a_procedure(name): context['procedures'][self.parse_name(name)] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'], 'parameters': self.generate_context_parameters( procedure), 'return_type': self.parse_return_type( self.get_return_type(procedure)), 'documentation': self.parse_documentation( procedure['documentation']) } elif Attributes.is_a_property_getter(name): property_name = self.parse_name( Attributes.get_property_name(name)) if property_name not in context['properties']: context['properties'][property_name] = { 'type': self.parse_return_type( self.get_return_type(procedure)), 'getter': None, 'setter': None, 'documentation': self.parse_documentation( procedure['documentation']) } context['properties'][property_name]['getter'] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'] } elif Attributes.is_a_property_setter(name): property_name = self.parse_name( Attributes.get_property_name(name)) params = self.generate_context_parameters(procedure) if property_name not in context['properties']: context['properties'][property_name] = { 'type': params[0]['type'], 'getter': None, 'setter': None, 'documentation': self.parse_documentation( procedure['documentation']) } context['properties'][property_name]['setter'] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'] } elif Attributes.is_a_class_method(name): class_name = Attributes.get_class_name(name) method_name = self.parse_name( Attributes.get_class_member_name(name)) params = self.generate_context_parameters(procedure) context['classes'][class_name]['methods'][method_name] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'], 'parameters': params[1:], 'return_type': self.parse_return_type( self.get_return_type(procedure)), 'documentation': self.parse_documentation( procedure['documentation']) } elif Attributes.is_a_class_static_method(name): class_name = Attributes.get_class_name(name) cls = context['classes'][class_name] method_name = self.parse_name( Attributes.get_class_member_name(name)) cls['static_methods'][method_name] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'], 'parameters': self.generate_context_parameters( procedure), 'return_type': self.parse_return_type( self.get_return_type(procedure)), 'documentation': self.parse_documentation( procedure['documentation']) } elif Attributes.is_a_class_property_getter(name): class_name = Attributes.get_class_name(name) cls = context['classes'][class_name] property_name = self.parse_name( Attributes.get_class_member_name(name)) if property_name not in cls['properties']: cls['properties'][property_name] = { 'type': self.parse_return_type( self.get_return_type(procedure)), 'getter': None, 'setter': None, 'documentation': self.parse_documentation( procedure['documentation']) } cls['properties'][property_name]['getter'] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'] } elif Attributes.is_a_class_property_setter(name): class_name = Attributes.get_class_name(name) cls = context['classes'][class_name] property_name = self.parse_name( Attributes.get_class_member_name(name)) if property_name not in cls['properties']: params = self.generate_context_parameters(procedure) cls['properties'][property_name] = { 'type': params[1]['type'], 'getter': None, 'setter': None, 'documentation': self.parse_documentation( procedure['documentation']) } cls['properties'][property_name]['setter'] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'] } # Sort the context def sort_dict(x): return collections.OrderedDict( sorted(x.items(), key=lambda x: x[0])) context['procedures'] = sort_dict(context['procedures']) context['properties'] = sort_dict(context['properties']) context['enumerations'] = sort_dict(context['enumerations']) context['classes'] = sort_dict(context['classes']) context['exceptions'] = sort_dict(context['exceptions']) for cls in context['classes'].values(): cls['methods'] = sort_dict(cls['methods']) cls['static_methods'] = sort_dict(cls['static_methods']) cls['properties'] = sort_dict(cls['properties']) return context
def generate_context(self): procedures = {} properties = {} classes = {} enumerations = {} for name,cls in self._defs['classes'].items(): classes[name] = { 'methods': {}, 'static_methods': {}, 'properties': {}, 'documentation': self.parse_documentation(cls['documentation']) } for name,enumeration in self._defs['enumerations'].items(): enumerations[name] = { 'values': [{ 'name': self.parse_name(x['name']), 'value': x['value'], 'documentation': self.parse_documentation(x['documentation']) } for x in enumeration['values']], 'documentation': self.parse_documentation(enumeration['documentation']) } for name,procedure in self._defs['procedures'].items(): if Attributes.is_a_procedure(procedure['attributes']): procedures[self.parse_name(name)] = { 'procedure': procedure, 'remote_name': name, 'parameters': self.generate_context_parameters(procedure), 'return_type': self.parse_return_type(procedure), 'documentation': self.parse_documentation(procedure['documentation']) } elif Attributes.is_a_property_getter(procedure['attributes']): property_name = self.parse_name(Attributes.get_property_name(procedure['attributes'])) if property_name not in properties: properties[property_name] = { 'type': self.parse_return_type(procedure), 'getter': None, 'setter': None, 'documentation': self.parse_documentation(procedure['documentation']) } properties[property_name]['getter'] = { 'procedure': procedure, 'remote_name': name } elif Attributes.is_a_property_setter(procedure['attributes']): property_name = self.parse_name(Attributes.get_property_name(procedure['attributes'])) if property_name not in properties: properties[property_name] = { 'type': self.generate_context_parameters(procedure)[0]['type'], 'getter': None, 'setter': None, 'documentation': self.parse_documentation(procedure['documentation']) } properties[property_name]['setter'] = { 'procedure': procedure, 'remote_name': name } elif Attributes.is_a_class_method(procedure['attributes']): class_name = Attributes.get_class_name(procedure['attributes']) method_name = self.parse_name(Attributes.get_class_method_name(procedure['attributes'])) classes[class_name]['methods'][method_name] = { 'procedure': procedure, 'remote_name': name, 'parameters': self.generate_context_parameters(procedure)[1:], 'return_type': self.parse_return_type(procedure), 'documentation': self.parse_documentation(procedure['documentation']) } elif Attributes.is_a_class_static_method(procedure['attributes']): class_name = Attributes.get_class_name(procedure['attributes']) method_name = self.parse_name(Attributes.get_class_method_name(procedure['attributes'])) classes[class_name]['static_methods'][method_name] = { 'procedure': procedure, 'remote_name': name, 'parameters': self.generate_context_parameters(procedure), 'return_type': self.parse_return_type(procedure), 'documentation': self.parse_documentation(procedure['documentation']) } elif Attributes.is_a_class_property_getter(procedure['attributes']): class_name = Attributes.get_class_name(procedure['attributes']) property_name = self.parse_name(Attributes.get_class_property_name(procedure['attributes'])) if property_name not in classes[class_name]['properties']: classes[class_name]['properties'][property_name] = { 'type': self.parse_return_type(procedure), 'getter': None, 'setter': None, 'documentation': self.parse_documentation(procedure['documentation']) } classes[class_name]['properties'][property_name]['getter'] = { 'procedure': procedure, 'remote_name': name } elif Attributes.is_a_class_property_setter(procedure['attributes']): class_name = Attributes.get_class_name(procedure['attributes']) property_name = self.parse_name(Attributes.get_class_property_name(procedure['attributes'])) if property_name not in classes[class_name]['properties']: classes[class_name]['properties'][property_name] = { 'type': self.generate_context_parameters(procedure)[1]['type'], 'getter': None, 'setter': None, 'documentation': self.parse_documentation(procedure['documentation']) } classes[class_name]['properties'][property_name]['setter'] = { 'procedure': procedure, 'remote_name': name } def sort(d): if type(d) == dict: return collections.OrderedDict(sorted([(x,sort(y)) for x,y in d.items()], key=lambda x: x[0])) else: return d return { 'service_name': self._service, 'procedures': sort(procedures), 'properties': sort(properties), 'classes': sort(classes), 'enumerations': sort(enumerations) }
def generate_context(self): context = { 'service_name': self._service, 'service_id': self._defs['id'], 'procedures': {}, 'properties': {}, 'classes': {}, 'enumerations': {}, 'exceptions': {} } for name, cls in self._get_defs('classes'): context['classes'][name] = { 'methods': {}, 'static_methods': {}, 'properties': {}, 'documentation': self.parse_documentation(cls['documentation']) } for name, enumeration in self._get_defs('enumerations'): context['enumerations'][name] = { 'values': [{ 'name': self.parse_name(x['name']), 'value': x['value'], 'documentation': self.parse_documentation(x['documentation']) } for x in enumeration['values']], 'documentation': self.parse_documentation(enumeration['documentation']) } for name, exception in self._get_defs('exceptions'): context['exceptions'][name] = { 'documentation': self.parse_documentation(exception['documentation']) } for name, procedure in self._get_defs('procedures'): if Attributes.is_a_procedure(name): context['procedures'][self.parse_name(name)] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'], 'parameters': self.generate_context_parameters(procedure), 'return_type': self.parse_return_type(self.get_return_type(procedure)), 'documentation': self.parse_documentation(procedure['documentation']) } elif Attributes.is_a_property_getter(name): property_name = self.parse_name( Attributes.get_property_name(name)) if property_name not in context['properties']: context['properties'][property_name] = { 'type': self.parse_return_type( self.get_return_type(procedure)), 'getter': None, 'setter': None, 'documentation': self.parse_documentation(procedure['documentation']) } context['properties'][property_name]['getter'] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'] } elif Attributes.is_a_property_setter(name): property_name = self.parse_name( Attributes.get_property_name(name)) params = self.generate_context_parameters(procedure) if property_name not in context['properties']: context['properties'][property_name] = { 'type': params[0]['type'], 'getter': None, 'setter': None, 'documentation': self.parse_documentation(procedure['documentation']) } context['properties'][property_name]['setter'] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'] } elif Attributes.is_a_class_method(name): class_name = Attributes.get_class_name(name) method_name = self.parse_name( Attributes.get_class_member_name(name)) params = self.generate_context_parameters(procedure) context['classes'][class_name]['methods'][method_name] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'], 'parameters': params[1:], 'return_type': self.parse_return_type(self.get_return_type(procedure)), 'documentation': self.parse_documentation(procedure['documentation']) } elif Attributes.is_a_class_static_method(name): class_name = Attributes.get_class_name(name) cls = context['classes'][class_name] method_name = self.parse_name( Attributes.get_class_member_name(name)) cls['static_methods'][method_name] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'], 'parameters': self.generate_context_parameters(procedure), 'return_type': self.parse_return_type(self.get_return_type(procedure)), 'documentation': self.parse_documentation(procedure['documentation']) } elif Attributes.is_a_class_property_getter(name): class_name = Attributes.get_class_name(name) cls = context['classes'][class_name] property_name = self.parse_name( Attributes.get_class_member_name(name)) if property_name not in cls['properties']: cls['properties'][property_name] = { 'type': self.parse_return_type( self.get_return_type(procedure)), 'getter': None, 'setter': None, 'documentation': self.parse_documentation(procedure['documentation']) } cls['properties'][property_name]['getter'] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'] } elif Attributes.is_a_class_property_setter(name): class_name = Attributes.get_class_name(name) cls = context['classes'][class_name] property_name = self.parse_name( Attributes.get_class_member_name(name)) if property_name not in cls['properties']: params = self.generate_context_parameters(procedure) cls['properties'][property_name] = { 'type': params[1]['type'], 'getter': None, 'setter': None, 'documentation': self.parse_documentation(procedure['documentation']) } cls['properties'][property_name]['setter'] = { 'procedure': procedure, 'remote_name': name, 'remote_id': procedure['id'] } # Sort the context def sort_dict(x): return collections.OrderedDict( sorted(x.items(), key=lambda x: x[0])) context['procedures'] = sort_dict(context['procedures']) context['properties'] = sort_dict(context['properties']) context['enumerations'] = sort_dict(context['enumerations']) context['classes'] = sort_dict(context['classes']) context['exceptions'] = sort_dict(context['exceptions']) for cls in context['classes'].values(): cls['methods'] = sort_dict(cls['methods']) cls['static_methods'] = sort_dict(cls['static_methods']) cls['properties'] = sort_dict(cls['properties']) return context
def generate_context(self): procedures = {} properties = {} classes = {} enumerations = {} for name, cls in self._defs["classes"].items(): classes[name] = { "methods": {}, "static_methods": {}, "properties": {}, "documentation": self.parse_documentation(cls["documentation"]), } for name, enumeration in self._defs["enumerations"].items(): enumerations[name] = { "values": [ { "name": self.parse_name(x["name"]), "value": x["value"], "documentation": self.parse_documentation(x["documentation"]), } for x in enumeration["values"] ], "documentation": self.parse_documentation(enumeration["documentation"]), } for name, procedure in self._defs["procedures"].items(): if Attributes.is_a_procedure(procedure["attributes"]): procedures[self.parse_name(name)] = { "procedure": procedure, "remote_name": name, "parameters": self.generate_context_parameters(procedure), "return_type": self.parse_return_type(procedure), "documentation": self.parse_documentation(procedure["documentation"]), } elif Attributes.is_a_property_getter(procedure["attributes"]): property_name = self.parse_name(Attributes.get_property_name(procedure["attributes"])) if property_name not in properties: properties[property_name] = { "type": self.parse_return_type(procedure), "getter": None, "setter": None, "documentation": self.parse_documentation(procedure["documentation"]), } properties[property_name]["getter"] = {"procedure": procedure, "remote_name": name} elif Attributes.is_a_property_setter(procedure["attributes"]): property_name = self.parse_name(Attributes.get_property_name(procedure["attributes"])) if property_name not in properties: properties[property_name] = { "type": self.generate_context_parameters(procedure)[0]["type"], "getter": None, "setter": None, "documentation": self.parse_documentation(procedure["documentation"]), } properties[property_name]["setter"] = {"procedure": procedure, "remote_name": name} elif Attributes.is_a_class_method(procedure["attributes"]): class_name = Attributes.get_class_name(procedure["attributes"]) method_name = self.parse_name(Attributes.get_class_method_name(procedure["attributes"])) classes[class_name]["methods"][method_name] = { "procedure": procedure, "remote_name": name, "parameters": self.generate_context_parameters(procedure)[1:], "return_type": self.parse_return_type(procedure), "documentation": self.parse_documentation(procedure["documentation"]), } elif Attributes.is_a_class_static_method(procedure["attributes"]): class_name = Attributes.get_class_name(procedure["attributes"]) method_name = self.parse_name(Attributes.get_class_method_name(procedure["attributes"])) classes[class_name]["static_methods"][method_name] = { "procedure": procedure, "remote_name": name, "parameters": self.generate_context_parameters(procedure), "return_type": self.parse_return_type(procedure), "documentation": self.parse_documentation(procedure["documentation"]), } elif Attributes.is_a_class_property_getter(procedure["attributes"]): class_name = Attributes.get_class_name(procedure["attributes"]) property_name = self.parse_name(Attributes.get_class_property_name(procedure["attributes"])) if property_name not in classes[class_name]["properties"]: classes[class_name]["properties"][property_name] = { "type": self.parse_return_type(procedure), "getter": None, "setter": None, "documentation": self.parse_documentation(procedure["documentation"]), } classes[class_name]["properties"][property_name]["getter"] = { "procedure": procedure, "remote_name": name, } elif Attributes.is_a_class_property_setter(procedure["attributes"]): class_name = Attributes.get_class_name(procedure["attributes"]) property_name = self.parse_name(Attributes.get_class_property_name(procedure["attributes"])) if property_name not in classes[class_name]["properties"]: classes[class_name]["properties"][property_name] = { "type": self.generate_context_parameters(procedure)[1]["type"], "getter": None, "setter": None, "documentation": self.parse_documentation(procedure["documentation"]), } classes[class_name]["properties"][property_name]["setter"] = { "procedure": procedure, "remote_name": name, } def sort(d): if type(d) == dict: return collections.OrderedDict(sorted([(x, sort(y)) for x, y in d.items()], key=lambda x: x[0])) else: return d return { "service_name": self._service, "procedures": sort(procedures), "properties": sort(properties), "classes": sort(classes), "enumerations": sort(enumerations), }