当前位置: 首页>>代码示例>>Python>>正文


Python util.XML类代码示例

本文整理汇总了Python中txaws.util.XML的典型用法代码示例。如果您正苦于以下问题:Python XML类的具体用法?Python XML怎么用?Python XML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _parse_website_config

    def _parse_website_config(self, xml_bytes):
        """Parse a C{WebsiteConfiguration} XML document."""
        root = XML(xml_bytes)
        index_suffix = root.findtext("IndexDocument/Suffix")
        error_key = root.findtext("ErrorDocument/Key")

        return WebsiteConfiguration(index_suffix, error_key)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:client.py

示例2: _parse_notification_config

    def _parse_notification_config(self, xml_bytes):
        """Parse a C{NotificationConfiguration} XML document."""
        root = XML(xml_bytes)
        topic = root.findtext("TopicConfiguration/Topic")
        event = root.findtext("TopicConfiguration/Event")

        return NotificationConfiguration(topic, event)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:client.py

示例3: snapshots

    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
开发者ID:antisvin,项目名称:txAWS,代码行数:25,代码来源:client.py

示例4: describe_instances

    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
开发者ID:antisvin,项目名称:txAWS,代码行数:33,代码来源:client.py

示例5: describe_volumes

    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
开发者ID:antisvin,项目名称:txAWS,代码行数:35,代码来源:client.py

示例6: _parse_versioning_config

    def _parse_versioning_config(self, xml_bytes):
        """Parse a C{VersioningConfiguration} XML document."""
        root = XML(xml_bytes)
        mfa_delete = root.findtext("MfaDelete")
        status = root.findtext("Status")

        return VersioningConfiguration(mfa_delete=mfa_delete, status=status)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:client.py

示例7: _parse_describe_availability_zones

 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
开发者ID:lzimm,项目名称:360io,代码行数:8,代码来源:client.py

示例8: _parse_describe_addresses

 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
开发者ID:lzimm,项目名称:360io,代码行数:8,代码来源:client.py

示例9: allocate_address

    def allocate_address(self, xml_bytes):
        """Parse the XML returned by the C{AllocateAddress} function.

        @param xml_bytes: XML bytes with a C{AllocateAddress} root element.
        @return: The public ip address as a string.
        """
        address_data = XML(xml_bytes)
        return address_data.findtext("publicIp")
开发者ID:antisvin,项目名称:txAWS,代码行数:8,代码来源:client.py

示例10: truth_return

    def truth_return(self, xml_bytes):
        """Parse the XML for a truth value.

        @param xml_bytes: XML bytes.
        @return: True if the node contains "return" otherwise False.
        """
        root = XML(xml_bytes)
        return root.findtext("return") == "true"
开发者ID:antisvin,项目名称:txAWS,代码行数:8,代码来源:client.py

示例11: parse_receive_message

def parse_receive_message(data):
    result = []
    element = XML(data).find('ReceiveMessageResult')
    for i in element.getchildren():
        receipt = i.findtext('ReceiptHandle').strip()
        body = base64.b64decode(i.findtext('Body'))
        result.append(Message(receipt, body))
    return result
开发者ID:lud4ik,项目名称:txAWS,代码行数:8,代码来源:parser.py

示例12: process_batch_result

def process_batch_result(data, root, success_tag):
    result = []
    element = XML(data).find(root)
    for i in element.getchildren():
        if i.tag == success_tag:
            result.append(True)
        else:
            result.append(False)
    return result
开发者ID:lud4ik,项目名称:txAWS,代码行数:9,代码来源:parser.py

示例13: _parse_terminate_instances

 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
开发者ID:lzimm,项目名称:360io,代码行数:10,代码来源:client.py

示例14: import_keypair

    def import_keypair(self, xml_bytes, key_material):
        """Extract the key name and the fingerprint from the result.

        TODO: there is no corresponding method in the 2009-11-30 version
             of the ec2 wsdl. Delete this?
        """
        keypair_data = XML(xml_bytes)
        key_name = keypair_data.findtext("keyName")
        key_fingerprint = keypair_data.findtext("keyFingerprint")
        return model.Keypair(key_name, key_fingerprint, key_material)
开发者ID:antisvin,项目名称:txAWS,代码行数:10,代码来源:client.py

示例15: parse_queue_attributes

def parse_queue_attributes(data):
    result = {}
    str_attrs = ['Policy', 'QueueArn']
    element = XML(data).find('GetQueueAttributesResult')
    for i in element.getchildren():
        attr = i.findtext('Name').strip()
        value = i.findtext('Value').strip()
        if attr not in str_attrs:
            value = int(value)
        result[attr] = value
    return result
开发者ID:lud4ik,项目名称:txAWS,代码行数:11,代码来源:parser.py


注:本文中的txaws.util.XML类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。