• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.XML类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: from_xml

    def from_xml(cls, xml_bytes):
        """
        Create an instance of this from XML bytes.

        @param xml_bytes: C{str} bytes of XML to parse
        @return: an instance of L{MultipartInitiationResponse}
        """
        root = XML(xml_bytes)
        return cls(root.findtext('Bucket'),
                   root.findtext('Key'),
                   root.findtext('UploadId'))
开发者ID:mithrandi,项目名称:txaws,代码行数:11,代码来源:model.py


示例17: _parse_describe_keypairs

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


示例18: get_console_output

 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,
     )
开发者ID:oubiwann,项目名称:txaws,代码行数:11,代码来源:client.py


示例19: describe_security_groups

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

        @param xml_bytes: XML bytes with a C{DescribeSecurityGroupsResponse}
            root element.
        @return: A list of L{SecurityGroup} instances.
        """
        root = XML(xml_bytes)
        result = []
        for group_info in root.findall("securityGroupInfo/item"):
            id = group_info.findtext("groupId")
            name = group_info.findtext("groupName")
            description = group_info.findtext("groupDescription")
            owner_id = group_info.findtext("ownerId")
            allowed_groups = []
            allowed_ips = []
            ip_permissions = group_info.find("ipPermissions")
            if ip_permissions is None:
                ip_permissions = ()
            for ip_permission in ip_permissions:

                # openstack doesn't handle self authorized groups properly
                # XXX this is an upstream problem and should be addressed there
                # lp bug #829609
                ip_protocol = ip_permission.findtext("ipProtocol")
                from_port = ip_permission.findtext("fromPort")
                to_port = ip_permission.findtext("toPort")

                if from_port:
                    from_port = int(from_port)

                if to_port:
                    to_port = int(to_port)

                for groups in ip_permission.findall("groups/item") or ():
                    user_id = groups.findtext("userId")
                    group_name = groups.findtext("groupName")
                    if user_id and group_name:
                        if (user_id, group_name) not in allowed_groups:
                            allowed_groups.append((user_id, group_name))
                for ip_ranges in ip_permission.findall("ipRanges/item") or ():
                    cidr_ip = ip_ranges.findtext("cidrIp")
                    allowed_ips.append(
                        model.IPPermission(
                            ip_protocol, from_port, to_port, cidr_ip))

            allowed_groups = [model.UserIDGroupPair(user_id, group_name)
                              for user_id, group_name in allowed_groups]

            security_group = model.SecurityGroup(
                id, name, description, owner_id=owner_id,
                groups=allowed_groups, ips=allowed_ips)
            result.append(security_group)
        return result
开发者ID:antisvin,项目名称:txAWS,代码行数:54,代码来源:client.py


示例20: create_keypair

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

        @param xml_bytes: XML bytes with a C{CreateKeyPairResponse} root
            element.
        @return: The L{Keypair} instance created.
        """
        keypair_data = XML(xml_bytes)
        key_name = keypair_data.findtext("keyName")
        key_fingerprint = keypair_data.findtext("keyFingerprint")
        key_material = keypair_data.findtext("keyMaterial")
        return model.Keypair(key_name, key_fingerprint, key_material)
开发者ID:antisvin,项目名称:txAWS,代码行数:12,代码来源:client.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python config.OrderedRawConfigParser类代码示例发布时间:2022-05-27
下一篇:
Python service.AWSServiceEndpoint类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap