本文整理汇总了Python中xml.etree.cElementTree.fromstring方法的典型用法代码示例。如果您正苦于以下问题:Python cElementTree.fromstring方法的具体用法?Python cElementTree.fromstring怎么用?Python cElementTree.fromstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.cElementTree
的用法示例。
在下文中一共展示了cElementTree.fromstring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: XmlToData
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def XmlToData(self, xml):
s = GXDLMSXmlSettings(self.outputType, self.hex, self.showStringAsHex, self.tagsByName)
self.__getAllDataNodes(ET.fromstring(xml).iter(), s)
return s.data
示例2: extract
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def extract(self, xmltext):
"""提取出xml数据包中的加密消息
@param xmltext: 待提取的xml字符串
@return: 提取出的加密消息字符串
"""
try:
xml_tree = ET.fromstring(xmltext)
encrypt = xml_tree.find("Encrypt")
touser_name = xml_tree.find("ToUserName")
return ierror.WXBizMsgCrypt_OK, encrypt.text, touser_name.text
except Exception as e:
print(e)
return ierror.WXBizMsgCrypt_ParseXml_Error, None, None
示例3: __init__
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def __init__(self, etree):
r"""
Initialize a new Element wrapper for ``etree``.
If ``etree`` is a string, then it will be converted to an
Element object using ``ElementTree.fromstring()`` first:
>>> ElementWrapper("<test></test>")
<Element "<?xml version='1.0' encoding='utf8'?>\n<test />">
"""
if isinstance(etree, compat.string_types):
etree = ElementTree.fromstring(etree)
self.__dict__['_etree'] = etree
示例4: list_collection
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def list_collection(self, collection=None, app=None, owner="nobody"):
"""
:collection: collection name. When euqals "None", return all
collections in the system.
:return: a list containing the connection names if successful, throws
KVNotExists if no such colection or other exception if other error
happened
"""
uri = self._get_config_endpoint(app, owner, collection)
content = self._do_request(uri, method="GET")
m = re.search(r'xmlns="([^"]+)"', content)
path = "./entry/title"
if m:
ns = m.group(1)
path = "./{%s}entry/{%s}title" % (ns, ns)
collections = et.fromstring(content)
return [node.text for node in collections.iterfind(path)]
示例5: parse_dbs
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def parse_dbs(folder):
"""
parse the XML dbs and build an in-memory lookup
:param folder: the folder full of *.xml files
:return:
"""
root = None
for filename in glob.glob(folder+'/*.xml'):
with open(filename) as f:
db_string = f.read() # remove the annoying namespace
db_string = re.sub(' xmlns="[^"]+"', '', db_string, count=1)
# xmlstring.append(db_string)
data = ET.fromstring(db_string)
if root is None:
root = data
else:
root.extend(data)
return root
#root = ET.fromstring("\n".join(xmlstring))
# namespace ="http://nvd.nist.gov/feeds/cve/1.2"
示例6: get_packages_swid
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def get_packages_swid(package_list):
"""
Get the packages from a swid string
:param package_strs:
:return:
"""
package_xml = None
packages = defaultdict(set)
errors = []
for xml_doc in package_list.split("\n"):
try:
# remove the <? ?> if any
xml_doc = re.sub('<\?[^>]+\?>', '', xml_doc)
# use DET since this is untrusted data
data = DET.fromstring(xml_doc)
name, version = data.attrib['name'], data.attrib['version']
version = version.split("-")[0]
packages[name].add(version)
except Exception as e:
errors.append(str(e))
return errors, packages
示例7: latest_packages
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def latest_packages(self):
apiurl = self.apiurl
prj = self.from_prj
if prj.startswith('openSUSE.org:'):
apiurl = 'https://api.opensuse.org'
prj = prj[len('openSUSE.org:'):]
data = self.cached_GET(makeurl(apiurl,
['project', 'latest_commits', prj]))
lc = ET.fromstring(data)
packages = set()
for entry in lc.findall('{http://www.w3.org/2005/Atom}entry'):
title = entry.find('{http://www.w3.org/2005/Atom}title').text
if title.startswith('In '):
packages.add(title[3:].split(' ')[0])
return sorted(packages)
示例8: is_maintenance_project
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def is_maintenance_project(self, prj):
root = ET.fromstring(self.get_project_meta(prj))
return root.get('kind', None) == 'maintenance_release'
示例9: meta_get_packagelist
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def meta_get_packagelist(self, prj, deleted=None, expand=False):
root = ET.fromstring(self._meta_get_packagelist(prj, deleted, expand))
return [ node.get('name') for node in root.findall('entry') if not node.get('name') == '000product' and not node.get('name').startswith('patchinfo.') ]
示例10: get_source_infos
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def get_source_infos(self, project, packages):
ret = dict()
for pkg_chunks in chunks(sorted(packages), 50):
root = ET.fromstring(self._get_source_infos(project, pkg_chunks))
for package in root.findall('sourceinfo'):
if package.findall('error'):
continue
ret[package.get('package')] = package
return ret
示例11: _find_existing_request
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def _find_existing_request(self, src_project, src_package, rev, dst_project,
dst_package):
"""Create a submit request."""
states = ['new', 'review', 'declined', 'revoked', 'superseded']
reqs = osc.core.get_exact_request_list(self.apiurl,
src_project,
dst_project,
src_package,
dst_package,
req_type='submit',
req_state=states)
foundrev = False
for r in reqs:
for a in r.actions:
srcrev = a.src_rev
# sometimes requests only contain the decimal revision
if re.match(r'^\d+$', srcrev) is not None:
xml = ET.fromstring(self._get_source_package(src_project, src_package, srcrev))
srcrev = xml.get('verifymd5')
logging.debug('rev {}'.format(srcrev))
if srcrev == rev:
logging.debug('{}: found existing request {} {}/{}'.format(dst_package, r.reqid, a.src_project, src_project))
foundrev = True
return foundrev
示例12: follow_link
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def follow_link(self, project, package, rev, verifymd5):
#print "follow", project, package, rev
# verify it's still the same package
xml = ET.fromstring(self._get_source_package(project, package, rev))
if xml.get('verifymd5') != verifymd5:
return None
xml = ET.fromstring(self.cached_GET(makeurl(self.apiurl,
['source', project, package],
{
'rev': rev
})))
linkinfo = xml.find('linkinfo')
if not linkinfo is None:
ret = self.follow_link(linkinfo.get('project'), linkinfo.get('package'), linkinfo.get('srcmd5'), verifymd5)
if ret:
project, package, rev = ret
return (project, package, rev)
示例13: do_cycle
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def do_cycle(self, subcmd, opts, *args):
"""${cmd_name}: Try to visualize build dependencies between the package list specified
Examples:
osc cycle <pkg1> <pkg2> <pkg3> # outputs a dot file showing the relation between the listed packages
"""
if len(args) == 0:
print("No packages were specified, no chain to draw")
apiurl = self.get_api_url()
print("digraph depgraph {")
args = [pkg.strip() for pkglist in args for pkg in pkglist.split(',') if pkg.strip()]
for pkgname in args:
try:
deps = ET.fromstring(get_dependson(apiurl, opts.project, opts.repository, opts.arch, [pkgname]))
pkg = deps.find('package')
print("\"%s\"" % pkgname)
for deps in pkg.findall('pkgdep'):
if deps.text in args:
print("\"%s\" -> \"%s\"" % (deps.text, pkgname))
except:
# Ignore packages that do not exist
print("[color=red]")
continue
print("}")
示例14: depends_on
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def depends_on(apiurl, project, repository, packages=None, reverse=None):
dependencies = set()
for arch in target_archs(apiurl, project, repository):
root = ET.fromstring(get_dependson(apiurl, project, repository, arch, packages, reverse))
dependencies.update(pkgdep.text for pkgdep in root.findall('.//pkgdep'))
return dependencies
示例15: reset_rebuild_data
# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import fromstring [as 别名]
def reset_rebuild_data(self, project):
data = self.api.pseudometa_file_load('support_pkg_rebuild')
if data is None:
return
root = ET.fromstring(data)
for stg in root.findall('staging'):
if stg.get('name') == project:
stg.find('rebuild').text = 'unknown'
stg.find('supportpkg').text = ''
# reset accepted staging project rebuild state to unknown and clean up
# supportpkg list
content = ET.tostring(root)
if content != data:
self.api.pseudometa_file_save('support_pkg_rebuild', content, 'accept command update')