本文整理汇总了Python中elementtree.ElementTree.SubElement.set方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.set方法的具体用法?Python SubElement.set怎么用?Python SubElement.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.ElementTree.SubElement
的用法示例。
在下文中一共展示了SubElement.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_work_unit_to_task
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import set [as 别名]
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()
示例2: AddElement
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import set [as 别名]
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'))
示例3: genPerlStdCIX
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import set [as 别名]
#.........这里部分代码省略.........
block["lines"].append(line)
#pprint(blocks)
# Process the blocks into a list of command info dicts.
def podrender(pod):
rendered = pod
rendered = re.sub("F<(.*?)>", r"\1", rendered)
rendered = re.sub("I<(.*?)>", r"*\1*", rendered)
def quoteifspaced(match):
if ' ' in match.group(1):
return "'%s'" % match.group(1)
else:
return match.group(1)
rendered = re.sub("C<(.*?)>", quoteifspaced, rendered)
def linkrepl(match):
content = match.group(1)
if content.startswith("/"): content = content[1:]
if "/" in content:
page, section = content.split("/", 1)
content = "%s in '%s'" % (section, page)
else:
content = "'%s'" % content
return content
rendered = re.sub("L<(.*?)>", linkrepl, rendered)
return rendered
# These perl built-ins are grouped in perlfunc.pod.
commands = []
WIDTH = 60 # desc field width
syscalls = """
getpwnam getgrnam gethostbyname getnetbyname getprotobyname
getpwuid getgrgid getservbyname gethostbyaddr getnetbyaddr
getprotobynumber getservbyport getpwent getgrent gethostent
getnetent getprotoent getservent setpwent setgrent sethostent
setnetent setprotoent setservent endpwent endgrent endhostent
endnetent endprotoent endservent
""".split()
calltip_skips = "sub use require".split()
for block in blocks:
name, sigs, lines = block["name"], block["sigs"], block["lines"]
if name == "-X": # template for -r, -w, -f, ...
pattern = re.compile(r"^ (-\w)\t(.*)$")
tlines = [line for line in lines if pattern.match(line)]
for tline in tlines:
tname, tdesc = pattern.match(tline).groups()
tsigs = [s.replace("-X", tname) for s in sigs]
command = {"name": tname, "sigs": tsigs,
"desc": textwrap.fill(tdesc, WIDTH)}
commands.append(command)
elif name in ("m", "q", "qq", "qr", "qx", "qw", "s", "tr", "y"):
operators = {
"m": """\
m/PATTERN/cgimosx
/PATTERN/cgimosx
Searches a string for a pattern match, and in scalar
context returns true if it succeeds, false if it fails.
""",
"q": """\
q/STRING/
'STRING'
A single-quoted, literal string.
""",
"qq": """\
qq/STRING/
示例4: rec2format
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import set [as 别名]
def rec2format (context, recs, output_format='mods'):
try:
config = context.config
source_catalog = context.get_source_catalog()
ctm = source_catalog.get_complete_mapping()
root = Element('modsCollection')
root.set('xmlns', 'http://www.loc.gov/mods/v3')
root.set('xmlns:xlink', 'http://www.w3.org/1999/xlink')
root.set('version', '3.0')
root.set('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
root.set('xsi:schemaLocation',
'http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd')
for rec in recs:
try:
mods = SubElement(root, 'mods')
mm = rec.get_mapped_metadata(ctm)
if mm.get('title', ''):
titleInfo = SubElement(mods, 'titleInfo')
title = SubElement(titleInfo, 'title')
title.text = mm['title']
if mm.get('author', []):
for au in mm['author']:
name = SubElement(mods, 'name')
name.set('type', 'personal')
# Note: bibutils looks for family/given split
if ' ' in au:
family, given = au.split(' ')
namePart = SubElement(name, 'namePart')
namePart.set('type', 'given')
namePart.text = given
namePart = SubElement(name, 'namePart')
namePart.set('type', 'family')
namePart.text = family
else:
namePart = SubElement(name, 'namePart')
namePart.set('type', 'family')
namePart.text = au
role = SubElement(name, 'role')
roleTerm = SubElement(role, 'roleTerm')
roleTerm.set('type', 'text')
roleTerm.text = 'author'
typeOfResource = SubElement(mods, 'typeOfResource')
typeOfResource.text = 'text'
# The following block is about the "host" journal in which this
# article appeared
relatedItem = SubElement(mods, 'relatedItem')
relatedItem.set('type', 'host')
titleInfo = SubElement(relatedItem, 'titleInfo')
title = SubElement(titleInfo, 'title')
title.text = mm['journal']
if mm.get('issn', ''):
identifier = SubElement(relatedItem, 'identifier')
identifier.set('type', 'issn')
identifier.text = mm['issn']
originInfo = SubElement(relatedItem, 'originInfo')
issuance = SubElement(originInfo, 'issuance')
issuance.text = 'continuing'
part = SubElement(relatedItem, 'part')
if mm.get('volume', ''):
detail = SubElement(part, 'detail')
detail.set('type', 'volume')
number = SubElement(detail, 'number')
number.text = mm['volume']
if mm.get('issue', ''):
detail = SubElement(part, 'detail')
detail.set('type', 'issue')
number = SubElement(detail, 'number')
number.text = mm['issue']
if mm.get('pages', ''):
extent = SubElement(part, 'extent')
extent.set('unit', 'page')
if '-' in mm['pages']:
start, end = mm['pages'].split('-')
st = SubElement(extent, 'start')
st.text = start
en = SubElement(extent, 'end')
en.text = end
else:
st = SubElement(extent, 'start')
st.text = mm['pages']
if mm.get('pubdate', ''):
date = SubElement(part, 'date')
date.text = mm['pubdate'][:4]
for subtype in ['subject', 'keyword']:
for sub in mm.get(subtype, []):
subject = SubElement(mods, 'subject')
if subtype == 'subject':
subject.set('authority', 'mesh')
topic = SubElement(subject, 'topic')
topic.text = sub
except:
print traceback.print_exc()
mods_out = etree.tostring(root)
if output_format == 'mods':
#.........这里部分代码省略.........