• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python webapp.mightNotFound函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中webapp.mightNotFound函数的典型用法代码示例。如果您正苦于以下问题:Python mightNotFound函数的具体用法?Python mightNotFound怎么用?Python mightNotFound使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: DELETE

 def DELETE(self, map_name, l_name, s_name, format):
     mf = get_mapfile(map_name)
     with webapp.mightNotFound("layer", mapfile=map_name):
         layer = mf.get_layer(l_name)
     with webapp.mightNotFound("style", layer=l_name):
         layer.remove_style(s_name)
     mf.save()
开发者ID:juanluisrp,项目名称:mra,代码行数:7,代码来源:server.py


示例2: DELETE

    def DELETE(self, l_name, s_name, format):
        """Remove style <s> from layer <l>."""

        mf = mra.get_available()
        with webapp.mightNotFound():
            layer = mf.get_layer(l_name)
        with webapp.mightNotFound("style", layer=l_name):
            layer.remove_style(s_name)
        mf.save()
开发者ID:jivechang,项目名称:mra,代码行数:9,代码来源:server.py


示例3: GET

    def GET(self, map_name, ws_name, ds_name, ft_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        ds = ws.get_datastore(ds_name)
        with webapp.mightNotFound("dataStore", datastore=ds_name):
            dsft = ds[ft_name]

        with webapp.mightNotFound("featureType", datastore=ds_name):
            ft = ws.get_featuretypemodel(ft_name, ds_name)

        extent = ft.get_extent()
        latlon_extent = ft.get_latlon_extent()

        return {"featureType": ({
                    "name": ft.name,
                    "nativeName": ft.name,
                    "namespace": None, # TODO
                    "title": ft.get_mra_metadata("title", ft.name),
                    "abstract": ft.get_mra_metadata("abstract", None),
                    "keywords": ft.get_mra_metadata("keywords", []),
                    "srs": "%s:%s" % (ft.get_authority()[0], ft.get_authority()[1]),
                    "nativeCRS": ft.get_wkt(),
                    "attributes": [{
                            "name": f.get_name(),
                            "minOccurs": 0 if f.is_nullable() else 1,
                            "maxOccurs": 1,
                            "nillable": f.is_nullable(),
                            "binding": f.get_type_name(),
                            "length": f.get_width(),
                            } for f in dsft.iterfields()],
                    "nativeBoundingBox": {
                        "minx": extent.minX(),
                        "miny": extent.minY(),
                        "maxx": extent.maxX(),
                        "maxy": extent.maxY(),
                        "crs": "%s:%s" % (ft.get_authority_name(), ft.get_authority_code()),
                        },
                    "latLonBoundingBox": {
                        "minx": latlon_extent.minX(),
                        "miny": latlon_extent.minY(),
                        "maxx": latlon_extent.maxX(),
                        "maxy": latlon_extent.maxY(),
                        "crs": "EPSG:4326",
                        },
                    "projectionPolicy": None, # TODO
                    "enabled": True, # TODO
                    "store": { # TODO: add key: class="dataStore"
                        "name": ds_name,
                        "href": "%s/maps/%s/workspaces/%s/datastores/%s.%s" % (
                            web.ctx.home, map_name, ws_name, ds_name, format)
                        },
                    "maxFeatures": 0, # TODO
                    "numDecimals": 0, # TODO
                    })
                }
开发者ID:juanluisrp,项目名称:mra,代码行数:55,代码来源:server.py


示例4: PUT

    def PUT(self, l_name, format):
        """Modify layer <l>."""

        mf = mra.get_available()

        data = get_data(name="layer", mandatory=[],
                        authorized=["name", "title", "abstract", "resource", "enabled", "defaultStyle"])
        if l_name != data.get("name", l_name):
            raise webapp.Forbidden("Can't change the name of a layer.")

        l_enabled = data.pop("enabled", True)

        mf = mra.get_available()
        with webapp.mightNotFound():
            layer = mf.get_layer(l_name)

        # update resource if changed
        href = data.get("resource", {}).get("href")
        if href:
            try:
                ws_name, st_type, st_name, r_type, r_name = mra.href_parse(href, 5)
            except ValueError:
                raise webapp.NotFound(message="resource \"%s\" was not found." % href)

            st_type, r_type = st_type[:-1], r_type[:-1] # Remove trailing s.

            ws = get_workspace(ws_name)
            with webapp.mightNotFound(r_type, workspace=ws_name):
                try:
                    model = ws.get_layermodel(r_type, st_name, r_name)
                except ValueError:
                    raise KeyError(r_type)

            if layer.get_mra_metadata("type") != r_type:
                raise webapp.BadRequest("Can't change a \"%s\" layer into a \"%s\"."
                                    % (layer.get_mra_metadata("type"), r_type))

            model.configure_layer(layer, l_enabled)

        # If we have a defaultStyle apply it.
        s_name = data.get("defaultStyle", {}).get("name")
        if s_name:
            with webapp.mightNotFound():
                style = mra.get_style(s_name)
            layer.add_style_sld(mf, s_name, style)
            
            # Remove the automatic default style.
            for s_name in layer.iter_styles():
                if s_name == tools.get_dflt_sld_name(layer.ms.type):
                    layer.remove_style(s_name)

        mf.save()
开发者ID:4g0st1n0,项目名称:mra,代码行数:52,代码来源:server.py


示例5: POST

    def POST(self, map_name, l_name, format):
        data = get_data(name="style", mandatory=["resource"],
                        authorized=["name", "title", "abstract", "resource"])

        url = urlparse.urlparse(data["resource"]["href"])
        if url.path.startswith(web.ctx.homepath):
            path = url.path[len(web.ctx.homepath):]
        else:
            raise webapp.BadRequest(message="Resource href (%s) is not handled by MRA." % url.path)

        try:
            _, map_name, _, s_name = path.rsplit("/", 3)
        except ValueError:
            raise webapp.NotFound(message="ressource '%s' was not found." % path)

        s_name = s_name.rsplit(".", 1)[0]

        # Get the new style.
        mf = get_mapfile(map_name)

        try:
            style = open(tools.get_style_path(s_name)).read()
        except IOError, OSError:
            with webapp.mightNotFound("style", mapfile=map_name):
                style = mf.get_style_sld(s_name)
开发者ID:juanluisrp,项目名称:mra,代码行数:25,代码来源:server.py


示例6: GET

    def GET(self, l_name, format):
        mf = mra.get_available()
        with webapp.mightNotFound():
            layer = mf.get_layer(l_name)

        if layer.get_type_name() == "RASTER":
            return {"fields": []}

        fields = [{
            "name": layer.get_metadata("gml_%s_alias" % field, None),
            "type": layer.get_metadata("gml_%s_type" % field, None),
            } for field in layer.iter_fields()]

        geom = layer.get_metadata("gml_geometries", False)
        if geom:
            type = layer.get_metadata("gml_%s_type" % geom, "undefined")
            occurs = layer.get_metadata("gml_%s_occurances" % geom, "0,1").split(",")
            min_occurs, max_occurs = int(occurs[0]), int(occurs[1])
        else:
            geom, type, min_occurs, max_occurs = "undefined", "undefined", 0, 1
        
        fields.append({
            "name": geom,
            "type": type,
            "minOccurs": min_occurs,
            "maxOccurs": max_occurs,
            })

        return {"fields": fields}
开发者ID:jivechang,项目名称:mra,代码行数:29,代码来源:server.py


示例7: PUT

    def PUT(self, s_name, format):
        """Modify style <s>."""

        # TODO: Also update layers using this style.
        with webapp.mightNotFound(message="Style \"%s\" does not exist." % s_name):
            mra.delete_style(s_name)
        data = web.data()
        mra.create_style(s_name, data)
开发者ID:jivechang,项目名称:mra,代码行数:8,代码来源:server.py


示例8: POST

    def POST(self, format):
        """Create a new layer."""

        data = get_data(name="layer",
                        mandatory=["name", "resource"],
                        authorized=["name", "title", "abstract", "resource", "enabled", "defaultStyle"])

        l_name = data.pop("name")
        l_enabled = data.pop("enabled", True)

        href = data["resource"]["href"]
        try:
            ws_name, st_type, st_name, r_type, r_name = mra.href_parse(href, 5)
        except ValueError:
            raise webapp.NotFound(message="resource \"%s\" was not found." % href)

        st_type, r_type = st_type[:-1], r_type[:-1] # Remove trailing s.

        ws = get_workspace(ws_name)
        with webapp.mightNotFound(r_type, workspace=ws_name):
            try:
                model = ws.get_layermodel(r_type, st_name, r_name)
            except ValueError:
                raise KeyError(r_type)

        mf = mra.get_available()
        with webapp.mightConflict():
            mf.create_layer(model, l_name, l_enabled)

        # If we have a defaultStyle apply it.
        s_name = data.get("defaultStyle", {}).get("name")
        if s_name:
            with webapp.mightNotFound():
                style = mra.get_style(s_name)
                layer = mf.get_layer(l_name)
            layer.add_style_sld(mf, s_name, style)

            # Remove the automatic default style.
            for s_name in layer.iter_styles():
                if s_name == tools.get_dflt_sld_name(layer.ms.type):
                    layer.remove_style(s_name)

        mf.save()

        webapp.Created("%s/layers/%s.%s" % (web.ctx.home, l_name, format))
开发者ID:jivechang,项目名称:mra,代码行数:45,代码来源:server.py


示例9: PUT

    def PUT(self, map_name, ws_name, st_type, st_name, f_type, format):
        import zipfile

        mf, ws = get_mapfile_workspace(map_name, ws_name)

        # TODO: According to geoserv's examples we might have to handle
        # directories as well as files, in that case we want to upload
        # all the files from the directory.

        # Lets first try to get the file.
        if f_type == "file":
            # Check if zip or not...
            data = web.data()
        elif f_type == "url":
            raise NotImplemented()
        elif f_type == "external":
            raise NotImplemented()

        # Now we make sure the store exists.
        with webapp.mightNotFound(message="Store {exception} does not exist "
                                  "and automatic creation is not yet suported."):
            ws.get_store_info(st_type, st_name)
            # TODO: Create the store if it does not exist.

        # Then we store the file.
        ext = web.ctx.env.get('CONTENT_TYPE', '').split("/")[-1]
        path = tools.mk_st_data_path(ws_name, st_type, st_name, st_name + (".%s" % ext) if ext else "")
        with open(path, "w") as f:
            f.write(data)

        # We also unzip it if its ziped.
        ctype = web.ctx.env.get('CONTENT_TYPE', None)
        if ctype == "application/zip":
            z = zipfile.ZipFile(path)
            for f in z.namelist():
                fp = tools.mk_st_data_path(ws_name, st_type, st_name, f)

                # If the file has the correct target we might want it.
                if format and fp.endswith(format) and not tools.is_hidden(fp):
                    path = fp

                z.extract(f, path=tools.get_st_data_path(ws_name, st_type, st_name))

        # Set new connection parameters:
        ws.update_store(st_type, st_name, {"connectionParameters":{"url":"file:"+tools.no_res_root(path)}})
        ws.save()

        # Finally we might have to configure it.
        params = web.input(configure="none")
        if params.configure == "first":
            raise NotImplemented()
        elif params.configure == "none":
            pass
        elif params.configure == "all":
            raise NotImplemented()
        else:
            raise webapp.BadRequest(message="configure must be one of first, none or all.")
开发者ID:juanluisrp,项目名称:mra,代码行数:57,代码来源:server.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python app.run函数代码示例发布时间:2022-05-26
下一篇:
Python config.get函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap