def parse(xml) -> core.Caps: root_el = xml2.from_string(xml, strip_ns=True) source_layers = gws.gis.source.check_layers( _layer(e) for e in xml2.all(root_el, 'Capability Layer')) return core.Caps( metadata=u.service_metadata(root_el), operations=u.service_operations(root_el), source_layers=source_layers, version=xml2.attr(root_el, 'version'))
def parse(xml): root_el = xml2.from_string(xml, strip_ns=True) tile_matrix_sets = [ _tile_matrix_set(e) for e in xml2.all(root_el, 'Contents TileMatrixSet') ] tms_map = {tms.uid: tms for tms in tile_matrix_sets} source_layers = gws.gis.source.check_layers( _layer(e, tms_map) for e in xml2.all(root_el, 'Contents Layer')) return Caps(tile_matrix_sets=tile_matrix_sets, metadata=u.service_metadata(root_el), operations=u.service_operations(root_el), source_layers=source_layers, version=xml2.attr(root_el, 'version'))
def _parse_svg(val): try: el = xml2.from_string(val) except Exception as exc: raise Error('parse error', val) from exc el_clean = gws.lib.svg.sanitize_element(el) w = xml2.attr(el_clean, 'width') h = xml2.attr(el_clean, 'height') if not w or not h: raise Error('missing width or height', val) return el_clean
def _parse(text, fallback_crs, **kwargs): try: xml_el = xml2.from_string(text, strip_ns=True) except xml2.Error: xml_el = None if xml_el: for fn in _XML_FORMATS: features = fn(xml_el, fallback_crs, **kwargs) if features is not None: gws.log.debug( f'parsed with {fn.__name__} count={len(features)}') return features # fallback for non-xml formats for fn in _TEXT_FORMATS: features = fn(text, fallback_crs, **kwargs) if features is not None: gws.log.debug(f'parsed with {fn.__name__} count={len(features)}') return features
def handle_request(self, req: gws.IWebRequest) -> gws.ContentResponse: rd = core.Request(req=req, project=None, service=self) if req.method == 'GET': return self.dispatch_request( rd, req.param('request', default='record')) # CSW should accept POST'ed xml, which can be wrapped in a SOAP envelope try: rd.xml_element = xml2.from_string(req.text) except xml2.Error: raise gws.base.web.error.BadRequest() if rd.xml_element.name.lower() == 'envelope': rd.xml_is_soap = True try: rd.xml_element = xml2.first(xml2.first('body')) except Exception: raise gws.base.web.error.BadRequest() return self.dispatch_request( rd, xml2.unqualify_name(rd.xml_element.name.lower()))
def parse(xml: str) -> Caps: root_el = xml2.from_string(xml, sort_atts=True, strip_ns=True, to_lower=True) ver = root_el.attributes.get('version', '').split('-')[0] if not ver.startswith('3'): raise gws.Error(f'unsupported QGIS version {ver!r}') caps = Caps(version=ver) caps.properties = _properties(xml2.first(root_el, 'properties')) caps.metadata = _project_meta_from_props(caps.properties) caps.project_crs = gws.gis.crs.get( xml2.text(root_el, 'projectCrs spatialrefsys authid')) caps.print_templates = _layouts(root_el) map_layers = _map_layers(root_el, caps.properties) root_group = _map_layer_tree(xml2.first(root_el, 'layer-tree-group'), map_layers) caps.source_layers = gws.gis.source.check_layers(root_group.layers) return caps
def from_fes_string(src: str) -> gws.SearchFilter: try: el = xml2.from_string(src) except Exception as exc: raise Error('invalid XML') from exc return from_fes_element(el)