当前位置: 首页>>代码示例>>Python>>正文


Python restful.Resource方法代码示例

本文整理汇总了Python中flask.ext.restful.Resource方法的典型用法代码示例。如果您正苦于以下问题:Python restful.Resource方法的具体用法?Python restful.Resource怎么用?Python restful.Resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.ext.restful的用法示例。


在下文中一共展示了restful.Resource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_template_endpoints

# 需要导入模块: from flask.ext import restful [as 别名]
# 或者: from flask.ext.restful import Resource [as 别名]
def add_template_endpoints(api, adapter):

    class Template(Resource):

        def get(self, lm_id):
            err = "{} template does not exist".format(lm_id)
            return safe_send(adapter.load_template(lm_id), err)

    class TemplateList(Resource):

        def get(self):
            return adapter.template_ids()

    templates_url = partial(url, Endpoints.templates)
    api.add_resource(TemplateList, templates_url())
    api.add_resource(Template, templates_url('<string:lm_id>')) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:18,代码来源:server.py

示例2: add_collection_endpoints

# 需要导入模块: from flask.ext import restful [as 别名]
# 或者: from flask.ext.restful import Resource [as 别名]
def add_collection_endpoints(api, adapter):

    class Collection(Resource):

        def get(self, collection_id):
            err = "{} collection not exist".format(collection_id)
            return safe_send(adapter.collection(collection_id), err)

    class CollectionList(Resource):

        def get(self):
            return adapter.collection_ids()

    collections_url = partial(url, Endpoints.collections)
    api.add_resource(CollectionList, collections_url())
    api.add_resource(Collection, collections_url('<string:collection_id>')) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:18,代码来源:server.py

示例3: add_mode_endpoint

# 需要导入模块: from flask.ext import restful [as 别名]
# 或者: from flask.ext.restful import Resource [as 别名]
def add_mode_endpoint(api, mode):

    if mode not in ['image', 'mesh']:
        raise ValueError("Mode can only be 'image' or 'mesh', "
                         "not {}".format(mode))

    class Mode(Resource):

        def get(self):
            return mode

    api.add_resource(Mode, url(Endpoints.mode)) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:14,代码来源:server.py

示例4: add_image_endpoints

# 需要导入模块: from flask.ext import restful [as 别名]
# 或者: from flask.ext.restful import Resource [as 别名]
def add_image_endpoints(api, adapter):
    r"""
    Generate a Flask App that will serve images, landmarks and templates to
    landmarker.io

    Parameters
    ----------

    adapter: :class:`ImageLandmarkerIOAdapter`
        Concrete implementation of the Image adapter. Will be queried for
        all data to pass to landmarker.io.

    """

    class ImageList(Resource):

        def get(self):
            return adapter.asset_ids()

    class Texture(Resource):

        def get(self, asset_id):
            err = "{} does not have a texture".format(asset_id)
            return image_file(adapter.texture_file(asset_id), err)

    class Thumbnail(Resource):

        def get(self, asset_id):
            err = "{} does not have a thumbnail".format(asset_id)
            return image_file(adapter.thumbnail_file(asset_id), err)

    image_url = partial(url, Endpoints.images)
    texture_url = partial(url, Endpoints.textures)
    thumbnail_url = partial(url, Endpoints.thumbnail)

    api.add_resource(ImageList, image_url())

    api.add_resource(Texture, asset(texture_url)())
    api.add_resource(Thumbnail, asset(thumbnail_url)()) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:41,代码来源:server.py

示例5: add_lm_endpoints

# 需要导入模块: from flask.ext import restful [as 别名]
# 或者: from flask.ext.restful import Resource [as 别名]
def add_lm_endpoints(api, lm_adapter, template_adapter):
    r"""
    Generate a Flask App that will serve meshes landmarks and templates to
    landmarker.io

    Parameters
    ----------
    adapter: :class:`LandmarkerIOAdapter`
        Concrete implementation of the LandmarkerIOAdapter. Will be queried for
        all data to pass to landmarker.io.
    dev: `bool`, optional
        If True, listen to anyone for CORS.

    Returns
    -------
    api, app, api_endpoint
    """

    class Landmark(Resource):

        def get(self, asset_id, lm_id):
            err = "{} does not have {} landmarks".format(asset_id, lm_id)
            try:
                return lm_adapter.load_lm(asset_id, lm_id)
            except Exception as e:
                try:
                    return template_adapter.load_template(lm_id)
                except Exception as e:
                    return abort(404, message=err)

        def put(self, asset_id, lm_id):
            try:
                return lm_adapter.save_lm(asset_id, lm_id, request.json)
            except Exception as e:
                print(e)
                return abort(409, message="{}:{} unable to "
                                          "save".format(asset_id, lm_id))

        # Need this here to enable CORS put see http://mzl.la/1rCDkWX
        def options(self, asset_id, lm_id):
            pass

    class LandmarkList(Resource):

        def get(self):
            return lm_adapter.asset_id_to_lm_id()

    class LandmarkListForId(Resource):

        def get(self, asset_id):
            return lm_adapter.lm_ids(asset_id)

    lm_url = partial(url, Endpoints.landmarks)
    api.add_resource(LandmarkList, lm_url())
    api.add_resource(LandmarkListForId, asset(lm_url)())
    api.add_resource(Landmark, asset(lm_url)('<string:lm_id>')) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:58,代码来源:server.py


注:本文中的flask.ext.restful.Resource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。