예제 #1
0
 def decode_resource(self, type_name):
     with open(os.path.join(self._path, u'Resources', type_name + u'.json')) as f:
         data = json.load(f)
         if data[u'kind'] == u'Resource':
             res = Resource(data[u'name'], data[u'description'])
             for method in data[u'methods']:
                 res.add_method(self._decode_method(method))
             return res
예제 #2
0
    def decode_resource(self, name):
        resource = Resource(name, u'')
        with open(os.path.join(self._path, u'Methods', name + u'.json')) as f:
            data = json.load(f)

            for method_name in data:
                method_data = data[method_name]
                fields = method_data.get(ImplMethodAttributes.FIELDS, {})
                fields_validation = method_data.get(
                    ImplMethodAttributes.FIELDS_VALIDATION, {})
                private_fields = method_data.get(
                    ImplMethodAttributes.PRIVATE_FIELDS, {})
                fields_descriptions = method_data.get(ImplResourceAttributes.FIELD_DESCRIPTION, {})

                method = ImplMethod(method_name)
                method.frequency = method_data.get(ImplMethodAttributes.FREQUENCY, None)
                method.auth_required = not method_data.get(ImplMethodAttributes.NO_AUTH_REQUIRED, False)
                method.is_private = method_data.get(ImplMethodAttributes.PRIVATE, False)
                method.request_limit = method_data.get(ImplMethodAttributes.REQUEST_LIMIT, None)
                method.request_limit = method_data.get(ImplMethodAttributes.TIME_LIMIT, None)
                method.result_type_name = deserialize.SchemaDeserializer._decode_type_string(
                    method_data.get(ImplResourceAttributes.RESULT_TYPE, None))
                method.deprecated = method_data.get(ImplResourceAttributes.DEPRECATED, False)
                method.description = method_data.get(ImplResourceAttributes.DESCRIPTION, '')

                for perm in self._decode_permissions(name, method_name):
                    method.add_permission(perm)

                resource.add_method(method)

                for field_name in fields:
                    field = Deserializer._decode_field(
                        field_name,
                        fields[field_name],
                        fields_descriptions.get(field_name, ''))

                    method.add_field(field)

                for field_name in private_fields:
                    field = Deserializer._decode_field(
                        field_name,
                        private_fields[field_name],
                        fields_descriptions.get(field_name, ''))

                    method.add_private_field(field)

                for query_name in fields_validation:
                    query_data = fields_validation[query_name]
                    for field_name in query_data:
                        field = Deserializer._decode_field(
                            field_name,
                            query_data[field_name],
                            '')

                        method.add_query_field(query_name, field)

        return resource
예제 #3
0
def populate_resource(reg, node):
    res = Resource(get_complex_type_name(node),
                   get_resource_description(node))

    for ch in node.children:
        method = get_method(ch)
        res.add_method(method)

    reg.add_type(res)