本文整理汇总了Python中txaws.util.XML.find方法的典型用法代码示例。如果您正苦于以下问题:Python XML.find方法的具体用法?Python XML.find怎么用?Python XML.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txaws.util.XML
的用法示例。
在下文中一共展示了XML.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_console_output
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def get_console_output(self, xml_bytes):
root = XML(xml_bytes)
output_node = root.find("output")
instance_id = root.find("instanceId").text.decode("ascii").strip()
timestamp = parse_timestamp(root.find("timestamp").text)
console_text = output_node.text.decode("base64").decode("utf-8")
return model.ConsoleOutput(
instance_id,
timestamp,
console_text,
)
示例2: from_xml
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def from_xml(cls, xml_bytes):
root = XML(xml_bytes)
owner_node = root.find("Owner")
owner = Owner(owner_node.findtext("ID"),
owner_node.findtext("DisplayName"))
acl_node = root.find("AccessControlList")
acl = []
for grant_node in acl_node.findall("Grant"):
grantee_node = grant_node.find("Grantee")
grantee = Grantee(grantee_node.findtext("ID"),
grantee_node.findtext("DisplayName"))
permission = grant_node.findtext("Permission")
acl.append(Grant(grantee, permission))
return cls(owner, acl)
示例3: describe_instances
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def describe_instances(self, xml_bytes):
"""
Parse the reservations XML payload that is returned from an AWS
describeInstances API call.
Instead of returning the reservations as the "top-most" object, we
return the object that most developers and their code will be
interested in: the instances. In instances reservation is available on
the instance object.
The following instance attributes are optional:
* ami_launch_index
* key_name
* kernel_id
* product_codes
* ramdisk_id
* reason
@param xml_bytes: raw XML payload from AWS.
"""
root = XML(xml_bytes)
results = []
# May be a more elegant way to do this:
for reservation_data in root.find("reservationSet"):
# Create a reservation object with the parsed data.
reservation = model.Reservation(
reservation_id=reservation_data.findtext("reservationId"),
owner_id=reservation_data.findtext("ownerId"))
# Get the list of instances.
instances = self.instances_set(
reservation_data, reservation)
results.extend(instances)
return results
示例4: describe_volumes
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def describe_volumes(self, xml_bytes):
"""Parse the XML returned by the C{DescribeVolumes} function.
@param xml_bytes: XML bytes with a C{DescribeVolumesResponse} root
element.
@return: A list of L{Volume} instances.
TODO: attachementSetItemResponseType#deleteOnTermination
"""
root = XML(xml_bytes)
result = []
for volume_data in root.find("volumeSet"):
volume_id = volume_data.findtext("volumeId")
size = int(volume_data.findtext("size"))
snapshot_id = volume_data.findtext("snapshotId")
availability_zone = volume_data.findtext("availabilityZone")
status = volume_data.findtext("status")
create_time = volume_data.findtext("createTime")
create_time = datetime.strptime(
create_time[:19], "%Y-%m-%dT%H:%M:%S")
volume = model.Volume(
volume_id, size, status, create_time, availability_zone,
snapshot_id)
result.append(volume)
for attachment_data in volume_data.find("attachmentSet"):
instance_id = attachment_data.findtext("instanceId")
device = attachment_data.findtext("device")
status = attachment_data.findtext("status")
attach_time = attachment_data.findtext("attachTime")
attach_time = datetime.strptime(
attach_time[:19], "%Y-%m-%dT%H:%M:%S")
attachment = model.Attachment(
instance_id, device, status, attach_time)
volume.attachments.append(attachment)
return result
示例5: snapshots
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def snapshots(self, xml_bytes):
"""Parse the XML returned by the C{DescribeSnapshots} function.
@param xml_bytes: XML bytes with a C{DescribeSnapshotsResponse} root
element.
@return: A list of L{Snapshot} instances.
TODO: ownersSet, restorableBySet, ownerId, volumeSize, description,
ownerAlias.
"""
root = XML(xml_bytes)
result = []
for snapshot_data in root.find("snapshotSet"):
snapshot_id = snapshot_data.findtext("snapshotId")
volume_id = snapshot_data.findtext("volumeId")
status = snapshot_data.findtext("status")
start_time = snapshot_data.findtext("startTime")
start_time = datetime.strptime(
start_time[:19], "%Y-%m-%dT%H:%M:%S")
progress = snapshot_data.findtext("progress")[:-1]
progress = float(progress or "0") / 100.
snapshot = model.Snapshot(
snapshot_id, volume_id, status, start_time, progress)
result.append(snapshot)
return result
示例6: _parse_describe_availability_zones
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def _parse_describe_availability_zones(self, xml_bytes):
results = []
root = XML(xml_bytes)
for zone_data in root.find("availabilityZoneInfo"):
zone_name = zone_data.findtext("zoneName")
zone_state = zone_data.findtext("zoneState")
results.append(model.AvailabilityZone(zone_name, zone_state))
return results
示例7: _parse_describe_addresses
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def _parse_describe_addresses(self, xml_bytes):
results = []
root = XML(xml_bytes)
for address_data in root.find("addressesSet"):
address = address_data.findtext("publicIp")
instance_id = address_data.findtext("instanceId")
results.append((address, instance_id))
return results
示例8: _parse_terminate_instances
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def _parse_terminate_instances(self, xml_bytes):
root = XML(xml_bytes)
result = []
# May be a more elegant way to do this:
for instance in root.find("instancesSet"):
instanceId = instance.findtext("instanceId")
previousState = instance.find("previousState").findtext("name")
shutdownState = instance.find("shutdownState").findtext("name")
result.append((instanceId, previousState, shutdownState))
return result
示例9: _parse_describe_keypairs
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def _parse_describe_keypairs(self, xml_bytes):
results = []
root = XML(xml_bytes)
keypairs = root.find("keySet")
if not keypairs:
return results
for keypair_data in keypairs:
key_name = keypair_data.findtext("keyName")
key_fingerprint = keypair_data.findtext("keyFingerprint")
results.append(model.Keypair(key_name, key_fingerprint))
return results
示例10: _parse_list_buckets
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def _parse_list_buckets(self, xml_bytes):
"""
Parse XML bucket list response.
"""
root = XML(xml_bytes)
buckets = []
for bucket_data in root.find("Buckets"):
name = bucket_data.findtext("Name")
date_text = bucket_data.findtext("CreationDate")
date_time = parseTime(date_text)
bucket = Bucket(name, date_time)
buckets.append(bucket)
return buckets
示例11: _parse_list_buckets
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def _parse_list_buckets(self, xml_bytes):
"""
Parse XML bucket list response.
"""
root = XML(xml_bytes)
buckets = []
for bucket_data in root.find("Buckets"):
name = bucket_data.findtext("Name")
date_text = bucket_data.findtext("CreationDate")
date_time = Time.fromISO8601TimeAndDate(date_text).asDatetime()
bucket = model.Bucket(name, date_time)
buckets.append(bucket)
return buckets
示例12: _parse_snapshots
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def _parse_snapshots(self, xml_bytes):
root = XML(xml_bytes)
result = []
for snapshot_data in root.find("snapshotSet"):
snapshot_id = snapshot_data.findtext("snapshotId")
volume_id = snapshot_data.findtext("volumeId")
status = snapshot_data.findtext("status")
start_time = snapshot_data.findtext("startTime")
start_time = datetime.strptime(start_time[:19], "%Y-%m-%dT%H:%M:%S")
progress = snapshot_data.findtext("progress")[:-1]
progress = float(progress or "0") / 100.0
snapshot = model.Snapshot(snapshot_id, volume_id, status, start_time, progress)
result.append(snapshot)
return result
示例13: describe_addresses
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def describe_addresses(self, xml_bytes):
"""Parse the XML returned by the C{DescribeAddresses} function.
@param xml_bytes: XML bytes with a C{DescribeAddressesResponse} root
element.
@return: a C{list} of L{tuple} of (publicIp, instancId).
"""
results = []
root = XML(xml_bytes)
for address_data in root.find("addressesSet"):
address = address_data.findtext("publicIp")
instance_id = address_data.findtext("instanceId")
results.append((address, instance_id))
return results
示例14: describe_availability_zones
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def describe_availability_zones(self, xml_bytes):
"""Parse the XML returned by the C{DescribeAvailibilityZones} function.
@param xml_bytes: XML bytes with a C{DescribeAvailibilityZonesResponse}
root element.
@return: a C{list} of L{AvailabilityZone}.
"""
results = []
root = XML(xml_bytes)
for zone_data in root.find("availabilityZoneInfo"):
zone_name = zone_data.findtext("zoneName")
zone_state = zone_data.findtext("zoneState")
results.append(model.AvailabilityZone(zone_name, zone_state))
return results
示例15: describe_keypairs
# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import find [as 别名]
def describe_keypairs(self, xml_bytes):
"""Parse the XML returned by the C{DescribeKeyPairs} function.
@param xml_bytes: XML bytes with a C{DescribeKeyPairsResponse} root
element.
@return: a C{list} of L{Keypair}.
"""
results = []
root = XML(xml_bytes)
keypairs = root.find("keySet")
if keypairs is None:
return results
for keypair_data in keypairs:
key_name = keypair_data.findtext("keyName")
key_fingerprint = keypair_data.findtext("keyFingerprint")
results.append(model.Keypair(key_name, key_fingerprint))
return results