Exemplo n.º 1
0
Arquivo: service.py Projeto: ilo/krpc
    def __init__(self, cls, client, service):
        """ Create a service from the dynamically created class type for the service, the client,
            and a KRPC.Service object received from a call to KRPC.GetServices()
            Should not be instantiated directly. Use _create_service instead. """
        super(_Service, self).__init__(client, service.name)
        self._cls = cls
        self._name = service.name
        self._types = client._types

        # Add class types to service
        for cls in service.classes:
            self._add_class(cls)

        # Add enumeration types to service
        for enum in service.enumerations:
            self._add_enumeration(enum)

        # Create plain procedures
        for procedure in service.procedures:
            if _Attributes.is_a_procedure(procedure.attributes):
                self._add_procedure(procedure)

        # Create static service properties
        properties = {}
        for procedure in service.procedures:
            if _Attributes.is_a_property_accessor(procedure.attributes):
                name = _Attributes.get_property_name(procedure.attributes)
                if name not in properties:
                    properties[name] = [None,None]
                if _Attributes.is_a_property_getter(procedure.attributes):
                    properties[name][0] = procedure
                else:
                    properties[name][1] = procedure
        for name, procedures in properties.items():
            self._add_property(name, procedures[0], procedures[1])

        # Create 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)
                self._add_class_method(class_name, method_name, procedure)

        # Create class properties
        properties = {}
        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 key not in properties:
                    properties[key] = [None,None]
                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():
            self._add_class_property(class_name, property_name, procedures[0], procedures[1])
Exemplo n.º 2
0
 def test_is_a_procedure(self):
     self.assertTrue(Attributes.is_a_procedure([]))
     self.assertFalse(Attributes.is_a_procedure(['Property.Get(PropertyName)']))
     self.assertFalse(Attributes.is_a_procedure(['Property.Set(PropertyName)']))
     self.assertFalse(Attributes.is_a_procedure(['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertFalse(Attributes.is_a_procedure(['Class.Property.Get(ServiceName.ClassName,PropertyName)']))
     self.assertFalse(Attributes.is_a_procedure(['Class.Property.Set(ServiceName.ClassName,PropertyName)']))