Exemplo n.º 1
0
    def __init__(self, service_name, name, procedures, documentation, sort):
        super(Class, self).__init__()
        self.service_name = service_name
        self.name = name
        self.fullname = service_name+'.'+name
        self.documentation = documentation
        self.cref = 'T:%s.%s' % (service_name, name)

        members = []
        properties = defaultdict(lambda: dict())

        for pname,pinfo in procedures.iteritems():

            #assert(Attributes.is_a_class_member(pinfo['attributes']))
            #assert(Attributes.get_class_name(pinfo['attributes']) == name)

            if Attributes.is_a_class_method(pinfo['attributes']):
                members.append(ClassMethod(service_name, name, pname, **pinfo))

            elif Attributes.is_a_class_static_method(pinfo['attributes']):
                members.append(ClassStaticMethod(service_name, name, pname, **pinfo))

            elif Attributes.is_a_class_property_accessor(pinfo['attributes']):
                propname = Attributes.get_class_property_name(pinfo['attributes'])
                proc = Procedure(service_name, pname, **pinfo)
                if Attributes.is_a_class_property_getter(pinfo['attributes']):
                    properties[propname]['getter'] = proc
                else:
                    properties[propname]['setter'] = proc

        for propname,prop in properties.iteritems():
            members.append(ClassProperty(service_name, name, propname, **prop))

        self.members = OrderedDict((member.name, member) for member in sorted(members, key=sort))
Exemplo n.º 2
0
    def __init__(self, service_name, name, procedures, documentation, sort):
        super(Class, self).__init__()
        self.service_name = service_name
        self.name = name
        self.fullname = service_name + '.' + name
        self.documentation = documentation
        self.cref = 'T:%s.%s' % (service_name, name)

        members = []
        properties = defaultdict(dict)

        for pname, pinfo in procedures.iteritems():
            if Attributes.is_a_class_method(pinfo['attributes']):
                members.append(ClassMethod(service_name, name, pname, **pinfo))

            elif Attributes.is_a_class_static_method(pinfo['attributes']):
                members.append(
                    ClassStaticMethod(service_name, name, pname, **pinfo))

            elif Attributes.is_a_class_property_accessor(pinfo['attributes']):
                propname = Attributes.get_class_property_name(
                    pinfo['attributes'])
                proc = Procedure(service_name, pname, **pinfo)
                if Attributes.is_a_class_property_getter(pinfo['attributes']):
                    properties[propname]['getter'] = proc
                else:
                    properties[propname]['setter'] = proc

        for propname, prop in properties.iteritems():
            members.append(ClassProperty(service_name, name, propname, **prop))

        self.members = OrderedDict(
            (member.name, member) for member in sorted(members, key=sort))
Exemplo n.º 3
0
 def test_get_class_name(self):
     self.assertRaises(ValueError, Attributes.get_class_name, [])
     self.assertRaises(ValueError, Attributes.get_class_name, ['Property.Get(PropertyName)'])
     self.assertRaises(ValueError, Attributes.get_class_name, ['Property.Set(PropertyName)'])
     self.assertEqual('ClassName', Attributes.get_class_name(['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertEqual('ClassName', Attributes.get_class_name(['Class.StaticMethod(ServiceName.ClassName,MethodName)']))
     self.assertEqual('ClassName', Attributes.get_class_name(['Class.Property.Get(ServiceName.ClassName,PropertyName)']))
     self.assertEqual('ClassName', Attributes.get_class_name(['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
Exemplo n.º 4
0
 def test_get_return_type_attributes(self):
     self.assertEqual([], Attributes.get_return_type_attrs([]))
     self.assertEqual([], Attributes.get_return_type_attrs(
         ['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertEqual(
         ['Class(ServiceName.ClassName)'],
         Attributes.get_return_type_attrs(
             ['ReturnType.Class(ServiceName.ClassName)']))
     self.assertEqual(
         ['Class(ServiceName.ClassName)'], Attributes.get_return_type_attrs(
             ['Class.Method(ServiceName.ClassName,MethodName)',
              'ReturnType.Class(ServiceName.ClassName)']))
     self.assertEqual(
         ['List(string)'], Attributes.get_return_type_attrs(
             ['ReturnType.List(string)']))
     self.assertEqual(
         ['Dictionary(int32,string)'], Attributes.get_return_type_attrs(
             ['ReturnType.Dictionary(int32,string)']))
     self.assertEqual(
         ['Set(string)'], Attributes.get_return_type_attrs(
             ['ReturnType.Set(string)']))
     self.assertEqual(
         ['List(Dictionary(int32,string))'],
         Attributes.get_return_type_attrs(
             ['ReturnType.List(Dictionary(int32,string))']))
     self.assertEqual(
         ['Dictionary(int32,List(ServiceName.ClassName))'],
         Attributes.get_return_type_attrs(
             ['ReturnType.Dictionary(int32,List(ServiceName.ClassName))']))
Exemplo n.º 5
0
 def test_get_property_name(self):
     self.assertRaises(ValueError, Attributes.get_property_name,
                       'ProcedureName')
     self.assertEqual('PropertyName',
                      Attributes.get_property_name('get_PropertyName'))
     self.assertEqual('PropertyName',
                      Attributes.get_property_name('set_PropertyName'))
     self.assertRaises(ValueError, Attributes.get_property_name,
                       'ClassName_MethodName')
     self.assertRaises(ValueError, Attributes.get_property_name,
                       'ClassName_StaticMethodName')
     self.assertRaises(ValueError, Attributes.get_property_name,
                       'ClassName_get_PropertyName)')
     self.assertRaises(ValueError, Attributes.get_property_name,
                       'ClassName_set_PropertyName)')
Exemplo n.º 6
0
 def test_get_class_name(self):
     self.assertRaises(ValueError, Attributes.get_class_name, [])
     self.assertRaises(
         ValueError, Attributes.get_class_name,
         ['Property.Get(PropertyName)'])
     self.assertRaises(
         ValueError, Attributes.get_class_name,
         ['Property.Set(PropertyName)'])
     self.assertEqual('ClassName', Attributes.get_class_name(
         ['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertEqual('ClassName', Attributes.get_class_name(
         ['Class.StaticMethod(ServiceName.ClassName,MethodName)']))
     self.assertEqual('ClassName', Attributes.get_class_name(
         ['Class.Property.Get(ServiceName.ClassName,PropertyName)']))
     self.assertEqual('ClassName', Attributes.get_class_name(
         ['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
Exemplo n.º 7
0
 def __init__(self,
              service_name,
              class_name,
              name,
              parameters,
              documentation,
              return_type=None,
              return_is_nullable=False,
              game_scenes=None):
     super(ClassStaticMethod, self).__init__()
     name = Attributes.get_class_member_name(name)
     self.service_name = service_name
     self.class_name = class_name
     self.name = name
     self.fullname = service_name + '.' + class_name + '.' + name
     if return_type is not None:
         self.return_type = as_type(self.types, return_type)
     else:
         self.return_type = None
     self.return_is_nullable = return_is_nullable
     self.parameters = [
         Parameter(documentation=documentation, **info)
         for info in parameters
     ]
     self.game_scenes = game_scenes
     self.documentation = documentation
     self.cref = 'M:%s.%s.%s' % (service_name, class_name, name)
Exemplo n.º 8
0
 def __init__(self,
              service_name,
              class_name,
              name,
              parameters,
              attributes,
              documentation,
              return_type=None):
     super(ClassStaticMethod, self).__init__()
     name = Attributes.get_class_method_name(attributes)
     self.service_name = service_name
     self.class_name = class_name
     self.name = name
     self.fullname = service_name + '.' + class_name + '.' + name
     if return_type is not None:
         self.return_type = self.types.get_return_type(
             return_type, attributes)
     else:
         self.return_type = None
     self.parameters = [
         Parameter(position=i,
                   attributes=attributes,
                   documentation=documentation,
                   **info) for i, info in enumerate(parameters)
     ]
     self.attributes = attributes
     self.documentation = documentation
     self.cref = 'M:%s.%s.%s' % (service_name, class_name, name)
Exemplo n.º 9
0
Arquivo: client.py Projeto: 602p/krpc
    def __init__(self, rpc_connection, stream_connection):
        self._types = Types()
        self._rpc_connection = rpc_connection
        self._rpc_connection_lock = threading.Lock()
        self._stream_connection = stream_connection
        self._request_type = self._types.as_type("KRPC.Request")
        self._response_type = self._types.as_type("KRPC.Response")

        # Set up the main KRPC service
        self.krpc = KRPC(self)

        services = self.krpc.get_services().services

        # Create class types
        # TODO: is this needed?!?
        for service in services:
            for procedure in service.procedures:
                try:
                    name = Attributes.get_class_name(procedure.attributes)
                    self._types.as_type("Class(" + service.name + "." + name + ")")
                except ValueError:
                    pass

        # Set up services
        for service in services:
            if service.name != "KRPC":
                setattr(self, _to_snake_case(service.name), create_service(self, service))

        # Set up stream update thread
        if stream_connection is not None:
            self._stream_thread = threading.Thread(target=krpc.stream.update_thread, args=(stream_connection,))
            self._stream_thread.daemon = True
            self._stream_thread.start()
        else:
            self._stream_thread = None
Exemplo n.º 10
0
 def __init__(self, service_name, class_name, name, getter=None, setter=None):
     super(ClassProperty, self).__init__()
     self.service_name = service_name
     self.class_name = class_name
     if getter is not None:
         name = Attributes.get_class_property_name(getter.attributes)
         self.type = getter.return_type
         self.documentation = getter.documentation
     else:
         name = Attributes.get_class_property_name(setter.attributes)
         self.type = setter.parameters[1].type
         self.documentation = setter.documentation
     self.name = name
     self.fullname = service_name+'.'+class_name+'.'+name
     self.getter = getter
     self.setter = setter
     self.cref = 'M:%s.%s.%s' % (service_name, class_name, name)
Exemplo n.º 11
0
    def __init__(self, service_name, name, procedures, documentation):
        super(Class, self).__init__()
        self.service_name = service_name
        self.name = name
        self.fullname = service_name+'.'+name
        self.documentation = documentation
        self.cref = 'T:%s.%s' % (service_name, name)

        self.members = {}
        for pname,pinfo in procedures.items():
            if Attributes.is_a_class_member(pinfo['attributes']) and \
               Attributes.get_class_name(pinfo['attributes']) == name:
                if Attributes.is_a_class_method(pinfo['attributes']):
                    member = ClassMethod(service_name, name, pname, **pinfo)
                elif Attributes.is_a_class_static_method(pinfo['attributes']):
                    member = ClassStaticMethod(service_name, name, pname, **pinfo)
                else:
                    continue
                self.members[member.name] = member

        properties = {}
        for pname,pinfo in procedures.items():
            if Attributes.is_a_class_property_accessor(pinfo['attributes']):
                propname = Attributes.get_class_property_name(pinfo['attributes'])
                if propname not in properties:
                    properties[propname] = {}
                if Attributes.is_a_class_property_getter(pinfo['attributes']):
                    properties[propname]['getter'] = Procedure(service_name, pname, **pinfo)
                else:
                    properties[propname]['setter'] = Procedure(service_name, pname, **pinfo)
        for propname,prop in properties.items():
            prop = ClassProperty(service_name, name, propname, **prop)
            self.members[prop.name] = prop
Exemplo n.º 12
0
 def test_get_class_name(self):
     self.assertRaises(ValueError,
                       Attributes.get_class_name, 'ProcedureName')
     self.assertRaises(ValueError,
                       Attributes.get_class_name, 'get_PropertyName')
     self.assertRaises(ValueError,
                       Attributes.get_class_name, 'set_PropertyName')
     self.assertEqual('ClassName',
                      Attributes.get_class_name('ClassName_MethodName'))
     self.assertEqual('ClassName',
                      Attributes.get_class_name(
                          'ClassName_StaticMethodName'))
     self.assertEqual('ClassName',
                      Attributes.get_class_name(
                          'ClassName_get_PropertyName)'))
     self.assertEqual('ClassName',
                      Attributes.get_class_name(
                          'ClassName_set_PropertyName)'))
Exemplo n.º 13
0
 def test_is_a_class_property_setter(self):
     self.assertFalse(Attributes.is_a_class_property_setter([]))
     self.assertFalse(Attributes.is_a_class_property_setter(['Property.Get(PropertyName)']))
     self.assertFalse(Attributes.is_a_class_property_setter(['Property.Set(PropertyName)']))
     self.assertFalse(Attributes.is_a_class_property_setter(['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertFalse(Attributes.is_a_class_property_setter(['Class.StaticMethod(ServiceName.ClassName,MethodName)']))
     self.assertFalse(Attributes.is_a_class_property_setter(['Class.Property.Get(ServiceName.ClassName,PropertyName)']))
     self.assertTrue(Attributes.is_a_class_property_setter(['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
Exemplo n.º 14
0
 def get_return_type(self, typ, attrs):
     """ Return a type object for the return value with the given
         protocol buffer type and procedure attributes """
     attrs = Attributes.get_return_type_attrs(attrs)
     for attr in attrs:
         try:
             return self.as_type(attr)
         except ValueError:
             pass
     return self.as_type(typ)
Exemplo n.º 15
0
 def get_return_type(self, typ, attrs):
     """ Return a type object for the return value with the given
         protocol buffer type and procedure attributes """
     attrs = Attributes.get_return_type_attrs(attrs)
     for attr in attrs:
         try:
             return self.as_type(attr)
         except ValueError:
             pass
     return self.as_type(typ)
Exemplo n.º 16
0
 def get_parameter_type(self, pos, typ, attrs):
     """ Return a type object for a parameter at the given
         position, with the given protocol buffer type and attributes """
     attrs = Attributes.get_parameter_type_attrs(pos, attrs)
     for attr in attrs:
         try:
             return self.as_type(attr)
         except ValueError:
             pass
     return self.as_type(typ)
Exemplo n.º 17
0
 def get_parameter_type(self, pos, typ, attrs):
     """ Return a type object for a parameter at the given
         position, with the given protocol buffer type and attributes """
     attrs = Attributes.get_parameter_type_attrs(pos, attrs)
     for attr in attrs:
         try:
             return self.as_type(attr)
         except ValueError:
             pass
     return self.as_type(typ)
Exemplo n.º 18
0
    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()])
Exemplo n.º 19
0
    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))
Exemplo n.º 20
0
 def __init__(self,
              service_name,
              class_name,
              name,
              getter=None,
              setter=None):
     super(ClassProperty, self).__init__()
     self.service_name = service_name
     self.class_name = class_name
     if getter is not None:
         name = Attributes.get_class_property_name(getter.attributes)
         self.type = getter.return_type
         self.documentation = getter.documentation
     else:
         name = Attributes.get_class_property_name(setter.attributes)
         self.type = setter.parameters[1].type
         self.documentation = setter.documentation
     self.name = name
     self.fullname = service_name + '.' + class_name + '.' + name
     self.getter = getter
     self.setter = setter
     self.cref = 'M:%s.%s.%s' % (service_name, class_name, name)
Exemplo n.º 21
0
 def test_get_return_type_attributes(self):
     self.assertEqual([], Attributes.get_return_type_attrs([]))
     self.assertEqual([], Attributes.get_return_type_attrs(
         ['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertEqual(['Class(ServiceName.ClassName)'], Attributes.get_return_type_attrs(
         ['ReturnType.Class(ServiceName.ClassName)']))
     self.assertEqual(['Class(ServiceName.ClassName)'], Attributes.get_return_type_attrs(
         ['Class.Method(ServiceName.ClassName,MethodName)',
          'ReturnType.Class(ServiceName.ClassName)']))
     self.assertEqual(['List(string)'], Attributes.get_return_type_attrs(
         ['ReturnType.List(string)']))
     self.assertEqual(['Dictionary(int32,string)'], Attributes.get_return_type_attrs(
         ['ReturnType.Dictionary(int32,string)']))
     self.assertEqual(['Set(string)'], Attributes.get_return_type_attrs(
         ['ReturnType.Set(string)']))
     self.assertEqual(['List(Dictionary(int32,string))'], Attributes.get_return_type_attrs(
         ['ReturnType.List(Dictionary(int32,string))']))
     self.assertEqual(['Dictionary(int32,List(ServiceName.ClassName))'], Attributes.get_return_type_attrs(
         ['ReturnType.Dictionary(int32,List(ServiceName.ClassName))']))
Exemplo n.º 22
0
 def __init__(self, service_name, class_name, name, parameters, attributes, documentation, return_type=None):
     super(ClassStaticMethod, self).__init__()
     name = Attributes.get_class_method_name(attributes)
     self.service_name = service_name
     self.class_name = class_name
     self.name = name
     self.fullname = service_name+'.'+class_name+'.'+name
     if return_type is not None:
         self.return_type = types.get_return_type(return_type, attributes)
     else:
         self.return_type = None
     self.parameters = [Parameter(position=i, attributes=attributes, documentation=documentation, **info) for i,info in enumerate(parameters)]
     self.attributes = attributes
     self.documentation = documentation
     self.cref = 'M:%s.%s.%s' % (service_name, class_name, name)
Exemplo n.º 23
0
    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))
Exemplo n.º 24
0
 def test_is_a_class_property_getter(self):
     self.assertFalse(Attributes.is_a_class_property_getter([]))
     self.assertFalse(Attributes.is_a_class_property_getter(
         ['Property.Get(PropertyName)']))
     self.assertFalse(Attributes.is_a_class_property_getter(
         ['Property.Set(PropertyName)']))
     self.assertFalse(Attributes.is_a_class_property_getter(
         ['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertFalse(Attributes.is_a_class_property_getter(
         ['Class.StaticMethod(ServiceName.ClassName,MethodName)']))
     self.assertTrue(Attributes.is_a_class_property_getter(
         ['Class.Property.Get(ServiceName.ClassName,PropertyName)']))
     self.assertFalse(Attributes.is_a_class_property_getter(
         ['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
Exemplo n.º 25
0
 def __init__(self, service_name, class_name, name, parameters,
              documentation, return_type=None, return_is_nullable=False):
     super(ClassStaticMethod, self).__init__()
     name = Attributes.get_class_member_name(name)
     self.service_name = service_name
     self.class_name = class_name
     self.name = name
     self.fullname = service_name+'.'+class_name+'.'+name
     if return_type is not None:
         self.return_type = as_type(self.types, return_type)
     else:
         self.return_type = None
     self.return_is_nullable = return_is_nullable
     self.parameters = [Parameter(documentation=documentation, **info)
                        for info in parameters]
     self.documentation = documentation
     self.cref = 'M:%s.%s.%s' % (service_name, class_name, name)
Exemplo n.º 26
0
    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))
Exemplo n.º 27
0
    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)
        }
Exemplo n.º 28
0
    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),
        }
Exemplo n.º 29
0
 def test_get_parameter_type_attributes(self):
     self.assertEqual([], Attributes.get_parameter_type_attrs(0, []))
     self.assertEqual([], Attributes.get_parameter_type_attrs(
         0, ['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertEqual([], Attributes.get_parameter_type_attrs(
         0, ['ReturnType.Class(ServiceName.ClassName)']))
     self.assertEqual([], Attributes.get_parameter_type_attrs(
         0, ['Class.Method(ServiceName.ClassName,MethodName)',
             'ReturnType.Class(ServiceName.ClassName)']))
     self.assertEqual([], Attributes.get_parameter_type_attrs(
         1, ['ParameterType(2).Class(ServiceName.ClassName)']))
     self.assertEqual(['Class(ServiceName.ClassName)'], Attributes.get_parameter_type_attrs(
         2, ['ParameterType(2).Class(ServiceName.ClassName)']))
     self.assertEqual(['Class(ServiceName.ClassName2)'], Attributes.get_parameter_type_attrs(
         2, ['ParameterType(0).Class(ServiceName.ClassName1)',
             'ParameterType(2).Class(ServiceName.ClassName2)']))
     self.assertEqual(['Class(ServiceName.ClassName)'], Attributes.get_parameter_type_attrs(
         1, ['Class.Method(ServiceName.ClassName,MethodName)',
             'ParameterType(1).Class(ServiceName.ClassName)']))
     self.assertEqual(['List(string)'], Attributes.get_parameter_type_attrs(
         1, ['ParameterType(1).List(string)']))
     self.assertEqual(['Dictionary(int32,string)'], Attributes.get_parameter_type_attrs(
         1, ['ParameterType(1).Dictionary(int32,string)']))
     self.assertEqual(['Set(string)'], Attributes.get_parameter_type_attrs(
         1, ['ParameterType(1).Set(string)']))
     self.assertEqual(['List(Dictionary(int32,string))'], Attributes.get_parameter_type_attrs(
         1, ['ParameterType(1).List(Dictionary(int32,string))']))
     self.assertEqual(['Dictionary(int32,List(ServiceName.ClassName))'], Attributes.get_parameter_type_attrs(
         1, ['ParameterType(1).Dictionary(int32,List(ServiceName.ClassName))']))
Exemplo n.º 30
0
    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
Exemplo n.º 31
0
    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
Exemplo n.º 32
0
    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)
        }
Exemplo n.º 33
0
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()
Exemplo n.º 34
0
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 enumeration in service.enumerations:
        cls._add_service_enumeration(enumeration)

    # Add exception types to service
    for exception in service.exceptions:
        cls._add_service_exception(exception)

    # Add procedures
    for procedure in service.procedures:
        if Attributes.is_a_procedure(procedure.name):
            cls._add_service_procedure(procedure)

    # Add properties
    properties = defaultdict(lambda: [None, None])
    for procedure in service.procedures:
        if Attributes.is_a_property_accessor(procedure.name):
            name = Attributes.get_property_name(procedure.name)
            if Attributes.is_a_property_getter(procedure.name):
                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.name):
            class_name = Attributes.get_class_name(procedure.name)
            method_name = Attributes.get_class_member_name(procedure.name)
            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.name):
            class_name = Attributes.get_class_name(procedure.name)
            method_name = Attributes.get_class_member_name(procedure.name)
            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.name):
            class_name = Attributes.get_class_name(procedure.name)
            property_name = Attributes.get_class_member_name(procedure.name)
            key = (class_name, property_name)
            if Attributes.is_a_class_property_getter(procedure.name):
                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()