本文整理汇总了Python中xml.etree.ElementTree.Element类的典型用法代码示例。如果您正苦于以下问题:Python Element类的具体用法?Python Element怎么用?Python Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Element类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: convert_to_xml
def convert_to_xml(self):
test_suites = Element('testsuites')
for suite in self.suites:
test_suites.append(suite.convert_to_xml())
return test_suites
开发者ID:stackedsax,项目名称:Specter,代码行数:7,代码来源:xunit.py
示例2: process_task
def process_task(self, target, command, args):
if self._shared_settings['starttls']:
raise Exception('Cannot use --hsts with --starttls.')
hsts_supported = self._get_hsts_header(target)
if hsts_supported:
hsts_timeout = hsts_supported
hsts_supported = True
# Text output
cmd_title = 'HTTP Strict Transport Security'
txt_result = [self.PLUGIN_TITLE_FORMAT(cmd_title)]
if hsts_supported:
txt_result.append(self.FIELD_FORMAT("OK - HSTS header received:", hsts_timeout))
else:
txt_result.append(self.FIELD_FORMAT("NOT SUPPORTED - Server did not send an HSTS header.", ""))
# XML output
xml_hsts_attr = {'sentHstsHeader': str(hsts_supported)}
if hsts_supported:
xml_hsts_attr['hstsHeaderValue'] = hsts_timeout
xml_hsts = Element('hsts', attrib = xml_hsts_attr)
xml_result = Element('hsts', title = cmd_title)
xml_result.append(xml_hsts)
return PluginBase.PluginResult(txt_result, xml_result)
开发者ID:0x0mar,项目名称:sslyze,代码行数:27,代码来源:PluginHSTS.py
示例3: dict_to_xml
def dict_to_xml(tag, d):
elem = Element(tag)
for key, val in d.items():
child = Element(key)
child.text = str(val)
elem.append(child)
return elem
开发者ID:dansackett,项目名称:learning-playground,代码行数:7,代码来源:xml_example.py
示例4: read_file
def read_file(file_obj):
it_obj = paragraphs(file_obj)
fo_obj = make_fo_tree()
flow = fo_obj[1][0]
for para in it_obj:
block = Element(ns + 'block')
block.set('space-before', '12pt')
flow.append(block)
the_string = para
while the_string:
the_index = the_string.find('`')
if the_index > -1:
start = the_string[:the_index]
insert_text(fo_obj, start)
the_string = the_string[the_index + 1:]
the_index = the_string.find('`')
if the_index > -1:
math = the_string[:the_index]
the_string = the_string[the_index + 1:]
insert_math(block, math)
else:
math = the_string
insert_math(block, math)
break
else:
insert_text(fo_obj, the_string)
break
return fo_obj
开发者ID:paulhtremblay,项目名称:asciimathml,代码行数:28,代码来源:asciimath2fo.py
示例5: _command_resum_rate
def _command_resum_rate(self, target):
"""
Performs 100 session resumptions with the server in order to estimate
the session resumption rate.
"""
# Create a thread pool and process the jobs
NB_THREADS = 20
MAX_RESUM = 100
thread_pool = ThreadPool()
for _ in xrange(MAX_RESUM):
thread_pool.add_job((self._resume_with_session_id, (target, )))
thread_pool.start(NB_THREADS)
# Format session ID results
(txt_resum, xml_resum) = self._format_resum_id_results(thread_pool, MAX_RESUM)
# Text output
cmd_title = 'Resumption Rate with Session IDs'
txt_result = [self.PLUGIN_TITLE_FORMAT(cmd_title)+' '+ txt_resum[0]]
txt_result.extend(txt_resum[1:])
# XML output
xml_result = Element('resum_rate', title = cmd_title)
xml_result.append(xml_resum)
thread_pool.join()
return PluginBase.PluginResult(txt_result, xml_result)
开发者ID:CRYPTOlab,项目名称:sslyze,代码行数:27,代码来源:PluginSessionResumption.py
示例6: write_header_elements
def write_header_elements(self, g):
"""
Helper method for write_header.
"""
graph_header = Element('graphHeader')
graph_header.append(self.render_tag_usage(g))
depends_on = g.header.depends_on
dependencies = SubElement(graph_header, 'dependencies')
if depends_on:
for dependency in depends_on:
if dependency:
SubElement(dependencies, 'dependsOn',
{'f.id': dependency})
aspaces = g.annotation_spaces
annotation_spaces = SubElement(graph_header, 'annotationSpaces')
if aspaces:
for aspace in aspaces:
SubElement(annotation_spaces, 'annotationSpace',
{'as.id': aspace.as_id})
roots = g.header.roots
if roots:
roots_element = SubElement(graph_header, 'roots')
for root in roots:
if root:
SubElement(roots_element, 'root').text = root
return graph_header
开发者ID:cidles,项目名称:graf-python,代码行数:32,代码来源:io.py
示例7: addToWorkingSet
def addToWorkingSet(newProjectPath):
workingSetFilePath = os.path.expanduser("~") + os.sep + ".colt" + os.sep + "workingset.xml"
projectsList = []
# Populate projects list
if os.path.exists(workingSetFilePath) :
workingSetElement = parse(workingSetFilePath).getroot()
for projectElement in workingSetElement :
projectPath = projectElement.attrib["path"]
if projectPath :
projectsList.append(projectPath)
# Remove project path from the list
projectsList = filter(lambda projectPath : projectPath != newProjectPath, projectsList)
# Push new project
projectsList.insert(0, newProjectPath)
# Save the list
workingSetElement = Element("workingset")
workingSetElement.set("openRecent", "true")
for projectPath in projectsList :
projectElement = SubElement(workingSetElement, "project")
projectElement.set("path", projectPath)
workingSetFile = open(workingSetFilePath, "w")
workingSetFile.write(tostring(workingSetElement))
workingSetFile.close()
开发者ID:Shchvova,项目名称:colt-sublime-plugin,代码行数:29,代码来源:colt.py
示例8: story_feed
def story_feed(request, story):
story = Story.objects.get(slug=story)
rss = Element('rss')
rss.set("version","2.0")
channel = SubElement(rss,'channel')
title = SubElement(channel,'title')
title.text = story.title
link = SubElement(channel,'link')
link.text = request.build_absolute_uri(reverse("story"))
desc = SubElement(channel,'description')
desc.text = story.description
chapters = story.chapters.all()
for index in chapters:
item = SubElement(channel,'item')
title_c = SubElement(item,'title')
title_c.text = index.title
link = SubElement(item,'link')
link.text = request.build_absolute_uri(index.get_absolute_url())
return HttpResponse(tostring(rss, encoding='UTF-8'))
开发者ID:gitter-badger,项目名称:fictionhub,代码行数:28,代码来源:views.py
示例9: _saveTracks
def _saveTracks(self, tracks):
element = Element("tracks")
for track in tracks:
track_element = self._saveTrack(track)
element.append(track_element)
return element
开发者ID:dparker18,项目名称:Pitivi,代码行数:7,代码来源:etree.py
示例10: _saveTimelineObjects
def _saveTimelineObjects(self, timeline_objects):
element = Element("timeline-objects")
for timeline_object in timeline_objects:
timeline_object_element = self._saveTimelineObject(timeline_object)
element.append(timeline_object_element)
return element
开发者ID:dparker18,项目名称:Pitivi,代码行数:7,代码来源:etree.py
示例11: convert_MoocMultipleChoiceAssessment_to_xml
def convert_MoocMultipleChoiceAssessment_to_xml(par):
""" Convert multiple choice question into xml. """
xml = Element('problem')
for key in ['display_name', 'max_attempts']:
xml.attrib[key] = str(par[key])
p = SubElement(xml, 'p')
p.text = par['question']
p = SubElement(xml, 'p')
p.text = 'Please select correct answer'
sub = SubElement(xml, 'multiplechoiceresponse')
sub = SubElement(sub, 'choicegroup')
sub.attrib['label'] = "Please select correct answer"
sub.attrib['type'] = "MultipleChoice"
for i, ans in enumerate(par['answers']):
choice = SubElement(sub, 'choice')
if i == par['correct_answer']:
choice.attrib['correct'] = 'true'
else:
choice.attrib['correct'] = 'false'
choice.text = ans
if 'explanation' in par:
add_solution(xml, par['explanation'])
return xml
开发者ID:Huaguiyuan,项目名称:phys_codes,代码行数:30,代码来源:converter.py
示例12: convert_MoocCheckboxesAssessment_to_xml
def convert_MoocCheckboxesAssessment_to_xml(par):
"""Convert checkbox assignment into xml. """
xml = Element('problem')
for key in ['display_name', 'max_attempts']:
xml.attrib[key] = str(par[key])
p = SubElement(xml, 'p')
p.text = par['question']
p = SubElement(xml, 'p')
p.text = 'Select the answers that match'
sub = SubElement(xml, 'choiceresponse')
sub = SubElement(sub, 'checkboxgroup')
sub.attrib['label'] = "Select the answers that match"
sub.attrib['direction'] = "vertical"
for i, ans in enumerate(par['answers']):
choice = SubElement(sub, 'choice')
if i in par['correct_answers']:
choice.attrib['correct'] = 'true'
else:
choice.attrib['correct'] = 'false'
choice.text = ans
if 'explanation' in par:
add_solution(xml, par['explanation'])
return xml
开发者ID:Huaguiyuan,项目名称:phys_codes,代码行数:30,代码来源:converter.py
示例13: convert_MoocVideo_to_xml
def convert_MoocVideo_to_xml(par):
""" Convert video_cell with MoocVideo into xml. """
xml = Element('video')
for key in par:
xml.attrib[key] = str(par[key])
return xml
开发者ID:Huaguiyuan,项目名称:phys_codes,代码行数:7,代码来源:converter.py
示例14: getBaseXML
def getBaseXML():
root = Element('soapenv:Envelope')
root.set('xmlns:soapenv', 'http://schemas.xmlsoap.org/soap/envelope/')
root.set('xmlns:ns', 'http://www.cisco.com/AXL/API/11.0')
header = SubElement(root, 'soapenv:Header')
body = SubElement(root, 'soapenv:Body')
return root, body
开发者ID:MrCollaborator,项目名称:CiscoUCScripts,代码行数:7,代码来源:updateAttribute_py2.py
示例15: process_task
def process_task(self, target, command, args):
ctSSL_initialize()
try:
(can_reneg, is_secure) = self._test_renegotiation(target)
finally:
ctSSL_cleanup()
# Text output
reneg_txt = 'Honored' if can_reneg else 'Rejected'
secure_txt = 'Supported' if is_secure else 'Not supported'
cmd_title = 'Session Renegotiation'
txt_result = [self.PLUGIN_TITLE_FORMAT.format(cmd_title)]
RENEG_FORMAT = ' {0:<35} {1}'
txt_result.append(RENEG_FORMAT.format('Client-initiated Renegotiations:', reneg_txt))
txt_result.append(RENEG_FORMAT.format('Secure Renegotiation: ', secure_txt))
# XML output
xml_reneg_attr = {'canBeClientInitiated' : str(can_reneg),
'isSecure' : str(is_secure)}
xml_reneg = Element('sessionRenegotiation', attrib = xml_reneg_attr)
xml_result = Element(command, title = cmd_title)
xml_result.append(xml_reneg)
return PluginBase.PluginResult(txt_result, xml_result)
开发者ID:Cyber-Forensic,项目名称:TRACE-SSL-check,代码行数:27,代码来源:PluginSessionRenegotiation.py
示例16: _create_xml_node
def _create_xml_node(self, key, value=''):
key = key.replace(' ', '').strip()
if key[0].isdigit(): # Would generate invalid XML
key = 'oid-' + key # Tags cannot start with a digit
xml_node = Element(key)
xml_node.text = value.strip()
return xml_node
开发者ID:kudithipudi,项目名称:sslyze,代码行数:7,代码来源:PluginCertInfo.py
示例17: execute
def execute(self, mappings, source):
"""Writes the given language code/name mappings to Android XML resource files.
source = string indicating source of the data, for example, 'cldr'
mappings = list of dictionaries containing mappings"""
# In order to be able to to localize a particular, limited set of words across multiple
# languages, here we define a list of language codes to support for every resource file
# generated. Where localized language names are missing, a place holder is printed. If
# ['*'] is specified, then all available language code/name pairs are generated.
COVERAGE_LIST = ['*']
# Get language names in English as a dict for inclusion in XML comments
english_pairs = {}
for entry in mappings:
for k, v in entry.iteritems():
if k == 'en':
english_pairs = v
break
for entry in mappings:
for k, v in entry.iteritems():
dir = os.path.join(os.path.dirname(__file__), self.get_directory(source) +
"../" + source + "-android/values-" + k)
if not os.path.exists(dir):
os.makedirs(dir)
with open(dir + "/arrays.xml", "w") as f:
top = Element('resources')
if k in english_pairs.keys():
top_comment = ElementTree.Comment(' ' + english_pairs[k].decode('utf-8') + ' (' + k + ') ')
else:
top_comment = ElementTree.Comment(' ' + k + ' ')
top.append(top_comment)
child = SubElement(top, 'string-array')
child.attrib['name'] = 'languages_all'
if '*' not in COVERAGE_LIST:
# Iterate through only those codes in COVERAGE_LIST
for lang_code in COVERAGE_LIST:
if lang_code in english_pairs.keys():
comment = ElementTree.Comment(' ' + lang_code + ' - ' + english_pairs[lang_code].decode('utf-8') + ' ')
else:
comment = ElementTree.Comment(' ' + lang_code + ' ')
child.append(comment)
entry = SubElement(child, 'item')
if lang_code in v.keys():
entry.text = v[lang_code].decode('utf-8')
else:
entry.text = "UNDEFINED"
else:
# Iterate through all available language codes
for lang_code, lang_name in sorted(v.iteritems()):
if lang_code in english_pairs.keys():
comment = ElementTree.Comment(' ' + lang_code + ' - ' + english_pairs[lang_code].decode('utf-8') + ' ')
else:
comment = ElementTree.Comment(' ' + lang_code + ' ')
child.append(comment)
entry = SubElement(child, 'item')
entry.text = lang_name.decode('utf-8')
f.write(self.prettify(top))
开发者ID:BABZAA,项目名称:language-list,代码行数:60,代码来源:Exporter.py
示例18: sort_time
def sort_time(source):
"""Sort the source Element elements along their time (for annotations) and id (for relations).
Returns a new Element
"""
dest=Element(source.tag)
dest.attrib.update(source.attrib)
antag=tag('annotation')
reltag=tag('relation')
rel=[ e for e in source if e.tag == reltag ]
rel.sort(cmp_id)
an=[ e for e in source if e.tag == antag ]
# Pre-parse begin times
for a in an:
f=a.find(tag('millisecond-fragment'))
if f is not None:
a._begin = long(f.attrib['begin'])
else:
print "Error: cannot find begin time for ", a.attrib['id']
a._begin = 0
an.sort(cmp_time)
for e in an:
dest.append(e)
for e in rel:
dest.append(e)
return dest
开发者ID:eamexicano,项目名称:advene,代码行数:31,代码来源:package_sorter.py
示例19: getItemsXML
def getItemsXML(expedition_id, category_id):
"""
Endpoint to return an XML List of all items associated
with a certain expedition and category
:param expedition_id:
:param category_id:
"""
items = session.query(Item).filter_by(
expedition_id=expedition_id,
category_id=category_id).all()
root = Element('allItems')
comment = Comment('XML Endpoint Listing '
'all Item for a specific Category and Expedition')
root.append(comment)
for i in items:
ex = SubElement(root, 'expedition')
ex.text = i.expedition.title
category_name = SubElement(ex, 'category_name')
category_description = SubElement(category_name,
'category_description')
category_picture = SubElement(category_name, 'category_picture')
category_name.text = i.category.name
category_description.text = i.category.description
category_picture.text = i.category.picture
item_name = SubElement(category_name, 'item_name')
item_decription = SubElement(item_name, 'item_description')
item_picture = SubElement(item_name, 'item_picture')
item_name.text = i.name
item_decription.text = i.description
item_picture.text = i.picture
print tostring(root)
return app.response_class(tostring(root), mimetype='application/xml')
开发者ID:capt-marwil,项目名称:Udacity-Item-Catalog,代码行数:32,代码来源:main.py
示例20: render_documentheader
def render_documentheader(self, standoffheader):
"""Create the documentHeader Element.
Returns
-------
documentheader : ElementTree
Primary element of the primary data document header.
"""
now = datetime.datetime.now()
pubDate = now.strftime("%Y-%m-%d")
documentheader = Element('documentHeader',
{"xmlns": "http://www.xces.org/ns/GrAF/1.0/",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
"docId": "PoioAPI-" + str(random.randint(1, 1000000)),
"version": standoffheader.version,
"creator": getpass.getuser(),
"date.created": pubDate})
filedesc = self.render_filedesc(standoffheader.filedesc)
profiledesc = self.render_profiledesc(standoffheader.profiledesc)
datadesc = self.render_datadesc(standoffheader.datadesc)
profiledesc.append(datadesc.getchildren()[0])
profiledesc.append(datadesc.getchildren()[1])
documentheader.append(filedesc)
documentheader.append(profiledesc)
return documentheader
开发者ID:cidles,项目名称:graf-python,代码行数:32,代码来源:io.py
注:本文中的xml.etree.ElementTree.Element类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论