當前位置: 首頁>>代碼示例>>Python>>正文


Python Attributes.get_class_method_name方法代碼示例

本文整理匯總了Python中krpc.attributes.Attributes.get_class_method_name方法的典型用法代碼示例。如果您正苦於以下問題:Python Attributes.get_class_method_name方法的具體用法?Python Attributes.get_class_method_name怎麽用?Python Attributes.get_class_method_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在krpc.attributes.Attributes的用法示例。


在下文中一共展示了Attributes.get_class_method_name方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_service

# 需要導入模塊: from krpc.attributes import Attributes [as 別名]
# 或者: from krpc.attributes.Attributes import get_class_method_name [as 別名]
def create_service(client, service):
    """ Create a new service type """
    cls = type(str(service.name), (ServiceBase,), {'_client': client, '_name': service.name})

    # 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()
開發者ID:602p,項目名稱:krpc,代碼行數:60,代碼來源:service.py

示例2: test_get_class_method_name

# 需要導入模塊: from krpc.attributes import Attributes [as 別名]
# 或者: from krpc.attributes.Attributes import get_class_method_name [as 別名]
 def test_get_class_method_name(self):
     self.assertRaises(ValueError, Attributes.get_class_method_name, [])
     self.assertRaises(
         ValueError, Attributes.get_class_method_name,
         ['Property.Get(PropertyName)'])
     self.assertRaises(
         ValueError, Attributes.get_class_method_name,
         ['Property.Set(PropertyName)'])
     self.assertEqual('MethodName', Attributes.get_class_method_name(
         ['Class.Method(ServiceName.ClassName,MethodName)']))
     self.assertEqual('MethodName', Attributes.get_class_method_name(
         ['Class.StaticMethod(ServiceName.ClassName,MethodName)']))
     self.assertRaises(
         ValueError, Attributes.get_class_method_name,
         ['Class.Property.Get(ServiceName.ClassName,PropertyName)'])
     self.assertRaises(
         ValueError, Attributes.get_class_method_name,
         ['Class.Property.Set(ServiceName.ClassName,PropertyName)'])
開發者ID:paperclip,項目名稱:krpc,代碼行數:20,代碼來源:test_attributes.py

示例3: __init__

# 需要導入模塊: from krpc.attributes import Attributes [as 別名]
# 或者: from krpc.attributes.Attributes import get_class_method_name [as 別名]
 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)
開發者ID:Kerbal007,項目名稱:krpc,代碼行數:17,代碼來源:nodes.py

示例4: generate_context

# 需要導入模塊: from krpc.attributes import Attributes [as 別名]
# 或者: from krpc.attributes.Attributes import get_class_method_name [as 別名]
    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
                }

#.........這裏部分代碼省略.........
開發者ID:Kerbal007,項目名稱:krpc,代碼行數:103,代碼來源:generator.py

示例5: generate_context

# 需要導入模塊: from krpc.attributes import Attributes [as 別名]
# 或者: from krpc.attributes.Attributes import get_class_method_name [as 別名]
    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"]))
#.........這裏部分代碼省略.........
開發者ID:artwhaley,項目名稱:krpc,代碼行數:103,代碼來源:generator.py


注:本文中的krpc.attributes.Attributes.get_class_method_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。