Exemplo n.º 1
0
def _parse_documentation_node(node):
    if node.tag == 'see':
        ref = node.attrib['cref']
        if ref[0] == 'M':
            ref = ref.split('.')
            ref[-1] = snake_case(ref[-1])
            ref = '.'.join(ref)
        return ref[2:]
    elif node.tag == 'paramref':
        return snake_case(node.attrib['name'])
    elif node.tag == 'c':
        replace = {'true': 'True', 'false': 'False', 'null': 'None'}
        if node.text in replace:
            return replace[node.text]
        else:
            return node.text
    elif node.tag == 'list':
        content = '\n'
        for item in node:
            item_content = _parse_documentation_content(item[0])
            content += '* %s\n' % '\n'.join(
                _indent(item_content.split('\n'), 2))[2:].rstrip()
        return content
    else:
        return node.text
Exemplo n.º 2
0
    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._stream_cache = {}
        self._stream_cache_lock = threading.Lock()
        self._request_type = self._types.as_type('KRPC.Request')
        self._response_type = self._types.as_type('KRPC.Response')

        # Get the services
        services = self._invoke('KRPC', 'GetServices', [], [], [], self._types.as_type('KRPC.Services')).services

        # Set up services
        for service in services:
            setattr(self, snake_case(service.name), create_service(self, service))

        # Set up stream update thread
        if stream_connection is not None:
            self._stream_thread_stop = threading.Event()
            self._stream_thread = threading.Thread(target=krpc.stream.update_thread,
                                                   args=(stream_connection, self._stream_thread_stop,
                                                         self._stream_cache, self._stream_cache_lock))
            self._stream_thread.daemon = True
            self._stream_thread.start()
        else:
            self._stream_thread = None
Exemplo n.º 3
0
def _parse_documentation(xml):
    if xml.strip() == '':
        return ''
    parser = ElementTree.XMLParser(encoding='UTF-8')
    root = ElementTree.XML(xml.encode('UTF-8'), parser=parser)
    summary = ''
    params = []
    returns = ''
    note = ''
    for node in root:
        if node.tag == 'summary':
            summary = _parse_documentation_content(node)
        elif node.tag == 'param':
            doc = _parse_documentation_content(node).replace('\n', '')
            params.append('%s: %s' % (snake_case(node.attrib['name']), doc))
        elif node.tag == 'returns':
            returns = 'Returns:\n    %s' % \
                      _parse_documentation_content(node).replace('\n', '')
        elif node.tag == 'remarks':
            note = 'Note: %s' % _parse_documentation_content(node)
    if params:
        params_str = 'Args:\n%s' % '\n'.join('    ' + x for x in params)
    else:
        params_str = ''
    return '\n\n'.join(x for x in (summary, params_str, returns, note)
                       if x != '')
Exemplo n.º 4
0
    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._stream_cache = {}
        self._stream_cache_lock = threading.Lock()
        self._request_type = self._types.as_type('KRPC.Request')
        self._response_type = self._types.as_type('KRPC.Response')

        # Get the services
        services = self._invoke('KRPC', 'GetServices', [], [], [],
                                self._types.as_type('KRPC.Services')).services

        # Set up services
        for service in services:
            setattr(self, snake_case(service.name),
                    create_service(self, service))

        # Set up stream update thread
        if stream_connection is not None:
            self._stream_thread_stop = threading.Event()
            self._stream_thread = threading.Thread(
                target=krpc.stream.update_thread,
                args=(stream_connection, self._stream_thread_stop,
                      self._stream_cache, self._stream_cache_lock))
            self._stream_thread.daemon = True
            self._stream_thread.start()
        else:
            self._stream_thread = None
Exemplo n.º 5
0
 def _add_service_class_property(cls, class_name, property_name, getter=None, setter=None):
     """ Add a property to a class """
     class_cls = cls._client._types.as_type('Class(' + cls._name + '.' + class_name + ')').python_type
     doc = None
     if getter:
         doc = _parse_documentation(getter.documentation)
     elif setter:
         doc = _parse_documentation(setter.documentation)
     if getter:
         getter_name = getter.name
         param_names, param_types, _, _, return_type = cls._parse_procedure(getter)
         # Rename this to self if it doesn't cause a name clash
         if 'self' not in param_names:
             param_names[0] = 'self'
         getter = _construct_func(cls._client._invoke, cls._name, getter_name, [],
                                  param_names, param_types, [True], [None], return_type)
         build_request = _construct_func(cls._client._build_request, cls._name, getter_name, [],
                                         param_names, param_types, [True], [None], return_type)
         setattr(getter, '_build_request', build_request)
         setattr(getter, '_return_type', return_type)
     if setter:
         param_names, param_types, _, _, return_type = cls._parse_procedure(setter)
         setter = _construct_func(cls._client._invoke, cls._name, setter.name, [],
                                  param_names, param_types, [True, True], [None, None], None)
     property_name = str(snake_case(property_name))
     return class_cls._add_property(property_name, getter, setter, doc=doc)
Exemplo n.º 6
0
 def _add_service_enumeration(cls, enum):
     """ Add an enumeration type """
     name = enum.name
     enum_type = cls._client._types.as_type('Enum(' + cls._name + '.' + name + ')',
                                            _parse_documentation(enum.documentation))
     enum_type.set_values(dict((str(snake_case(x.name)), x.value) for x in enum.values))
     setattr(cls, name, enum_type.python_type)
Exemplo n.º 7
0
 def _add_service_property(cls, name, getter=None, setter=None):
     """ Add a property """
     doc = None
     if getter:
         doc = _parse_documentation(getter.documentation)
     elif setter:
         doc = _parse_documentation(setter.documentation)
     if getter:
         getter_name = getter.name
         _, _, _, _, return_type = cls._parse_procedure(getter)
         getter = _construct_func(cls._client._invoke, cls._name,
                                  getter_name, ['self'], [], [], [], [],
                                  return_type)
         build_request = _construct_func(cls._client._build_request,
                                         cls._name, getter_name, ['self'],
                                         [], [], [], [], return_type)
         setattr(getter, '_build_request', build_request)
         setattr(getter, '_return_type', return_type)
     if setter:
         param_names, param_types, _, _, _ = cls._parse_procedure(setter)
         setter = _construct_func(cls._client._invoke, cls._name,
                                  setter.name, ['self'], param_names,
                                  param_types, [True], [None], None)
     name = str(snake_case(name))
     return cls._add_property(name, getter, setter, doc=doc)
Exemplo n.º 8
0
 def _add_service_procedure(cls, procedure):
     """ Add a procedure """
     param_names, param_types, param_required, param_default, return_type = cls._parse_procedure(procedure)
     func = _construct_func(
         cls._client._invoke,
         cls._name,
         procedure.name,
         [],
         param_names,
         param_types,
         param_required,
         param_default,
         return_type,
     )
     build_request = _construct_func(
         cls._client._build_request,
         cls._name,
         procedure.name,
         [],
         param_names,
         param_types,
         param_required,
         param_default,
         return_type,
     )
     setattr(func, "_build_request", build_request)
     setattr(func, "_return_type", return_type)
     name = str(snake_case(procedure.name))
     return cls._add_static_method(name, func, doc=_parse_documentation(procedure.documentation))
Exemplo n.º 9
0
def _parse_documentation(xml):
    if xml.strip() == '':
        return ''
    parser = ElementTree.XMLParser(encoding='UTF-8')
    root = ElementTree.XML(xml.encode('UTF-8'), parser=parser)
    summary = ''
    params = []
    returns = ''
    note = ''
    for node in root:
        if node.tag == 'summary':
            summary = _parse_documentation_content(node)
        elif node.tag == 'param':
            doc = _parse_documentation_content(node).replace('\n', '')
            params.append('%s: %s' % (snake_case(node.attrib['name']), doc))
        elif node.tag == 'returns':
            returns = 'Returns:\n    %s' % \
                      _parse_documentation_content(node).replace('\n', '')
        elif node.tag == 'remarks':
            note = 'Note: %s' % _parse_documentation_content(node)
    if params:
        params_str = 'Args:\n%s' % '\n'.join('    ' + x for x in params)
    else:
        params_str = ''
    return '\n\n'.join(x for x in (summary, params_str, returns, note)
                       if x != '')
Exemplo n.º 10
0
 def ref(self, obj):
     name = obj.fullname.split('.')
     if isinstance(obj, Procedure) or isinstance(obj, Property) or \
        isinstance(obj, ClassMethod) or isinstance(obj, ClassStaticMethod) or isinstance(obj, ClassProperty) or \
        isinstance(obj, EnumerationValue):
         name[-1] = snake_case(name[-1])
     return self.shorten_ref('.'.join(name)).replace('.', '::')
Exemplo n.º 11
0
 def ref(self, obj):
     name = obj.fullname.split('.')
     if any(isinstance(obj, cls) for cls in
            (Procedure, Property, ClassMethod, ClassStaticMethod,
             ClassProperty, EnumerationValue)):
         name[-1] = snake_case(name[-1])
     return self.shorten_ref('.'.join(name)).replace('.', '::')
Exemplo n.º 12
0
Arquivo: cpp.py Projeto: Loran425/krpc
 def ref(self, obj):
     name = obj.fullname.split('.')
     if any(isinstance(obj, cls) for cls in
            (Procedure, Property, ClassMethod, ClassStaticMethod,
             ClassProperty, EnumerationValue)):
         name[-1] = snake_case(name[-1])
     return self.shorten_ref('.'.join(name)).replace('.', '::')
Exemplo n.º 13
0
    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._stream_manager = StreamManager(self)

        # Get the services
        services = self._invoke('KRPC', 'GetServices', [], [], [],
                                self._types.services_type).services

        # Set up services
        for service in services:
            setattr(self, snake_case(service.name),
                    create_service(self, service))

        # Set up stream update thread
        if stream_connection is not None:
            self._stream_thread_stop = threading.Event()
            self._stream_thread = threading.Thread(
                target=krpc.streammanager.update_thread,
                args=(self._stream_manager, stream_connection,
                      self._stream_thread_stop))
            self._stream_thread.daemon = True
            self._stream_thread.start()
        else:
            self._stream_thread = None
Exemplo n.º 14
0
 def _add_service_class_property(cls, class_name, property_name, getter=None, setter=None):
     """ Add a property to a class """
     class_cls = cls._client._types.as_type('Class('+cls._name+'.'+class_name+')').python_type
     doc = None
     if getter:
         doc = _parse_documentation(getter.documentation)
     elif setter:
         doc = _parse_documentation(setter.documentation)
     if getter:
         getter_name = getter.name
         param_names, param_types, _, _, return_type = cls._parse_procedure(getter)
         # Rename this to self if it doesn't cause a name clash
         if 'self' not in param_names:
             param_names[0] = 'self'
         getter = _construct_func(cls._client._invoke, cls._name, getter_name, [],
                                  param_names, param_types, [True], [None], return_type)
         build_request = _construct_func(cls._client._build_request, cls._name, getter_name, [],
                                         param_names, param_types, [True], [None], return_type)
         setattr(getter, '_build_request', build_request)
         setattr(getter, '_return_type', return_type)
     if setter:
         param_names, param_types, _, _, return_type = cls._parse_procedure(setter)
         setter = _construct_func(cls._client._invoke, cls._name, setter.name, [],
                                  param_names, param_types, [True, True], [None, None], None)
     property_name = str(snake_case(property_name))
     return class_cls._add_property(property_name, getter, setter, doc=doc)
Exemplo n.º 15
0
 def _add_service_class_static_method(cls, class_name, method_name, procedure):
     """ Add a static method to a class """
     class_cls = cls._client._types.as_type("Class(" + cls._name + "." + class_name + ")").python_type
     param_names, param_types, param_required, param_default, return_type = cls._parse_procedure(procedure)
     func = _construct_func(
         cls._client._invoke,
         cls._name,
         procedure.name,
         [],
         param_names,
         param_types,
         param_required,
         param_default,
         return_type,
     )
     build_request = _construct_func(
         cls._client._build_request,
         cls._name,
         procedure.name,
         [],
         param_names,
         param_types,
         param_required,
         param_default,
         return_type,
     )
     setattr(func, "_build_request", build_request)
     setattr(func, "_return_type", return_type)
     name = str(snake_case(method_name))
     class_cls._add_static_method(name, func, doc=_parse_documentation(procedure.documentation))
Exemplo n.º 16
0
 def _add_service_class_method(cls, class_name, method_name, procedure):
     """ Add a method to a class """
     class_cls = cls._client._types.as_type("Class(" + cls._name + "." + class_name + ")").python_type
     param_names, param_types, param_required, param_default, return_type = cls._parse_procedure(procedure)
     # Rename this to self if it doesn't cause a name clash
     if "self" not in param_names:
         param_names[0] = "self"
     func = _construct_func(
         cls._client._invoke,
         cls._name,
         procedure.name,
         [],
         param_names,
         param_types,
         param_required,
         param_default,
         return_type,
     )
     build_request = _construct_func(
         cls._client._build_request,
         cls._name,
         procedure.name,
         [],
         param_names,
         param_types,
         param_required,
         param_default,
         return_type,
     )
     setattr(func, "_build_request", build_request)
     setattr(func, "_return_type", return_type)
     name = str(snake_case(method_name))
     class_cls._add_method(name, func, doc=_parse_documentation(procedure.documentation))
Exemplo n.º 17
0
 def parse_cref(cref):
     if cref[0] == 'M':
         cref = cref[2:].split('.')
         member = snake_case(cref[-1])
         del cref[-1]
         return '::'.join(cref)+'::'+member
     elif cref[0] == 'T':
         return cref[2:].replace('.', '::')
     else:
         raise RuntimeError('Unknown cref \'%s\'' % cref)
Exemplo n.º 18
0
 def _add_service_enumeration(cls, enumeration):
     """ Add an enum type """
     name = enumeration.name
     enumeration_type = cls._client._types.enumeration_type(
         cls._name, name, _parse_documentation(enumeration.documentation))
     enumeration_type.set_values(dict(
         (str(snake_case(x.name)), {
             'value': x.value, 'doc': _parse_documentation(x.documentation)
         }) for x in enumeration.values))
     setattr(cls, name, enumeration_type.python_type)
Exemplo n.º 19
0
 def parse_cref(cref):
     if cref[0] == 'M':
         cref = cref[2:].split('.')
         member = snake_case(cref[-1])
         del cref[-1]
         return '::'.join(cref)+'::'+member
     elif cref[0] == 'T':
         return cref[2:].replace('.', '::')
     else:
         raise RuntimeError('Unknown cref \'%s\'' % cref)
Exemplo n.º 20
0
 def _add_service_enumeration(cls, enumeration):
     """ Add an enum type """
     name = enumeration.name
     enumeration_type = cls._client._types.enumeration_type(
         cls._name, name, _parse_documentation(enumeration.documentation))
     enumeration_type.set_values(
         dict((str(snake_case(x.name)), {
             'value': x.value,
             'doc': _parse_documentation(x.documentation)
         }) for x in enumeration.values))
     setattr(cls, name, enumeration_type.python_type)
Exemplo n.º 21
0
 def _add_service_procedure(cls, procedure):
     """ Add a procedure """
     param_names, param_types, param_required, param_default, return_type = cls._parse_procedure(procedure)
     func = _construct_func(cls._client._invoke, cls._name, procedure.name, [],
                            param_names, param_types, param_required, param_default, return_type)
     build_request = _construct_func(cls._client._build_request, cls._name, procedure.name, [],
                                     param_names, param_types, param_required, param_default, return_type)
     setattr(func, '_build_request', build_request)
     setattr(func, '_return_type', return_type)
     name = str(snake_case(procedure.name))
     return cls._add_static_method(name, func, doc=_parse_documentation(procedure.documentation))
Exemplo n.º 22
0
 def _add_service_class_static_method(cls, class_name, method_name, procedure):
     """ Add a static method to a class """
     class_cls = cls._client._types.as_type('Class(' + cls._name + '.' + class_name + ')').python_type
     param_names, param_types, param_required, param_default, return_type = cls._parse_procedure(procedure)
     func = _construct_func(cls._client._invoke, cls._name, procedure.name, [],
                            param_names, param_types, param_required, param_default, return_type)
     build_request = _construct_func(cls._client._build_request, cls._name, procedure.name, [],
                                     param_names, param_types, param_required, param_default, return_type)
     setattr(func, '_build_request', build_request)
     setattr(func, '_return_type', return_type)
     name = str(snake_case(method_name))
     class_cls._add_static_method(name, func, doc=_parse_documentation(procedure.documentation))
Exemplo n.º 23
0
 def _add_service_enumeration(cls, enum):
     """ Add an enumeration type """
     name = enum.name
     enum_type = cls._client._types.as_type(
         "Enum(" + cls._name + "." + name + ")", _parse_documentation(enum.documentation)
     )
     enum_type.set_values(
         dict(
             (str(snake_case(x.name)), {"value": x.value, "doc": _parse_documentation(x.documentation)})
             for x in enum.values
         )
     )
     setattr(cls, name, enum_type.python_type)
Exemplo n.º 24
0
def _parse_documentation_node(node):
    if node.tag == 'see':
        ref = node.attrib['cref']
        if ref[0] == 'M':
            ref = ref.split('.')
            ref[-1] = snake_case(ref[-1])
            ref = '.'.join(ref)
        return ref[2:]
    elif node.tag == 'paramref':
        return snake_case(node.attrib['name'])
    elif node.tag == 'c':
        replace = {'true': 'True', 'false': 'False', 'null': 'None'}
        if node.text in replace:
            return replace[node.text]
        return node.text
    elif node.tag == 'list':
        content = '\n'
        for item in node:
            item_content = _parse_documentation_content(item[0])
            content += '* %s\n' % '\n'.join(
                _indent(item_content.split('\n'), 2))[2:].rstrip()
        return content
    return node.text
Exemplo n.º 25
0
 def _parse_procedure(cls, procedure):
     param_names = [snake_case(param.name) for param in procedure.parameters]
     param_types = [cls._client._types.get_parameter_type(i, param.type, procedure.attributes) for i,param in enumerate(procedure.parameters)]
     param_required = [not param.has_default_argument for param in procedure.parameters]
     param_default = []
     for param,typ in zip(procedure.parameters, param_types):
         if param.has_default_argument:
             param_default.append(Decoder.decode(param.default_argument, typ))
         else:
             param_default.append(None)
     return_type = None
     if procedure.has_return_type:
         return_type = cls._client._types.get_return_type(procedure.return_type, procedure.attributes)
     return param_names, param_types, param_required, param_default, return_type
Exemplo n.º 26
0
 def _parse_procedure(cls, procedure):
     param_names = [snake_case(param.name) for param in procedure.parameters]
     param_types = [cls._client._types.get_parameter_type(i, param.type, procedure.attributes)
                    for i, param in enumerate(procedure.parameters)]
     param_required = [not param.has_default_value for param in procedure.parameters]
     param_default = []
     for param, typ in zip(procedure.parameters, param_types):
         if param.has_default_value:
             param_default.append(Decoder.decode(param.default_value, typ))
         else:
             param_default.append(None)
     return_type = None
     if procedure.has_return_type:
         return_type = cls._client._types.get_return_type(procedure.return_type, procedure.attributes)
     return param_names, param_types, param_required, param_default, return_type
Exemplo n.º 27
0
def _parse_documentation_node(node):
    if node.tag == "see":
        ref = node.attrib["cref"]
        if ref[0] == "M":
            ref = ref.split(".")
            ref[-1] = snake_case(ref[-1])
            ref = ".".join(ref)
        return ref[2:]
    elif node.tag == "paramref":
        return snake_case(node.attrib["name"])
    elif node.tag == "c":
        replace = {"true": "True", "false": "False", "null": "None"}
        if node.text in replace:
            return replace[node.text]
        else:
            return node.text
    elif node.tag == "list":
        content = "\n"
        for item in node:
            item_content = _parse_documentation_content(item[0])
            content += "* %s\n" % "\n".join(_indent(item_content.split("\n"), 2))[2:].rstrip()
        return content
    else:
        return node.text
Exemplo n.º 28
0
 def _add_service_class_method(cls, class_name, method_name, procedure):
     """ Add a method to a class """
     class_cls = cls._client._types.as_type('Class(' + cls._name + '.' + class_name + ')').python_type
     param_names, param_types, param_required, param_default, return_type = cls._parse_procedure(procedure)
     # Rename this to self if it doesn't cause a name clash
     if 'self' not in param_names:
         param_names[0] = 'self'
     func = _construct_func(cls._client._invoke, cls._name, procedure.name, [],
                            param_names, param_types, param_required, param_default, return_type)
     build_request = _construct_func(cls._client._build_request, cls._name, procedure.name, [],
                                     param_names, param_types, param_required, param_default, return_type)
     setattr(func, '_build_request', build_request)
     setattr(func, '_return_type', return_type)
     name = str(snake_case(method_name))
     class_cls._add_method(name, func, doc=_parse_documentation(procedure.documentation))
Exemplo n.º 29
0
 def ref(self, obj):
     name = obj.fullname
     if isinstance(obj, Procedure) or isinstance(obj, ClassMethod) or isinstance(obj, ClassStaticMethod):
         parameters = [self.type(p.type) for p in obj.parameters]
         if isinstance(obj, ClassMethod):
             parameters = parameters[1:]
         name = name.split('.')
         name[-1] = lower_camel_case(name[-1])+'('+', '.join(parameters)+')'
         name = '.'.join(name)
     elif isinstance(obj, Property) or isinstance(obj, ClassProperty):
         name = name.split('.')
         name[-1] = 'get'+name[-1]+'()'
         name = '.'.join(name)
     elif isinstance(obj, EnumerationValue):
         name = name.split('.')
         name[-1] = snake_case(name[-1]).upper()
         name = '.'.join(name)
     return self.shorten_ref(name)
Exemplo n.º 30
0
 def _parse_procedure(cls, procedure):
     param_names = [snake_case(param.name)
                    for param in procedure.parameters]
     param_types = [cls._client._types.as_type(param.type)
                    for param in procedure.parameters]
     param_required = [not param.default_value
                       for param in procedure.parameters]
     param_default = []
     for param, typ in zip(procedure.parameters, param_types):
         if param.default_value:
             param_default.append(Decoder.decode(param.default_value, typ))
         else:
             param_default.append(None)
     return_type = None
     if not Types.is_none_type(procedure.return_type):
         return_type = cls._client._types.as_type(procedure.return_type)
     return param_names, param_types, param_required, \
         param_default, return_type
Exemplo n.º 31
0
 def _add_service_property(cls, name, getter=None, setter=None):
     """ Add a property """
     doc = None
     if getter:
         doc = _parse_documentation(getter.documentation)
     elif setter:
         doc = _parse_documentation(setter.documentation)
     if getter:
         getter_name = getter.name
         _,_,_,_,return_type = cls._parse_procedure(getter)
         getter = _construct_func(cls._client._invoke, cls._name, getter_name, ['self'], [], [], [], [], return_type)
         build_request = _construct_func(cls._client._build_request, cls._name, getter_name, ['self'], [], [], [], [], return_type)
         setattr(getter, '_build_request', build_request)
         setattr(getter, '_return_type', return_type)
     if setter:
         param_names, param_types, _,_,_ = cls._parse_procedure(setter)
         setter = _construct_func(cls._client._invoke, cls._name, setter.name, ['self'], param_names, param_types, [True], [None], None)
     name = str(snake_case(name))
     return cls._add_property(name, getter, setter, doc=doc)
Exemplo n.º 32
0
 def _build_error(self, error):
     """ Build an exception from an error message that
         can be thrown to the calling code """
     # TODO: modify the stack trace of the thrown exception so it looks like
     #       it came from the local call
     if error.service and error.name:
         service_name = snake_case(error.service)
         type_name = error.name
         if not hasattr(self, service_name):
             raise RuntimeError(
                 'Error building exception; service \'%s\' not found' %
                 service_name)
         service = getattr(self, service_name)
         if not hasattr(service, type_name):
             raise RuntimeError(
                 'Error building exception; type \'%s.%s\' not found' %
                 (service_name, type_name))
         return getattr(service, type_name)(self._error_message(error))
     return RPCError(self._error_message(error))
Exemplo n.º 33
0
 def _parse_procedure(cls, procedure):
     param_names = [
         snake_case(param.name) for param in procedure.parameters
     ]
     param_types = [
         cls._client._types.as_type(param.type)
         for param in procedure.parameters
     ]
     param_required = [
         not param.default_value for param in procedure.parameters
     ]
     param_default = []
     for param, typ in zip(procedure.parameters, param_types):
         if param.default_value:
             param_default.append(Decoder.decode(param.default_value, typ))
         else:
             param_default.append(None)
     return_type = None
     if not Types.is_none_type(procedure.return_type):
         return_type = cls._client._types.as_type(procedure.return_type)
     return param_names, param_types, param_required, \
         param_default, return_type
Exemplo n.º 34
0
    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, snake_case(service.name), create_service(self, service))

        # Set up stream update thread
        if stream_connection is not None:
            self._stream_thread_stop = threading.Event()
            self._stream_thread = threading.Thread(target=krpc.stream.update_thread,
                                                   args=(stream_connection,self._stream_thread_stop))
            self._stream_thread.daemon = True
            self._stream_thread.start()
        else:
            self._stream_thread = None
Exemplo n.º 35
0
def _parse_documentation(xml):
    if xml.strip() == "":
        return ""
    parser = ElementTree.XMLParser(encoding="UTF-8")
    root = ElementTree.XML(xml.encode("UTF-8"), parser=parser)
    summary = ""
    params = []
    returns = ""
    note = ""
    for node in root:
        if node.tag == "summary":
            summary = _parse_documentation_content(node)
        elif node.tag == "param":
            doc = _parse_documentation_content(node).replace("\n", "")
            params.append("%s: %s" % (snake_case(node.attrib["name"]), doc))
        elif node.tag == "returns":
            returns = "Returns:\n    %s" % _parse_documentation_content(node).replace("\n", "")
        elif node.tag == "remarks":
            note = "Note: %s" % _parse_documentation_content(node)
    if len(params) > 0:
        params_str = "Args:\n%s" % "\n".join("    " + x for x in params)
    else:
        params_str = ""
    return "\n\n".join(x for x in (summary, params_str, returns, note) if x != "")
Exemplo n.º 36
0
 def parse_name(self, name):
     name = snake_case(name)
     if name in self._keywords:
         return '%s_' % name
     else:
         return name
Exemplo n.º 37
0
 def parse_param(self, node):
     return '\n:%s %s' % (snake_case(node.attrib['name']),
                          self.parse_node(node).strip())
Exemplo n.º 38
0
 def parse_name(self, name):
     name = snake_case(name)
     if name in self._keywords:
         return '%s_' % name
     else:
         return name
Exemplo n.º 39
0
 def parse_paramref(node):
     return snake_case(node.attrib['name'])
Exemplo n.º 40
0
 def method_name(self, name):
     if snake_case(name) in self._keywords:
         return '%s_' % name
     return name
Exemplo n.º 41
0
 def paramref(self, name):
     return super(CppDomain, self).paramref(snake_case(name))
Exemplo n.º 42
0
 def method_name(self, name):
     name = snake_case(name)
     if name in self.language.keywords:
         return '%s_' % name
     return name
Exemplo n.º 43
0
 def paramref(self, name):
     return super(PythonDomain, self).paramref(snake_case(name))
Exemplo n.º 44
0
def _member_name(name):
    return str(_update_names(snake_case(name))[0])
Exemplo n.º 45
0
 def method_name(self, name):
     name = snake_case(name)
     if name in self.language.keywords:
         return '%s_' % name
     return name
Exemplo n.º 46
0
 def parse_const_name(name):
     return snake_case(name).upper()
Exemplo n.º 47
0
Arquivo: cpp.py Projeto: Loran425/krpc
 def parse_name(self, name):
     return super(CppLanguage, self).parse_name(snake_case(name))
Exemplo n.º 48
0
 def parse_const_name(name):
     return snake_case(name).upper()
Exemplo n.º 49
0
def _member_name(name):
    return str(_update_names(snake_case(name))[0])
Exemplo n.º 50
0
 def parse_name(self, name):
     return super(CppLanguage, self).parse_name(snake_case(name))