本文整理汇总了Python中elementtree.ElementTree.SubElement类的典型用法代码示例。如果您正苦于以下问题:Python SubElement类的具体用法?Python SubElement怎么用?Python SubElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: toXML
def toXML(self):
'''Generate the xml representation of the letter matrix'''
# <control type="panel">
control = Element('control', type='panel', id=str(CONTROL_PANEL))
if True:
SubElement(control, 'posx').text = str(self.posx)
SubElement(control, 'posy').text = str(self.posy)
SubElement(control, 'width').text = str(self.width)
SubElement(control, 'height').text = str(self.height)
SubElement(control, 'onleft').text = '-'
SubElement(control, 'onright').text = '-'
SubElement(control, 'onup').text = '-'
SubElement(control, 'ondown').text = '-'
SubElement(control, 'viewtype', label='').text = 'panel'
SubElement(control, 'pagecontrol').text = '-'
SubElement(control, 'scrolltime').text = '-'
SubElement(control, 'hitrect', x=str(-10), y=str(-10), w=str(1), h=str(1))
# <itemlayout>
itemlayout = SubElement(control, 'itemlayout', height=str(self.letterHeight), width=str(self.letterWidth))
if True:
self.addItemLayout(itemlayout, self.theme.inactive, 1)
self.addItemLayout(itemlayout, self.theme.active, 2)
# </itemlayout>
SubElement(control, 'focusedlayout', height=str(self.height), width=str(self.width))
# <content>
content = SubElement(control, 'content')
if True:
# <item>
for letter in self.letters:
content.append(letter.toXML())
# </item>
# </content>
# </control>
return control
示例2: TextElement
def TextElement(root, name, detail_value):
if detail_value:
te = SubElement(root, name)
if detail_value.type == "text/html": detail_value.type = "html"
if detail_value.type == "text/plain": detail_value.type = "text"
te.attrib["type"] = detail_value.type
te.text = detail_value.value
示例3: CreateSourceElement
def CreateSourceElement(ee, feed):
"""Create an atom:source element in the provided entry element,
based on the provided feed metadata.
"""
if not feed: return
root = SubElement(ee, "source")
TextElement(root, "title", feed.get("title_detail"))
if feed.has_key("links"):
for link in feed.links:
LinkElement(root, "link", link)
TextElement(root, "subtitle", feed.get("subtitle_detail"))
TextElement(root, "rights", feed.get("rights_detail"))
SubElement(root, "generator").text = "feedarchive"
SubElement(root, "updated").text = rfc3339(time.time())
SubElementIf(root, "id", feed.get("id"))
if feed.has_key("image"):
SubElement(root, "icon").text = feed.image.href
if feed.has_key("tags"):
for tag in feed.tags:
te = SubElement(root, "category")
if tag.get("term"): te.attrib["term"] = tag.term
if tag.get("scheme"): te.attrib["scheme"] = tag.scheme
if tag.get("label"): te.attrib["label"] = tag.label
PersonElement(root, "author", feed.get("author_detail"))
示例4: LinkElement
def LinkElement(root, name, link):
if link:
le = SubElement(root, name)
if (link.has_key("rel")): le.attrib["rel"] = link.rel
if (link.has_key("title")): le.attrib["title"] = link.title
if (link.has_key("type")):
le.attrib["type"] = link.type
if (link.has_key("href")): le.attrib["href"] = link.href
示例5: addRing
def addRing(self, objRing, strType):
if strType == 'Inner':
elemBnd = Element('innerBoundaryIs')
else:
elemBnd = Element('outerBoundaryIs')
elemRing = SubElement(elemBnd, 'LinearRing')
elemCoords = SubElement(elemRing, "coordinates")
elemCoords.text = self.addCoordinates(objRing[1])
return elemBnd
示例6: GetFeedElement
def GetFeedElement(feed):
"""Create an atom:feed element for the provided feed.
The provided feed must be in the format described at http://feedparser.org.
"""
rss = Element("rss")
rss.attrib["version"] = "2.0"
root = SubElement(rss, "channel")
TextElement(root, "title", feed.feed.get("title_detail"))
if feed.feed.has_key("links"):
for link in feed.feed.links:
if link.rel != "self": continue
SubElementIf(root, "link", link.href)
TextElement(root, "description", feed.feed.get("subtitle_detail"))
TextElement(root, "copyright", feed.feed.get("rights_detail"))
SubElement(root, "generator").text = "feedarchive"
if feed.feed.has_key("image"):
im = feed.feed.image
ie = SubElement(root, "image")
SubElementIf(ie, "url", im.get("href"))
SubElementIf(ie, "title", im.get("title"))
SubElementIf(ie, "link", im.get("link"))
if feed.feed.has_key("tags"):
for tag in feed.feed.tags:
te = SubElement(root, "category")
if (tag.has_key("scheme")): te.attrib["domain"] = tag.scheme
te.text = tag.term
for entry in feed.entries:
ee = SubElement(root, "item")
TextElement(ee, "title", entry.get("title_detail"))
SubElementIf(ee, "link", entry.get("link"))
TextElement(ee, "description", entry.get("summary_detail"))
SubElementIf(ee, "guid", entry.get("id"))
DateTimeElement(ee, "pubDate", entry, "published")
PersonElement(ee, "author", entry.get("author_detail"))
if entry.has_key("links"):
for link in entry.links:
if link.rel != "enclosure": continue
ence = SubElement(ee, "enclosure")
AttribIf(ence, "url", link.get("url"))
AttribIf(ence, "length", link.get("length"))
AttribIf(ence, "type", link.get("type"))
return rss
示例7: GetFeedElement
def GetFeedElement(feed):
"""Create an atom:feed element for the provided feed.
The provided feed must be in the format described at http://feedparser.org.
"""
root = Element("feed")
root.attrib["xmlns"] = "http://www.w3.org/2005/Atom"
TextElement(root, "title", feed.feed.get("title_detail"))
if feed.feed.has_key("links"):
for link in feed.feed.links:
LinkElement(root, "link", link)
TextElement(root, "subtitle", feed.feed.get("subtitle_detail"))
TextElement(root, "rights", feed.feed.get("rights_detail"))
SubElement(root, "generator").text = "feedarchive"
SubElement(root, "updated").text = rfc3339(time.time())
SubElementIf(root, "id", feed.feed.get("id"))
if feed.feed.has_key("image"):
SubElement(root, "icon").text = feed.feed.image.href
if feed.feed.has_key("tags"):
for tag in feed.feed.tags:
te = SubElement(root, "category")
if tag.get("term"): te.attrib["term"] = tag.term
if tag.get("scheme"): te.attrib["scheme"] = tag.scheme
if tag.get("label"): te.attrib["label"] = tag.label
PersonElement(root, "author", feed.feed.get("author_detail"))
for entry in feed.entries:
ee = SubElement(root, "entry")
TextElement(ee, "title", entry.get("title_detail"))
if entry.has_key("links"):
for link in entry.links:
LinkElement(ee, "link", link)
TextElement(ee, "summary", entry.get("summary_detail"))
TextElement(ee, "content", entry.get("content_detail"))
DateTimeElement(ee, "published", entry, "published")
DateTimeElement(ee, "updated", entry, "updated")
SubElementIf(ee, "id", entry.get("id"))
PersonElement(ee, "author", entry.get("author_detail"))
PersonElement(ee, "publisher", entry.get("publisher_detail"))
if entry.has_key("contributors"):
for contributor in entry.contributors:
PersonElement(ee, "contributor", contributor)
CreateSourceElement(ee, entry.get("source"))
return root
示例8: createFilePodcast
def createFilePodcast(mediaFilePath, title, description=''):
"""
create the xml file using utf
"""
mediaItem = Element("media")
mediaItem.attrib["version"] = VERSION
titleNode = SubElement(mediaItem, "title")
titleNode.text = title
descrNode = SubElement(mediaItem, "description")
descrNode.text = description
createXmlFile(mediaFilePath + '.xml', mediaItem)
mediaItem.clear()
示例9: ToElement
def ToElement(self):
"""
Gets an ElementTree.Element representation.
"""
peer = self.peer
elt = Element("entity", id=peer.id_)
SubElement(elt, "address").text = peer.address.ToString()
SubElement(elt, "version").text = str(peer.protocol_version)
hist = SubElement(elt, "history")
keys = self.intervals.keys()
keys.sort()
for k in keys:
c = SubElement(hist, "connected")
i = self.intervals[k]
c.text = "%s-%s" % (i.start, i.end)
return elt
示例10: gencix
def gencix(major, minor):
# First generate first pass at the CILE over all of the lib tree
cixfile = "activeperl-%d.%d.cix" % (major, minor)
command = "python ../../../ci2.py scan -n -r -p -l Perl -T /tmp/ActivePerl-%d.%d/perl/lib -i \"*.pm\"> %s" % (major, minor, cixfile)
retval = os.system(command)
if retval != 0:
print "Error scanning ActivePerl library"
sys.exit(retval)
#
# Grab the output of that scan
root = parse(cixfile).getroot()
newroot = Element("codeintel", version="2.0")
cixfile = SubElement(newroot, "file", lang="Perl",
mtime=str(int(time.time())),
path=os.path.basename('perl.cix'))
for file in root.getiterator('file'):
print >> sys.stderr, "Processing", file.get('path')
for blob in file:
if blob.get("src"):
# Don't want the src string.
del blob.attrib["src"]
cixfile.append(blob)
cix = genPerlStdCIX(cixfile, "/tmp/ActivePerl-%d.%d/perl/lib/pod/perlfunc.pod" % (major, minor))
parent_map = dict((c, p) for p in cixfile.getiterator() for c in p)
for variable in newroot.getiterator('variable'):
attributes = variable.get('attributes')
if attributes and '__local__' in variable.get('attributes'):
parent_map[variable].remove(variable)
# Generate the CIX.
print >>sys.stderr, "Prettying"
prettify(newroot)
tree = ElementTree(newroot)
#fname = '../../../lib/codeintel2/stdlibs/perl-%d.%d.cix' % (major, minor)
fname = 'perl-%d.%d.cix' % (major, minor)
#os.system('p4 edit %s' % fname)
stream = open(fname, "w")
print >>sys.stderr, "Writing"
stream.write('<?xml version="1.0" encoding="UTF-8"?>\n')
tree.write(stream)
stream.close()
示例11: changeSyntaticToPhonetic
def changeSyntaticToPhonetic(xml):
lexicon = xml.getroot()
for lemma in lexicon.getiterator('lemma'):
if lemma.get('special'): continue
phon = lemma.find('phon')
if phon is not None:
phon = phon.text.split()
phon.append('#1')
synt = lemma.find('synt')
if synt is None:
synt = SubElement(lemma, 'synt')
else:
synt.clear()
synt.tail = '\n '
if phon:
for ph in phon:
SubElement(synt, 'tok').text = ph
示例12: add_work_unit_to_task
def add_work_unit_to_task(tree_root, task_name_or_id):
"""Adds a work unit to the specified task. If the task is not
active, the operation throws Active_error."""
# Obtain the task id.
node = find_task(tree_root, task_name_or_id)
task_id = node.find("id").text
# If the task is killed, report it.
if node.get("killed") == "yes":
raise Active_error("Task %s is dead, aborting "
"operation." % task_name_or_id)
# Create a work-unit for the found task.
work_units = tree_root.find("work-unit-list")
work_unit = SubElement(work_units, "work-unit")
work_unit.set("id", task_id)
work_unit.text = get_today()
示例13: add_task
def add_task(tree_root, task_name):
"""Adds (stripped) task_name to the tree_root."""
assert task_name == task_name.strip()
assert len(task_name) > 1
# Get a new task id, higher than all previous ones.
id_num = highest_task_id(tree_root) + 1
assert id_num >= 0
# Create the task.
tasklist = tree_root.find("task-list")
task = SubElement(tasklist, "task")
SubElement(task, "id").text = "%d" % id_num
SubElement(task, "name").text = task_name.strip()
date_today = get_today()
SubElement(task, "starting-day").text = date_today
SubElement(task, "note").text = ""
last_unit = SubElement(task, "last-unit", attrib = {"amount": "0"})
last_unit.text = date_today
示例14: recurse_for_children
def recurse_for_children(current_node, parent_node, active_cat, show_empty=True):
child_count = current_node.child.count()
if show_empty or child_count > 0 or current_node.product_set.count() > 0:
temp_parent = SubElement(parent_node, 'li')
attrs = {'href': current_node.get_absolute_url()}
if current_node == active_cat:
attrs["class"] = "current"
if current_node.parent:
link = SubElement(temp_parent, 'a', attrs)
else:
link = SubElement(temp_parent, 'span', {})
link.text = current_node.name
if child_count > 0:
new_parent = SubElement(temp_parent, 'ul')
children = current_node.child.all()
for child in children:
recurse_for_children(child, new_parent, active_cat)
示例15: AddElement
def AddElement(element, name, value):
# if it is a ctypes structure
if isinstance(value, ctypes.Structure):
# create an element for the structure
structElem = SubElement(element, name)
# iterate over the fields in the structure
for propName in value._fields_:
propName = propName[0]
itemVal = getattr(value, propName)
if isinstance(itemVal, (int, long)):
propName += "_LONG"
itemVal = unicode(itemVal)
structElem.set(propName, EscapeSpecials(itemVal))#.encode('utf8'))
elif isinstance(value, (list, tuple)):
# add the element to hold the values
#listElem = SubElement(element, name)
# remove the s at the end (if there)
name = name.rstrip('s')
for i, attrVal in enumerate(value):
AddElement(element, "%s_%05d"%(name, i), attrVal)
elif isinstance(value, dict):
dictElem = SubElement(element, name)
for n, val in value.items():
AddElement(dictElem, n, val)
else:
if isinstance(value, (int, long)):
name += "_LONG"
element.set(name, EscapeSpecials(value))#.encode('utf8', 'backslashreplace'))