Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_wps_process_with_invalid_identifer():
p = Process(etree.Element('invalid'))
assert repr(p) == ''
assert str(p) == 'WPS Process: , title='
if elem.tag[0] == "{":
uri, tag = elem.tag[1:].split("}")
existing_namespaces.add(namespaces.get_namespace_from_url(uri))
for key, link in ns_keys:
if link is not None and key not in existing_namespaces:
root.set("xmlns:%s" % key, link)
return root
else:
# lxml does not support setting xmlns attributes
# Update the elements nsmap with new namespaces
new_map = root.nsmap
for key, link in ns_keys:
if link is not None:
new_map[key] = link
# Recreate the root element with updated nsmap
new_root = etree.Element(root.tag, nsmap=new_map)
# Carry over attributes
for a, v in list(root.items()):
new_root.set(a, v)
# Carry over children
for child in root:
new_root.append(deepcopy(child))
return new_root
def axml_category(d):
#
if is_empty(d):
return None
else:
try:
category = etree.Element("category", nsmap=ns)
term = extract_p('term', d, None)
if term is not None: category.set("term", term)
scheme = extract_p('scheme', d, None)
if scheme is not None: category.set("scheme", scheme)
label = extract_p('label', d, None)
if label is not None: category.set("label", label)
return category
except Exception as ex:
log.warn('could encode category', ex)
return None
def axml_styleset(d):
#
# raster
# Default Raster
# A sample style that draws a
#
#
if is_empty(d):
return None
else:
try:
styleset = etree.Element(ns_elem("owc", "styleSet"), nsmap=ns)
name = extract_p('name', d, None)
if name is not None: etree.SubElement(styleset, ns_elem("owc", "name")).text = name
title = extract_p('title', d, None)
if title is not None: etree.SubElement(styleset, ns_elem("owc", "title")).text = title
subtitle = extract_p('abstract', d, None)
if subtitle is not None: etree.SubElement(styleset, ns_elem("owc", "abstract")).text = subtitle
is_default = extract_p('default', d, None)
# TODO no example for default setting on style set
if is_default is not None: etree.SubElement(styleset, ns_elem("owc", "default")).text = is_default
legend_url = extract_p('legendURL', d, None)
if legend_url is not None: etree.SubElement(styleset, ns_elem("owc", "legendURL")).text = legend_url
# TODO no example for content on style set
content = extract_p('content', d, None)
content_enc = None if content is None else axml_content(content)
if content_enc is not None: styleset.append(content_enc)
def axml_creator_app(d):
# MiraMon
if is_empty(d):
return None
else:
try:
creator_app = etree.Element("generator", nsmap=ns)
title = extract_p('title', d, None)
if title is not None: creator_app.text = title
uri = extract_p('uri', d, None)
if uri is not None: creator_app.set("uri", uri)
version = extract_p('version', d, None)
if version is not None: creator_app.set("version", version)
return creator_app
except Exception as ex:
log.warn('could encode creator_app', ex)
return None
def axml_operation(d):
# ..
# etree.SubElement(entry, ns_elem("owc", "offering"), name="blah").text = "some value1"
if is_empty(d):
return None
else:
try:
operation = etree.Element(ns_elem("owc", "operation"), nsmap=ns)
operations_code = extract_p('code', d, None)
if operations_code is not None: operation.set("code", operations_code)
http_method = extract_p('method', d, None)
if http_method is not None: operation.set("method", http_method)
mimetype = extract_p('type', d, None)
if mimetype is not None: operation.set("type", mimetype)
request_url = extract_p('href', d, None)
if request_url is not None: operation.set("href", request_url)
# use axml_content here
request = extract_p('request', d, None)
request_enc = None if request is None else axml_content(request)
if request_enc is not None: operation.append(request_enc)
# use axml_content here
result = extract_p('result', d, None)
def getXml(self):
root = etree.Element(nspath_eval('wps:Reference', namespaces),
attrib={nspath_eval("xlink:href", namespaces): self.url})
if self.method:
root.attrib['method'] = self.method
bodyElement = etree.SubElement(
root, nspath_eval('wps:Body', namespaces))
getFeatureElement = etree.SubElement(
bodyElement, nspath_eval('wfs:GetFeature', namespaces),
attrib={"service": "WFS",
"version": "1.1.0",
"outputFormat": "text/xml; subtype=gml/3.1.1",
nspath_eval("xsi:schemaLocation", namespaces): "%s %s" % (namespaces['wfs'], WFS_SCHEMA_LOCATION)})
#
# the_geom
# STATE
#
def toXML(self):
node0 = etree.Element(util.nspath_eval('ogc:PropertyIsLike', namespaces))
node0.set('wildCard', self.wildCard)
node0.set('singleChar', self.singleChar)
node0.set('escapeChar', self.escapeChar)
if not self.matchCase:
node0.set('matchCase', 'false')
etree.SubElement(node0, util.nspath_eval('ogc:PropertyName', namespaces)).text = self.propertyname
etree.SubElement(node0, util.nspath_eval('ogc:Literal', namespaces)).text = self.literal
return node0
def _setrootelement(self, el):
if etree.__name__ == 'lxml.etree': # apply nsmap
return etree.Element(util.nspath_eval(el, namespaces), nsmap=namespaces)
else:
return etree.Element(util.nspath_eval(el, namespaces))