Ejemplo n.º 1
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.Property.Get(ServiceName.ClassName,PropertyName)']))
     self.assertEqual('ClassName', Attributes.get_class_name(['Class.Property.Set(ServiceName.ClassName,PropertyName)']))
Ejemplo n.º 2
0
Archivo: service.py Proyecto: 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])
Ejemplo n.º 3
0
Archivo: client.py Proyecto: ilo/krpc
    def __init__(self, rpc_connection, stream_connection):
        self._rpc_connection = rpc_connection
        self._rpc_connection_lock = threading.Lock()
        self._stream_connection = stream_connection
        self._types = _Types()
        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 = KRPCService(self)

        services = self.krpc.get_services().services

        # Create class types
        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
        self._stream_thread = threading.Thread(target=krpc.stream.update_thread, args=(stream_connection,))
        self._stream_thread.daemon = True
        self._stream_thread.start()
Ejemplo n.º 4
0
    def __init__(self, connection):
        self._connection = connection
        self._connection_lock = threading.Lock()
        self._types = _Types()
        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 = KRPCService(self)

        services = self.krpc.get_services().services

        # Create class types
        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))