本文整理汇总了Python中xml.etree.ElementTree.XML.getchildren方法的典型用法代码示例。如果您正苦于以下问题:Python XML.getchildren方法的具体用法?Python XML.getchildren怎么用?Python XML.getchildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.ElementTree.XML
的用法示例。
在下文中一共展示了XML.getchildren方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _request
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import getchildren [as 别名]
def _request(method, data=None):
"""Make the raw request to the Prowl API."""
# Catch the errors and treat them just like the normal response.
try:
res = urlopen(API_URL_BASE + method, urlencode(data) if data else None)
except HTTPError as res:
pass
xml = XML(res.read())
if xml.tag != 'prowl':
raise Error('malformed response: unexpected tag %r' % xml.tag)
children = xml.getchildren()
if len(children) != 1:
raise Error('malformed response: too many children')
node = children[0]
status, data, text = node.tag, node.attrib, node.text
if status not in ('success', 'error'):
raise Error('malformed response: unknown status %r' % node.tag)
if 'code' not in node.attrib:
raise Error('malformed response: no response code')
if status == 'error' and not text:
raise Error('malformed response: no error message with code %d' % data['code'])
data = dict((k, int(v)) for k, v in data.items())
_last_meta_data.update(data)
return status, data, text
示例2: getNotifications
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import getchildren [as 别名]
def getNotifications(self, rurl):
"""
Get a list of L{Notification} objects for the specified notification collection.
@param rurl: a user's notification collection URL
@type rurl: L{URL}
"""
assert(isinstance(rurl, URL))
# List all children of the notification collection
results = self.getPropertiesOnHierarchy(rurl, (davxml.getcontenttype,))
items = results.keys()
items.sort()
notifications = []
for path in items:
path = urllib.unquote(path)
nurl = URL(url=path)
if rurl == nurl:
continue
props = results[path]
if props.get(davxml.getcontenttype, "none").split(";")[0] in ("text/xml", "application/xml"):
data, _ignore_etag = self.readData(URL(url=path))
node = XML(data)
if node.tag == str(csxml.notification):
for child in node.getchildren():
if child.tag == str(csxml.invite_notification):
notifications.append(InviteNotification().parseFromNotification(nurl, child))
elif child.tag == str(csxml.invite_reply):
notifications.append(InviteReply().parseFromNotification(nurl, child))
return notifications
示例3: sendNotification
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import getchildren [as 别名]
def sendNotification(key, message, priority=None, url=None, app=None, event=None, providerkey=None):
API_URL_BASE = 'https://api.prowlapp.com/publicapi/'
DEFAULT_PRIORITY = 0
DEFAULT_APP = 'SSHMonitor'
DEFAULT_EVENT = 'default'
data = {
'apikey': key if isinstance(key, basestring) else ','.join(key),
'priority': priority or DEFAULT_PRIORITY,
'application': app or DEFAULT_APP,
'event': event or DEFAULT_EVENT,
'description': message
}
if url is not None:
data['url'] = url
if providerkey is not None:
data['providerkey'] = providerkey
method = 'add'
"""Make the raw request to the Prowl API."""
# Catch the errors and treat them just like the normal response.
try:
res = urlopen(API_URL_BASE + method, urlencode(data) if data else None)
except HTTPError as res:
pass
xml = XML(res.read())
if xml.tag != 'prowl':
raise Error('malformed response: unexpected tag %r' % xml.tag)
children = xml.getchildren()
if len(children) != 1:
raise Error('malformed response: too many children')
node = children[0]
status, data, text = node.tag, node.attrib, node.text
# Unknown status
if status not in ('success', 'error'):
raise Error('malformed response: unknown status %r' % node.tag)
# No response code
if 'code' not in node.attrib:
raise Error('malformed response: no response code')
# No error message with code
if status == 'error' and not text:
raise Error('malformed response: no error message with code %d' % data['code'])
data = dict((k, int(v)) for k, v in data.items())
_last_meta_data.update(data)
示例4: getRequestFromXml
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import getchildren [as 别名]
def getRequestFromXml(self,body):
tree = XML(body)
if 'request' != tree.tag:
raise InputValidationException()
r = record()
for tag in tree.getchildren():
if tag.tag in ['id','mothername']:
setattr(r,tag.tag,tag.text)
if None is getattr(r,'id',None):
raise InputValidationException()
if None is getattr(r,'mothername',None):
raise InputValidationException()
return r
示例5: layers
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import getchildren [as 别名]
def layers(self):
'''get a dict of layer->href'''
url = self.url + 'layers.xml'
headers, response = self.http.request(url, 'GET')
if headers.status != 200: raise Exception('listing failed - %s, %s' %
(headers,response))
# try to resolve layer if already configured
dom = XML(response)
layers = []
for layer in dom.getchildren():
els = layer.getchildren()
layers.append(self.layer(els[0].text))
return layers
示例6: to_dict
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import getchildren [as 别名]
def to_dict(xml):
try:
tree = XML(xml)
tables = tree.getchildren()
L = []
for table in tables:
D = {}
for i in table.keys():
D[i] = table.get(i)
D['text'] = table.text
# for i in table.getchildren():
# D.update({i.tag.lower():i.text})
L.append(D)
return L
except:
return []
示例7: _list_gwc_layers
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import getchildren [as 别名]
def _list_gwc_layers(client=None):
'''get a dict of layer->href'''
if not client:
client = _gwc_client()
url = settings.INTERNAL_GEOSERVER_BASE_URL + 'gwc/rest/layers/'
headers, response = client.request(url, 'GET')
if headers.status != 200: raise Exception('listing failed - %s, %s' %
(headers,response))
# try to resolve layer if already configured
dom = XML(response)
layers = {}
for layer in dom.getchildren():
els = layer.getchildren()
layers[els[0].text] = els[1].get('href')
return layers