python类_namespace_map()的实例源码

views.py 文件源码 项目:djangosaml2 作者: knaperek 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def register_namespace_prefixes():
    from saml2 import md, saml, samlp
    try:
        from saml2 import xmlenc
        from saml2 import xmldsig
    except ImportError:
        import xmlenc
        import xmldsig
    prefixes = (('saml', saml.NAMESPACE),
                ('samlp', samlp.NAMESPACE),
                ('md', md.NAMESPACE),
                ('ds', xmldsig.NAMESPACE),
                ('xenc', xmlenc.NAMESPACE))
    if hasattr(ElementTree, 'register_namespace'):
        for prefix, namespace in prefixes:
            ElementTree.register_namespace(prefix, namespace)
    else:
        for prefix, namespace in prefixes:
            ElementTree._namespace_map[namespace] = prefix
__init__.py 文件源码 项目:deb-python-pysaml2 作者: openstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def register_prefix(self, nspair):
        """
        Register with ElementTree a set of namespaces

        :param nspair: A dictionary of prefixes and uris to use when
            constructing the text representation.
        :return:
        """
        for prefix, uri in nspair.items():
            try:
                ElementTree.register_namespace(prefix, uri)
            except AttributeError:
                # Backwards compatibility with ET < 1.3
                ElementTree._namespace_map[uri] = prefix
            except ValueError:
                pass
views.py 文件源码 项目:penndjangosaml2 作者: wharton 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def register_namespace_prefixes():
    from saml2 import md, saml, samlp
    try:
        from saml2 import xmlenc
        from saml2 import xmldsig
    except ImportError:
        import xmlenc
        import xmldsig
    prefixes = (('saml', saml.NAMESPACE),
                ('samlp', samlp.NAMESPACE),
                ('md', md.NAMESPACE),
                ('ds', xmldsig.NAMESPACE),
                ('xenc', xmlenc.NAMESPACE))
    if hasattr(ElementTree, 'register_namespace'):
        for prefix, namespace in prefixes:
            ElementTree.register_namespace(prefix, namespace)
    else:
        for prefix, namespace in prefixes:
            ElementTree._namespace_map[namespace] = prefix
test_xml_etree.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __enter__(self):
        from xml.etree import ElementTree
        self._nsmap = ElementTree._namespace_map
        self._path_cache = ElementTree.ElementPath._cache
        # Copy the default namespace mapping
        ElementTree._namespace_map = self._nsmap.copy()
        # Copy the path cache (should be empty)
        ElementTree.ElementPath._cache = self._path_cache.copy()
        self.checkwarnings.__enter__()
test_xml_etree.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __exit__(self, *args):
        from xml.etree import ElementTree
        # Restore mapping and path cache
        ElementTree._namespace_map = self._nsmap
        ElementTree.ElementPath._cache = self._path_cache
        self.checkwarnings.__exit__(*args)
test_xml_etree.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __enter__(self):
        from xml.etree import ElementTree
        self._nsmap = ElementTree._namespace_map
        self._path_cache = ElementTree.ElementPath._cache
        # Copy the default namespace mapping
        ElementTree._namespace_map = self._nsmap.copy()
        # Copy the path cache (should be empty)
        ElementTree.ElementPath._cache = self._path_cache.copy()
        self.checkwarnings.__enter__()
test_xml_etree.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __exit__(self, *args):
        from xml.etree import ElementTree
        # Restore mapping and path cache
        ElementTree._namespace_map = self._nsmap
        ElementTree.ElementPath._cache = self._path_cache
        self.checkwarnings.__exit__(*args)
test_xml_etree.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __enter__(self):
        from xml.etree import ElementTree
        self._nsmap = ElementTree._namespace_map
        self._path_cache = ElementTree.ElementPath._cache
        # Copy the default namespace mapping
        ElementTree._namespace_map = self._nsmap.copy()
        # Copy the path cache (should be empty)
        ElementTree.ElementPath._cache = self._path_cache.copy()
        self.checkwarnings.__enter__()
test_xml_etree.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __exit__(self, *args):
        from xml.etree import ElementTree
        # Restore mapping and path cache
        ElementTree._namespace_map = self._nsmap
        ElementTree.ElementPath._cache = self._path_cache
        self.checkwarnings.__exit__(*args)
xml_.py 文件源码 项目:ryu-lagopus-ext 作者: lagopus 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def register_namespace(prefix, uri):
        from xml.etree import ElementTree
        # cElementTree uses ElementTree's _namespace_map, so that's ok
        ElementTree._namespace_map[uri] = prefix
test_xml_etree.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __enter__(self):
        from xml.etree import ElementTree
        self._nsmap = ElementTree._namespace_map
        self._path_cache = ElementTree.ElementPath._cache
        # Copy the default namespace mapping
        ElementTree._namespace_map = self._nsmap.copy()
        # Copy the path cache (should be empty)
        ElementTree.ElementPath._cache = self._path_cache.copy()
        self.checkwarnings.__enter__()
test_xml_etree.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __exit__(self, *args):
        from xml.etree import ElementTree
        # Restore mapping and path cache
        ElementTree._namespace_map = self._nsmap
        ElementTree.ElementPath._cache = self._path_cache
        self.checkwarnings.__exit__(*args)
test_xml_etree.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __enter__(self):
        from xml.etree import ElementTree
        self._nsmap = ElementTree._namespace_map
        self._path_cache = ElementTree.ElementPath._cache
        # Copy the default namespace mapping
        ElementTree._namespace_map = self._nsmap.copy()
        # Copy the path cache (should be empty)
        ElementTree.ElementPath._cache = self._path_cache.copy()
        self.checkwarnings.__enter__()
test_xml_etree.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __exit__(self, *args):
        from xml.etree import ElementTree
        # Restore mapping and path cache
        ElementTree._namespace_map = self._nsmap
        ElementTree.ElementPath._cache = self._path_cache
        self.checkwarnings.__exit__(*args)
xml_etree_elementtree.py 文件源码 项目:python-xml 作者: emusical 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def lookup_ns_prefix_for_uri(self, node, uri):
        if uri == nodes.Node.XMLNS_URI:
            return 'xmlns'
        result = None
        # Lookup namespace URI in ET's awful global namespace/prefix registry
        if hasattr(BaseET, '_namespace_map') and uri in BaseET._namespace_map:
            result = BaseET._namespace_map[uri]
            if result == '':
                result = None
        if result is None or re.match('ns\d', result):
            # We either have no namespace prefix in the global mapping, in
            # which case we will try looking for a matching xmlns attribute,
            # or we have a namespace prefix that was probably assigned
            # automatically by ElementTree and we'd rather use a
            # human-assigned prefix if available.
            curr_node = node
            while self._is_node_an_element(curr_node):
                for n, v in curr_node.attrib.items():
                    if v == uri:
                        if n.startswith('xmlns:'):
                            result = n.split(':')[1]
                            return result
                        elif n.startswith('{%s}' % nodes.Node.XMLNS_URI):
                            result = n.split('}')[1]
                            return result
                curr_node = self.get_node_parent(curr_node)
        return result


问题


面经


文章

微信
公众号

扫码关注公众号