Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_equivalent_sites(tile_xml, equivalent_sites):
""" Used to add to the tag the equivalent tiles associated with it."""
pb_types = equivalent_sites.split(',')
equivalent_sites_xml = ET.SubElement(tile_xml, 'equivalent_sites')
for eq_site in pb_types:
eq_pb_type_xml = ET.parse(
"{}/{tile}/{tile}.pb_type.xml".format(
args.tiles_directory, tile=eq_site.lower()
)
)
pb_type_root = eq_pb_type_xml.getroot()
site_xml = ET.SubElement(
equivalent_sites_xml, 'site', {
'pb_type': tile_import.add_vpr_tile_prefix(eq_site),
'pin_mapping': 'custom'
}
)
cli.show_message(_("Delete old Kdenlive project file."))
except FileNotFoundError:
cli.show_message(_("No existing Kdenlive project file to remove."))
# add mediafiles
counter = 1
for f in sorted(glob.glob("*.MP4")):
# for f in sorted(os.listdir()):
newprod = etree.SubElement(self.root, "producer")
newprod.set("id", str(counter))
newprop = etree.SubElement(newprod, "property")
newprop.text = os.path.join(folder, f)
newprop.set("name", "resource")
# insert lines after root tag, otherwise kdenlive crashes at start
self.root.insert(0, newprod)
newentry = etree.SubElement(self.mainbin, "entry")
newentry.set("producer", str(counter))
counter += 1
# save as new file
self.tree.write("mlt-playlist.kdenlive")
cli.show_message(_("Open Kdenlive project"))
# open Kdenlive as separate thread to keep GPT responsive
thread = threading.Thread(target=self.openproject,
args=("kdenlive", "mlt-playlist.kdenlive"))
thread.start()
cli.workdir(self.wdir)
def getXML(self) :
# return lxml etree element
graphXML = etree.Element("graph",defaultedgetype=self.type,mode=self.mode,label=self.label,timeformat=self.time_format)
for attributesElement in self.attributes.getAttributesDeclarationXML() :
graphXML.append(attributesElement)
nodesXML = etree.SubElement(graphXML, "nodes")
node_ids=self._nodes.keys()
node_ids.sort()
for id in node_ids :
nodesXML.append(self._nodes[id].getXML())
edgesXML = etree.SubElement(graphXML, "edges")
edge_ids=self._edges.keys()
edge_ids.sort()
for id in edge_ids :
edgesXML.append(self._edges[id].getXML())
return graphXML
))
return
try:
parsed = etree.parse(xmp_file)
mapped = False
tags = parsed.xpath(xmp_mapping['xpath'], namespaces=xmp_mapping['namespaces'])
if tags:
tags[0].attrib[xmp_mapping['atribute_key']] = assignment_id
mapped = True
if not mapped:
parent_xpath = xmp_mapping['xpath'][0: xmp_mapping['xpath'].rfind('/')]
parent = parsed.xpath(parent_xpath, namespaces=xmp_mapping['namespaces'])
if parent:
elem = etree.SubElement(parent[0], "{{{0}}}Description".format(xmp_mapping['namespaces']['rdf']),
nsmap=xmp_mapping['namespaces'])
elem.attrib[xmp_mapping['atribute_key']] = assignment_id
else:
logger.error('Cannot find xmp_mapping path in XMP file for assignment: {}'.format(assignment_id))
return
buf = BytesIO()
buf.write(etree.tostring(parsed.getroot(), pretty_print=True))
buf.seek(0)
media_id = app.media.put(buf, resource='planning_files', filename=xmp_file.filename,
content_type='application/octet-stream')
get_resource_service('planning_files').patch(updates_coverage['planning']['xmp_file'],
{
'filemeta': {'media_id': media_id},
'media': media_id})
push_notification('planning_files:updated', item=updates_coverage['planning']['xmp_file'])
cord = et.SubElement(datarecord,"{%s}field" % ns["swe"])
cord.attrib["name"] = "y"
quantity = et.SubElement(cord,"{%s}Quantity" % ns["swe"])
quantity.attrib["definition"] = sosConfig.urn["refsystem"] + sosConfig.istsosepsg + ":y-position"
cord = et.SubElement(datarecord,"{%s}field" % ns["swe"])
cord.attrib["name"] = "z"
quantity = et.SubElement(cord,"{%s}Quantity" % ns["swe"])
quantity.attrib["definition"] = sosConfig.urn["refsystem"] + sosConfig.istsosepsg + ":z-position"
for index, field in enumerate(DS.observedProperties):
fieldQ = et.SubElement(datarecord,"{%s}field" % ns["swe"])
fieldQ.attrib["name"] = field["name_opr"]
quantity = et.SubElement(fieldQ,"{%s}Quantity" % ns["swe"])
quantity.attrib["definition"] = field["def_opr"]
if not (field["name_uom"]=="" or field["name_uom"]==None or field["name_uom"]=="NULL"):
uom = et.SubElement(quantity,"{%s}uom" % ns["swe"])
uom.attrib["code"] = field["name_uom"]
"""
if not (field["desc_opr"]=="" or field["desc_opr"]==None or field["desc_opr"]=="NULL"):
description = et.SubElement(quantity,"{%s}description" % ns["swe"])
description.text = field["desc_opr"]
"""
"""
# Handling constraint
Permitted conigurations:
{"role":"urn:ogc:def:classifiers:x-istsos:1.0:qualityIndex:check:reasonable","min":"10"}
{"role":"urn:ogc:def:classifiers:x-istsos:1.0:qualityIndex:check:reasonable","max":"10"}
global_root = etree.Element("sdf", version="1.5")
world_object = etree.Element("world", name=world_name)
global_root.append(world_object);
model_object = etree.Element("model", name=robot_name)
world_object.append(model_object)
etree.SubElement(model_object, "static").text = "false"
etree.SubElement(model_object, "pose").text = "0 0 0 0 0 0"
etree.SubElement(model_object, "plugin", name="Model_Vel",
filename="libmodel_vel.so")
#world_object.append(createFloor())
include_floor = etree.SubElement(world_object, "include")
etree.SubElement(include_floor, "uri").text = "model://ground_plane"
include_sun = etree.SubElement(world_object, "include")
etree.SubElement(include_sun, "uri").text = "model://sun"
#Sorts them in the correct order
#operation.connections.sort(key=lambda tup: tup[0], reverse=True)
ordered_connection = [reorder_pair(connection[1], operation.get_laminate_generations())
for connection in operation.connections]
tree = tree_node.spawnTreefromList(ordered_connection, sort=True)
assert(len(tree.decendents) == len(operation.bodies_generic) - 1)
midpoints = [connect[0] for connect in operation.connections]
print(midpoints)
#This key function tells it to ignore the following special characters when sorting.
link_sort = lambda string: str(string).replace('|', '\x02').replace('*','\x01')
counter = 0
def toxml(self, rootElement , rootNs):
root = ElementTree.Element("{" + rootNs + "}" + rootElement)
address = ElementTree.SubElement(root, "{" + NS_WS_ADDRESSING + "}Address")
address.text = self._Address
param = ElementTree.SubElement(root, "{" + NS_WS_ADDRESSING + "}ReferenceParameters")
ruri = ElementTree.SubElement(param, "{" + NS_WS_MANAGEMENT + "}ResourceURI")
ruri.text = self._ReferenceParameters._resource_uri
sset = ElementTree.SubElement(param, "{" + NS_WS_MANAGEMENT + "}SelectorSet")
selectors = self._ReferenceParameters._selector_set
for selector in selectors.keys():
s = ElementTree.SubElement(sset, "{" + NS_WS_MANAGEMENT + "}Selector")
s.set("Name", selector)
s.text = selectors[selector]
return root
def dict2xmlPayloadBlock(dict, node, privkey=None, pubkey=None):
pb = etree.SubElement(node, '{%s}Payload_Block' % ns_dict['taxii'])
pb_bind = etree.SubElement(pb, '{%s}Payload_Binding' % ns_dict['taxii'])
pb_bind.text = dict['payload_binding']
pb_payload = etree.SubElement(pb, '{%s}Payload' % ns_dict['taxii'])
if pubkey:
if privkey:
payload_structure = decrypt_payload(str2xml(dict['payload']), privkey, pubkey)
else:
payload_structure = encrypt_payload(str(dict['payload']), pubkey)
pb_payload.text = payload_structure
else:
if dict['payload_binding'] == 'ENCRYPTED_PAYLOAD':
pb_payload.text = dict['payload']
else:
payload_structure = str2xml(dict['payload'])
pb_payload.append(payload_structure.getroot())
#TODO: Signatures
if 'destination_feed_name' in dict:
etree.SubElement(xml, 'CustomerRefNo')
etree.SubElement(xml, 'ExtraServices')
etree.SubElement(xml, 'HoldForPickup')
etree.SubElement(xml, 'OpenDistribute')
etree.SubElement(xml, 'PermitNumber')
etree.SubElement(xml, 'PermitZIPCode')
etree.SubElement(xml, 'PermitHolderName')
etree.SubElement(xml, 'CRID')
etree.SubElement(xml, 'MID')
etree.SubElement(xml, 'LogisticsManagerMID')
etree.SubElement(xml, 'VendorCode')
etree.SubElement(xml, 'VendorProductVersionNumber')
etree.SubElement(xml, 'SenderName')
etree.SubElement(xml, 'SenderEMail')
etree.SubElement(xml, 'RecipientName')
etree.SubElement(xml, 'RecipientEMail')
etree.SubElement(xml, 'ReceiptOption')
image = etree.SubElement(xml, 'ImageType')
image.text = 'PDF'
self.result = usps.send_request('label', xml)
# Get the layer and iterate through the features
lyr = ds.GetLayer(0)
root = etree.Element("shapefile", name=layername)
OFTInteger = ogr.OFTInteger
OFTReal = ogr.OFTReal
OFTString = ogr.OFTString
for feat in lyr:
featurenode = etree.SubElement(root, "feature")
feat_defn = lyr.GetLayerDefn()
GetFieldDefn = feat_defn.GetFieldDefn
for i in range(feat_defn.GetFieldCount()):
field_defn = GetFieldDefn(i)
fieldnode = etree.SubElement(featurenode, field_defn.GetName())
if field_defn.GetType() == OFTInteger:
fieldnode.text = str(feat.GetFieldAsInteger(i))
elif field_defn.GetType() == OFTReal:
fieldnode.text = str(feat.GetFieldAsDouble(i))
elif field_defn.GetType() == OFTString:
FieldString = str(feat.GetFieldAsString(i))
# @ToDo: Don't assume UTF-8
fieldnode.text = FieldString.decode(encoding="UTF-8",
errors="strict")
wktnode = etree.SubElement(featurenode, "wkt")
geom = feat.GetGeometryRef()
wktnode.text = geom.ExportToWkt()
# @ToDo: Convert using XSLT