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


Python XML.findall方法代码示例

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


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

示例1: _parse_get_bucket

# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import findall [as 别名]
    def _parse_get_bucket(self, xml_bytes):
        root = XML(xml_bytes)
        name = root.findtext("Name")
        prefix = root.findtext("Prefix")
        marker = root.findtext("Marker")
        max_keys = root.findtext("MaxKeys")
        is_truncated = root.findtext("IsTruncated")
        contents = []

        for content_data in root.findall("Contents"):
            key = content_data.findtext("Key")
            date_text = content_data.findtext("LastModified")
            modification_date = parseTime(date_text)
            etag = content_data.findtext("ETag")
            size = content_data.findtext("Size")
            storage_class = content_data.findtext("StorageClass")
            owner_id = content_data.findtext("Owner/ID")
            owner_display_name = content_data.findtext("Owner/DisplayName")
            owner = ItemOwner(owner_id, owner_display_name)
            content_item = BucketItem(key, modification_date, etag, size,
                                      storage_class, owner)
            contents.append(content_item)

        common_prefixes = []
        for prefix_data in root.findall("CommonPrefixes"):
            common_prefixes.append(prefix_data.text)

        return BucketListing(name, prefix, marker, max_keys, is_truncated,
                             contents, common_prefixes)
开发者ID:ArtRichards,项目名称:txaws,代码行数:31,代码来源:client.py

示例2: describe_security_groups

# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import findall [as 别名]
    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,代码行数:56,代码来源:client.py

示例3: _parse_lifecycle_config

# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import findall [as 别名]
    def _parse_lifecycle_config(self, xml_bytes):
        """Parse a C{LifecycleConfiguration} XML document."""
        root = XML(xml_bytes)
        rules = []

        for content_data in root.findall("Rule"):
            id = content_data.findtext("ID")
            prefix = content_data.findtext("Prefix")
            status = content_data.findtext("Status")
            expiration = int(content_data.findtext("Expiration/Days"))
            rules.append(
                LifecycleConfigurationRule(id, prefix, status, expiration))

        return LifecycleConfiguration(rules)
开发者ID:antisvin,项目名称:txAWS,代码行数:16,代码来源:client.py

示例4: _parse_describe_security_groups

# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import findall [as 别名]
    def _parse_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"):
            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") or []
            for ip_permission in ip_permissions:
                user_id = ip_permission.findtext("groups/item/userId")
                group_name = ip_permission.findtext("groups/item/groupName")
                if user_id and group_name:
                    key = (user_id, group_name)
                    if key not in allowed_groups:
                        user_group_pair = model.UserIDGroupPair(user_id, group_name)
                        allowed_groups.setdefault(user_id, user_group_pair)
                else:
                    ip_protocol = ip_permission.findtext("ipProtocol")
                    from_port = int(ip_permission.findtext("fromPort"))
                    to_port = int(ip_permission.findtext("toPort"))
                    cidr_ip = ip_permission.findtext("ipRanges/item/cidrIp")
                    allowed_ips.append(model.IPPermission(ip_protocol, from_port, to_port, cidr_ip))

            security_group = model.SecurityGroup(
                name, description, owner_id=owner_id, groups=allowed_groups.values(), ips=allowed_ips
            )
            result.append(security_group)
        return result
开发者ID:lzimm,项目名称:360io,代码行数:38,代码来源:client.py

示例5: parse_list_queues

# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import findall [as 别名]
def parse_list_queues(data):
    result = []
    element = XML(data).find('ListQueuesResult')
    for tag in element.findall('QueueUrl'):
        result.append(tag.text.strip())
    return result
开发者ID:lud4ik,项目名称:txAWS,代码行数:8,代码来源:parser.py

示例6: _parse_get_bucket

# 需要导入模块: from txaws.util import XML [as 别名]
# 或者: from txaws.util.XML import findall [as 别名]
            url_context=self._url_context(bucket=bucket, object_name=object_name),
        )
        d = self._submit(self._query_factory(details))
        d.addCallback(self._parse_get_bucket)
        return d

    def _parse_get_bucket(self, (response, xml_bytes)):
        root = XML(xml_bytes)
        name = root.findtext("Name")
        prefix = root.findtext("Prefix")
        marker = root.findtext("Marker")
        max_keys = root.findtext("MaxKeys")
        is_truncated = root.findtext("IsTruncated")
        contents = []

        for content_data in root.findall("Contents"):
            key = content_data.findtext("Key")
            date_text = content_data.findtext("LastModified")
            modification_date = parseTime(date_text)
            etag = content_data.findtext("ETag")
            size = content_data.findtext("Size")
            storage_class = content_data.findtext("StorageClass")
            owner_id = content_data.findtext("Owner/ID")
            owner_display_name = content_data.findtext("Owner/DisplayName")
            owner = ItemOwner(owner_id, owner_display_name)
            content_item = BucketItem(key, modification_date, etag, size,
                                      storage_class, owner)
            contents.append(content_item)

        common_prefixes = []
        for prefix_data in root.findall("CommonPrefixes"):
开发者ID:mithrandi,项目名称:txaws,代码行数:33,代码来源:client.py


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