當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。