本文整理汇总了Python中xml.etree.cElementTree.register_namespace函数的典型用法代码示例。如果您正苦于以下问题:Python register_namespace函数的具体用法?Python register_namespace怎么用?Python register_namespace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register_namespace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: remove_invalid_point_name
def remove_invalid_point_name(fname, output_dir):
print fname
print LINE_SEPARATOR_CHAR_NUM * LINE_SEPARATOR_CHAR
ElementTree.register_namespace('', "http://www.w3.org/2000/svg")
tree = ElementTree.parse(fname)
for node in tree.iter('{http://www.w3.org/2000/svg}text'):
point_name = node.attrib.get('tag')
# tag="LYRD.DLP.1TR5433"
if point_name is not None:
point_name = point_name.strip().split('.')
point_name = point_name[len(point_name)-1]
if point_name is not None and point_name in g_invalid_point_db_list:
print point_name
# 1TE5501-15
patterns = r'\d\w{2}\d{4}-\d{2}'
match_obj = re.match(patterns, point_name, re.I)
if match_obj:
print match_obj.group()
new_point_name = point_name.replace('-','',1)
node.set('tag', 'LYRD.DLP.' + new_point_name)
else:
node.clear()
tree.write(output_dir+fname.split("/")[3])
print LINE_SEPARATOR_CHAR_NUM * LINE_SEPARATOR_CHAR
开发者ID:ZhiweiYAN,项目名称:sis_dcs_points_mapping,代码行数:28,代码来源:remove_invalid_point_in_svg.py
示例2: to_string
def to_string(self, endpoints):
"""
Converts the given endpoint description beans into a string
:param endpoints: A list of EndpointDescription beans
:return: A string containing an XML document
"""
# Make the ElementTree
root = self._make_xml(endpoints)
tree = ElementTree.ElementTree(root)
# Force the default name space
ElementTree.register_namespace("", EDEF_NAMESPACE)
# Make the XML
for encoding in ('unicode', 'UTF-8'):
# Prepare a StringIO output
output = StringIO()
try:
# Try to write with a correct encoding
tree.write(output, encoding=encoding, xml_declaration=True,
method="xml")
break
except LookupError:
# 'unicode' is needed in Python 3, but unknown in Python 2...
continue
else:
raise LookupError("Couldn't find a valid encoding")
return output.getvalue()
开发者ID:tcalmant,项目名称:pelix-ecf-chat,代码行数:33,代码来源:edef.py
示例3: fix_mani_meta_bug
def fix_mani_meta_bug(self, app_path):
print
print "=============================================="
print "++++++Fix AndroidManifest meta-data bug+++++++"
print "=============================================="
try:
mani_xml_path = "%s/AndroidManifest.xml" % app_path
schemas = "http://schemas.android.com/apk/res/android"
ET.register_namespace("android", schemas)
tree = ET.parse(mani_xml_path)
k_android_name = "{%s}name" % schemas
application = tree.find("application")
meta_datas = application.findall("meta-data")
for meta_data in meta_datas:
android_name = meta_data.get(k_android_name)
if android_name.startswith("@string"):
label_array = android_name.split("/")
if len(label_array) == 2:
key = label_array[1]
value_in_strings = self.get_strings_item_value(
app_path, key)
meta_data.set(k_android_name, value_in_strings)
tree.write(mani_xml_path, "utf-8", True)
print "Fix mani meta-data bug in %s => OK" % app_path
print
except Exception, e:
print "Fix mani meta-data bug in %s => Failure" % app_path
logging.error(e)
开发者ID:mumaoxi,项目名称:hkc_lib,代码行数:28,代码来源:packageutils.py
示例4: readworld
def readworld():
from xml.etree import cElementTree as ElementTree
ElementTree.register_namespace('xsi', 'http://www.w3.org/2001/XMLScheme-instance')
namespace = {'xsi': 'http://www.w3.org/2001/XMLScheme-instance'}
xmlPath = 'e:\\test.xml'
xmlRoot = ElementTree.parse(xmlPath).getroot()
results = xmlRoot.findall(".//SectorObjects/MyObjectBuilder_EntityBase[StorageName]")
try:
for result in results:
roidname = result.find('StorageName').text
for pos in result.iter('Position'):
pos = pos.attrib
posx = pos.get('x')
posx = float(posx)
posy = pos.get('y')
posy = float(posy)
posz = pos.get('z')
posz = float(posz)
#Do the damn thing
createAsteroid(posx,posy,posz,roidname)
#print(posz)
print(roidname)
except AttributeError as aE:
print('no')
开发者ID:TheEngineer50,项目名称:Blender-SE-Map-Importer,代码行数:30,代码来源:blenderimportscript.py
示例5: checkFile
def checkFile(fn, options):
global current_file, warn_nbr, root
current_file = fn
print("Starting %s%s" % (fn, options))
tree = ET.parse(fn)
root = tree.getroot()
#print("root.attrib=%s, test -> %d" % (root.attrib, "xmlns" in root.attrib))
# # attrib list doesn't have includes "xmlns", even though it's there
#print("root.tag=%s" % root.tag)
no_ns = root.tag.find("{") < 0
#print("no_ns = %s" % no_ns)
ET.register_namespace("", "http://www.w3.org/2000/svg")
# Stops tree.write() from prefixing above with "ns0"
check(root, 0)
if trace and len(bad_namespaces) != 0:
print("bad_namespaces = %s" % bad_namespaces)
if new_file:
sp = fn.rfind('.svg')
if sp+3 != len(fn)-1: # Indeces of last chars
print("filename doesn't end in '.svg' (%d, %d)" % (sp, len(fn)))
else:
if no_ns:
root.attrib["xmlns"] = "http://www.w3.org/2000/svg"
for ns in bad_namespaces:
remove_namespace(root, ns)
new_fn = fn.replace(".svg", ".new.svg")
print("writing to %s" % (new_fn))
tree.write(new_fn)
return warn_nbr
开发者ID:nevil-brownlee,项目名称:check_svg,代码行数:31,代码来源:check-svg.py
示例6: modify_mani_activity_name
def modify_mani_activity_name(self, extra_dir, old_activity, new_activity):
print
print "====================="
print "+Update Mani activity"
print "====================="
mani_xml_path = "%s/AndroidManifest.xml" % extra_dir
schemas = "http://schemas.android.com/apk/res/android"
ET.register_namespace("android", schemas)
tree = ET.parse(mani_xml_path)
k_android_name = "{%s}name" % schemas
application = tree.find("application")
items = application.findall("activity")
activity = None
for item in items:
android_name = item.get(k_android_name)
if android_name == old_activity:
activity = item
break
if activity != None:
old_android_name = activity.get(k_android_name)
print ">>>old activity name: %s" % old_android_name
if new_activity:
activity.set(k_android_name, str(new_activity))
tree.write(mani_xml_path, "utf-8", True)
new_android_name = activity.get(k_android_name)
print ">>>new activity name: %s" % new_android_name
print "Update AndroidManifest.xml activity name %s to %s => OK" % (old_activity, new_activity)
print
else:
print ">>>not exists activity name %s" % old_activity
开发者ID:mumaoxi,项目名称:hkc_lib,代码行数:31,代码来源:packageutils.py
示例7: ban
def ban(self, jid, reason=None):
"""Ban a user"""
ET.register_namespace('', self.muc_namespace)
root_element = ET.Element('{' + self.muc_namespace + '}query')
item = ET.SubElement(root_element, 'item')
item.set('affiliation', 'outcast')
item.set('jid', jid)
if reason is not None:
reasonelement = ET.SubElement(item, 'reason')
reasonelement.text = reason
iq = self.connection.create_iq(id='ban', itype='set',
payload=root_element,
namespace=self.muc_namespace)
try:
response = iq.send()
log.debug('Ban success')
return True
except IqError as iqe:
log.warning('IqError happened! Error: ' + iqe.text)
return False
except IqTimeout as iqt:
log.warning('IqTimeout happened!')
return False
开发者ID:Woll0r,项目名称:cardboardbot,代码行数:26,代码来源:CardboardIq.py
示例8: track_to_tcx
def track_to_tcx(track, pretty=False):
ns = tcx_ns
root = xml.Element(ns('TrainingCenterDatabase'))
root.set(xsi_ns('schemaLocation'), ' '.join([
_TCX_NS, _TCX_NS_XSD, _ACT_EXT_NS, _ACT_EXT_NS_XSD]))
xml.register_namespace('', _TCX_NS)
xml.register_namespace('_ns3', _ACT_EXT_NS)
activities = xml.SubElement(root, ns('Activities'))
activity = xml.SubElement(activities, ns('Activity'))
activity.set(ns('Sport'), 'Biking')
xml.SubElement(activity, ns('Id')).text = \
format_timestamp(track.timestamp)
create_laps(track, activity, ns)
if pretty:
indent_element_tree(root, ws=' ')
out = xml.tostring(root)
# ElementTree doesn't let me set prefix ns3 and a lot of software
# seems to be hardcoded to use ns3 so have to use this little hack.
out = out.replace('_ns3:', 'ns3:').replace('xmlns:_ns3', 'xmlns:ns3')
return "<?xml version='1.0' encoding='utf-8'?>\n" + out
开发者ID:broschb,项目名称:bryton-gps-linux,代码行数:33,代码来源:tcx.py
示例9: delete_dest_laucher_action_category
def delete_dest_laucher_action_category(self):
dest_mani = "%s/AndroidManifest.xml" % self.decode_dir
schemas = "http://schemas.android.com/apk/res/android"
ET.register_namespace("android", schemas)
k_android_name = "{%s}name" % schemas
tree = ET.parse(dest_mani)
application = tree.find("application")
activitys = application.findall("activity")
for activity in activitys:
intent_filters = activity.findall("intent-filter")
for intent_filter in intent_filters:
action_main = None
actions = intent_filter.findall("action")
for action in actions:
android_name = action.get(k_android_name)
if android_name == "android.intent.action.MAIN":
action_main = action
category_launcher = None
categories = intent_filter.findall("category")
for category in categories:
android_name = category.get(k_android_name)
if android_name == "android.intent.category.LAUNCHER":
category_launcher = category
if action_main != None and category_launcher != None:
intent_filter.remove(action_main)
intent_filter.remove(category_launcher)
tree.write(dest_mani, "utf-8", True)
print "Delete dest launcher action category %s => OK" % dest_mani
print
开发者ID:mumaoxi,项目名称:hkc_lib,代码行数:29,代码来源:mergeutils.py
示例10: banlist
def banlist(self):
"""Fetch the banlist and process it"""
# Register namespace to an empty prefix
ET.register_namespace('', self.muc_namespace)
# Create the query elements
root_element = ET.Element('{' + self.muc_namespace + '}query')
item = ET.SubElement(root_element, 'item')
item.set('affiliation', 'outcast')
# Create IQ stanza
iq = self.connection.create_iq(id='banlist', itype='get',
payload=root_element,
namespace=self.muc_namespace)
# Get response and find elements inside
try:
response = iq.send()
items = response.findall('.//{' + self.muc_namespace + '}item')
log.debug("Banlist contents: " + str(items))
res = ""
for item in items:
if item.get('jid') is not None:
res += "\n" + item.get('jid') + ": " + str(item[0].text)
return res
except IqError as iqe:
log.warning('IqError happened! Error: ' + iqe.text)
return iqe.text
except IqTimeout as iqt:
log.warning('IqTimeout happened!')
return iqt.text
开发者ID:Woll0r,项目名称:cardboardbot,代码行数:32,代码来源:CardboardIq.py
示例11: update_dest_mani_application
def update_dest_mani_application(self, new_items, tag):
print
print "================================="
print "++++Merge mani application+++++++"
print "================================="
print ">>>tag: %s" % tag
dest_mani = "%s/AndroidManifest.xml" % self.decode_dir
schemas = "http://schemas.android.com/apk/res/android"
ET.register_namespace("android", schemas)
k_android_name = "{%s}name" % schemas
tree = ET.parse(dest_mani)
application = tree.find("application")
old_items = application.findall(tag)
delete_items = []
# 检索出android:name值相同的
for old_item in old_items:
old_item_android_name = old_item.get(k_android_name)
for new_item in new_items:
new_item_android_name = new_item.get(k_android_name)
if old_item_android_name == new_item_android_name:
delete_items.append(old_item)
# 去除android:name值相同的
for delete_item in delete_items:
application.remove(delete_item)
tree.write(dest_mani, "utf-8", True)
# 添加新的
for new_item in new_items:
application.append(new_item)
tree.write(dest_mani, "utf-8", True)
print "Update mani application tag %s %s => OK" % (tag, dest_mani)
print
开发者ID:mumaoxi,项目名称:hkc_lib,代码行数:31,代码来源:mergeutils.py
示例12: update_dest_mani_permission
def update_dest_mani_permission(self, new_permissions):
print
print "================================="
print "++++Merge mani permission+++++++"
print "================================="
dest_mani = "%s/AndroidManifest.xml" % self.decode_dir
schemas = "http://schemas.android.com/apk/res/android"
ET.register_namespace("android", schemas)
k_android_name = "{%s}name" % schemas
tree = ET.parse(dest_mani)
root = tree.getroot()
old_permissions = root.findall("uses-permission")
# 添加新的
for new_permission in new_permissions:
# 判断是否存在相同的
new_permission_android_name = new_permission.get(k_android_name)
exist_permission = False
for old_permission in old_permissions:
old_permission_android_name = old_permission.get(
k_android_name)
if new_permission_android_name == old_permission_android_name:
exist_permission = True
break
# 不存在则添加
if not exist_permission:
root.append(new_permission)
tree.write(dest_mani, "utf-8", True)
print "Update mani permissions %s => OK" % dest_mani
print
开发者ID:mumaoxi,项目名称:hkc_lib,代码行数:29,代码来源:mergeutils.py
示例13: track_to_garmin_gpxx
def track_to_garmin_gpxx(track, pretty=False):
ns = gpx_ns
root = xml.Element(ns('gpx'))
root.set(xsi_ns('schemaLocation'), ' '.join([
_GPX_NS, _GPX_NS_XSD, _TPX_NS, _TPX_NS_XSD]))
root.set(ns('version'), '1.1')
root.set(ns('creator'), 'Bryton-GPS-Linux')
xml.register_namespace('', _GPX_NS)
xml.register_namespace('gpxtpx', _TPX_NS)
trk = xml.SubElement(root, ns('trk'))
for seg in track.merged_segments():
create_tpx_trkseg(seg, trk, ns)
if pretty:
indent_element_tree(root, ws=' ')
return "<?xml version='1.0' encoding='utf-8'?>\n" + xml.tostring(root)
开发者ID:Pitmairen,项目名称:bryton-gps-linux,代码行数:26,代码来源:gpx.py
示例14: xml
def xml(self):
ET.register_namespace('', SCHEME_PREFIX[1:-1])
root = ET.Element("USERJOURNEY", {'APPNAME': self.app_name, 'NAME': self.name, 'VALID': 'true', 'VERSION': self.version})
root.set('xmlns', "http://www.reflective.com")
root.set('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance")
root.set('xsi:schemaLocation', "http://www.reflective.com stschema.xsd")
description = ET.SubElement(root, 'DESCRIPTION')
plugin = ET.SubElement(root, 'PLUGIN', {'ID': '1'})
responseprocessor = ET.SubElement(root, 'RESPONSEPROCESSOR')
created = ET.SubElement(root, 'CREATED')
created.text = self.created
for nvp in self.uj_global_settings:
text = nvp['text']
attributes = {key: value for key, value in nvp.items() if key is not 'text'}
new_nvp = ET.SubElement(root, 'NVP', attributes)
new_nvp.text = text
dynamic_data_element = ET.SubElement(root, 'DYNAMICDATA')
for ddi in self.dditems:
dynamic_data_element.append(ddi.xml())
steps_element = ET.SubElement(root, 'STEPS')
for step in [step for sg in self.stepgroups for step in sg.steps]:
st = step.xml()
steps_element.append(step.xml())
rough_string = ET.tostring(root, 'utf-8')
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent='\t').replace('<?xml version="1.0" ?>\n', self.first_import_line)
开发者ID:bobev18,项目名称:stujeditor,代码行数:30,代码来源:userjourney.py
示例15: modify_app_lanucher
def modify_app_lanucher(self, decoded_file_path, ldpi, mdpi, hdpi,
xhdpi, xxhdpi):
print
print "====================="
print "+++Update app icon+++"
print "====================="
print ">>>decoded_file_path: %s" % decoded_file_path
print ">>>ldpi: %s" % ldpi
print ">>>mdpi: %s" % mdpi
print ">>>hdpi: %s" % hdpi
print ">>>xhdpi: %s" % xhdpi
print ">>>xxhdpi: %s" % xxhdpi
mani_xml_path = "%s/AndroidManifest.xml" % decoded_file_path
schemas = "http://schemas.android.com/apk/res/android"
ET.register_namespace("android", schemas)
tree = ET.parse(mani_xml_path)
app = tree.find("application")
k_icon = "{%s}icon" % schemas
s_icon = app.get(k_icon)
icon_array = s_icon.split("/")
new_icon_name = "%s.png" % icon_array[1]
print ">>>New icon name: %s" % new_icon_name
if hdpi:
res_path = "%s/res" % decoded_file_path
res_array = os.listdir(res_path)
res_array = os.listdir(res_path)
for item in res_array:
if item.startswith("drawable"):
self.modify_drawable_icon(decoded_file_path, item, ldpi,
mdpi, hdpi, xhdpi, xxhdpi, new_icon_name)
else:
print ">>>You must give me hdpi image"
开发者ID:mumaoxi,项目名称:hkc_lib,代码行数:32,代码来源:packageutils.py
示例16: __init__
def __init__(self, ns, prefix=None):
"""Args:
ns (string) - namespace
prefix (string) - optionnal prefix to register"""
self.ns = ns
if prefix:
ElementTree.register_namespace(prefix, ns)
开发者ID:darcyg,项目名称:upnpy,代码行数:7,代码来源:utils.py
示例17: modify_meta_data
def modify_meta_data(self, extra_dir, key, value):
print
print "====================="
print "+++Update meta_data++"
print "====================="
print ">>>extra_dir: %s" % extra_dir
print ">>>key: %s" % key
print ">>>value: %s" % value
mani_xml_path = "%s/AndroidManifest.xml" % extra_dir
schemas = "http://schemas.android.com/apk/res/android"
ET.register_namespace("android", schemas)
tree = ET.parse(mani_xml_path)
k_android_name = "{%s}name" % schemas
k_android_value = "{%s}value" % schemas
application = tree.find("application")
items = application.findall("meta-data")
meta_data = None
for item in items:
android_name = item.get(k_android_name)
if android_name == key:
meta_data = item
break
if meta_data != None:
old_android_value = meta_data.get(k_android_value)
print ">>>old meta-data: %s" % old_android_value
if value:
meta_data.set(k_android_value, str(value))
tree.write(mani_xml_path, "utf-8", True)
new_android_value = meta_data.get(k_android_value)
print ">>>new meta-data: %s" % new_android_value
print "Update meta-data %s to %s => OK" % (key, value)
print
else:
print ">>>not exists meta-data %s" % key
开发者ID:mumaoxi,项目名称:hkc_lib,代码行数:34,代码来源:packageutils.py
示例18: __init__
def __init__(self, root, req):
"""
<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd" xmlns="http://www.phyloxml.org">
002 <phylogeny rooted="false">
"""
et.register_namespace('', self.namespace)
self.req = req
self.e = self.element('phyloxml')
phylogeny = self.element('phylogeny', rooted="true")
#rect = self.element('rectangular')
#rect.append(self.element('alignRight', 'true'))
#params = self.element('parameters')
#params.append(rect)
#render = self.element('render')
#render.append(params)
#phylogeny.append(render)
"""
<render>
<parameters>
<rectangular>
<alignRight>true</alignRight>
</rectangular>
</parameters>
</render>
"""
phylogeny.append(self.element('name', root.name))
phylogeny.append(self.element('description', root.name))
clade = self.clade(root)
self.append_children(clade, root)
phylogeny.append(clade)
self.e.append(phylogeny)
开发者ID:kublaj,项目名称:glottolog3,代码行数:32,代码来源:compute_treefiles.py
示例19: svg_icon
def svg_icon(loader, name, css_class=''):
"""
Return inline SVG markup for an icon.
This is a helper for generating inline SVGs for rendering icons in HTML
that can be customized via CSS.
See https://github.com/blog/2112-delivering-octicons-with-svg
:param loader: Callable accepting an icon name and returning XML markup for
the SVG.
:param name: The name of the SVG file to render
:param css_class: CSS class attribute for the returned `<svg>` element
"""
# Register SVG as the default namespace. This avoids a problem where
# ElementTree otherwise serializes SVG elements with an 'ns0' namespace (eg.
# '<ns0:svg>...') and browsers will not render the result as SVG.
# See http://stackoverflow.com/questions/8983041
ElementTree.register_namespace('', SVG_NAMESPACE_URI)
root = ElementTree.fromstring(loader(name))
if css_class:
root.set('class', css_class)
# If the SVG has its own title, ignore it in favor of the title attribute
# of the <svg> or its containing element, which is usually a link.
title_el = root.find('{{{}}}title'.format(SVG_NAMESPACE_URI))
if title_el is not None:
root.remove(title_el)
return Markup(ElementTree.tostring(root))
开发者ID:nlisgo,项目名称:h,代码行数:31,代码来源:jinja_extensions.py
示例20: __init__
def __init__(self, content, device=None):
self.content = content
ET.register_namespace('', 'urn:psialliance-org')
self.xml_node = ET.fromstring(self.content)
print(self.xml_node)
self.psia_ns = {'root_ns':'urn:psialliance-org'}
if device is not None:
self.device = device
开发者ID:yuetianle,项目名称:gateway,代码行数:8,代码来源:psia_wrap.py
注:本文中的xml.etree.cElementTree.register_namespace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论