Пример #1
0
def resolve(path):
    routes = import_routes()
    index = path[1:]
    if index in routes:
        config = routes[index]
        logic = str_to_logic(config['controller'])
        return Response(200, 'text/html', logic())
    return Response(404, 'text/html', '')
Пример #2
0
def generate_response(path):
    file_list = list_tree('./happy/public')
    for key, abs_path in enumerate(file_list):
        # cut out 'public/' from paths
        file_list[key] = abs_path.replace('public/', '')

    if has_file_ending(path) and path in file_list:
        file_path = path.split('.')
        file_ending = file_path[-1]
        images = ['ico', 'png', 'gif', 'jpg']
        others = ['html', 'css']
        if file_ending in images:
            content_type = 'image/' + file_ending
        elif file_ending in others:
            content_type = 'text/' + file_ending
        response_code = 200
        public_path = path.replace('/happy/', 'happy/public/')
        with open(public_path) as f:
            response_body = f.read()
        return Response(response_code, content_type, response_body)
    if path == '/':
        path = '/homepage'
    return resolve(path)
Пример #3
0
 def GetCapabilities(self, params):
     response = Response('application/vnd.ogc.wms_xml', self.capabilities)
     return response
Пример #4
0
 def GetCapabilities(self, params):
     response = Response('text/xml', self.capabilities)
     return response
Пример #5
0
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)

            elements = capetree.findall('Capability//OnlineResource')
            for element in elements:
                element.set('{http://www.w3.org/1999/xlink}href',
                            self.opsonlineresource)

            self.processServiceCapabilities(capetree)

            rootlayerelem = capetree.find(
                '{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer'
            )

            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('SRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)

            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('Name')
                layername.text = layer.name
                env = layer.envelope()
                llp = layerproj.inverse(Coord(env.minx, env.miny))
                urp = layerproj.inverse(Coord(env.maxx, env.maxy))
                latlonbb = ElementTree.Element('LatLonBoundingBox')
                latlonbb.set('minx', str(llp.x))
                latlonbb.set('miny', str(llp.y))
                latlonbb.set('maxx', str(urp.x))
                latlonbb.set('maxy', str(urp.y))
                layerbbox = ElementTree.Element('BoundingBox')
                layerbbox.set('SRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('Layer')
                layere.append(layername)
                if layer.title:
                    layertitle = ElementTree.Element('Title')
                    layertitle.text = layer.title
                    layere.append(layertitle)
                if layer.abstract:
                    layerabstract = ElementTree.Element('Abstract')
                    layerabstract.text = layer.abstract
                    layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(latlonbb)
                layere.append(layerbbox)
                if len(layer.wmsextrastyles) > 0:
                    for extrastyle in [layer.wmsdefaultstyle] + list(
                            layer.wmsextrastyles):
                        style = ElementTree.Element('Style')
                        stylename = ElementTree.Element('Name')
                        stylename.text = extrastyle
                        styletitle = ElementTree.Element('Title')
                        styletitle.text = extrastyle
                        style.append(stylename)
                        style.append(styletitle)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + ElementTree.tostring(
                capetree)
        response = Response('application/vnd.ogc.wms_xml', self.capabilities)
        return response