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


Python etree.register_namespace方法代码示例

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


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

示例1: format

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def format(self, diff, orig_tree, differ=None):
        # Make a new tree, both because we want to add the diff namespace
        # and also because we don't want to modify the original tree.
        result = deepcopy(orig_tree)
        if isinstance(result, etree._ElementTree):
            root = result.getroot()
        else:
            root = result

        etree.register_namespace(DIFF_PREFIX, DIFF_NS)

        for action in diff:
            self.handle_action(action, root)

        self.finalize(root)

        etree.cleanup_namespaces(result, top_nsmap={DIFF_PREFIX: DIFF_NS})
        return self.render(result) 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:20,代码来源:formatting.py

示例2: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self):
        """
        Constructor.
        Defines the "--name" option of a script.
        """
        # Call the base class constructor.
        inkex.Effect.__init__(self)
        #import matplotlib
        #Define string option "--name" with "-n" shortcut and default value "World".
        self.arg_parser.add_argument('-n', '--name', action = 'store',
          type = str, dest = 'name', default = 'none',
          help = 'Name group')
        inkex.NSS[u"figurefirst"] = u"http://flyranch.github.io/figurefirst/"
        try:
            etree.register_namespace("figurefirst","http://flyranch.github.io/figurefirst/")
        except AttributeError:
            #inkex.etree._NamespaceRegistry.update(inkex.addNS("name", "figurefirst"))
            #This happens on windows version of inkscape - it might be good to check
            #and see if the namespace has been correctly added to the document
            pass 
开发者ID:FlyRanch,项目名称:figurefirst,代码行数:22,代码来源:tag_group.py

示例3: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self):
        """
        Constructor.
        Defines the "--name" option of a script.
        """
        # Call the base class constructor.
        inkex.Effect.__init__(self)
        #import matplotlib
        #Define string option "--name" with "-n" shortcut and default value "World".
        self.arg_parser.add_argument('-n', '--name', action = 'store',
          type = str, dest = 'name', default = 'none',
          help = 'Name linespec')
        inkex.NSS[u"figurefirst"] = u"http://flyranch.github.io/figurefirst/"
        try:
            etree.register_namespace("figurefirst","http://flyranch.github.io/figurefirst/")
        except AttributeError:
            #inkex.etree._NamespaceRegistry.update(inkex.addNS("name", "figurefirst"))
            #This happens on windows version of inkscape - it might be good to check
            #and see if the namespace has been correctly added to the document
            pass 
开发者ID:FlyRanch,项目名称:figurefirst,代码行数:22,代码来源:tag_linespec.py

示例4: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self):
        """
        Constructor.
        Defines the "--name" option of a script.
        """
        # Call the base class constructor.
        inkex.Effect.__init__(self)
        #import matplotlib
        #Define string option "--name" with "-n" shortcut and default value "World".
        self.arg_parser.add_argument('-n', '--name', action = 'store',
          type =str, dest = 'name', default = 'none',
          help = 'Name figure')
        self.arg_parser.add_argument('-t', '--template', action = 'store',
          type = str, dest = 'template', default = 'none',
          help = 'Name template (optional)')
        inkex.NSS[u"figurefirst"] = u"http://flyranch.github.io/figurefirst/"
        try:
            etree.register_namespace("figurefirst","http://flyranch.github.io/figurefirst/")
        except AttributeError:
            #inkex.etree._NamespaceRegistry.update(inkex.addNS("name", "figurefirst"))
            #This happens on windows version of inkscape - it might be good to check
            #and see if the namespace has been correctly added to the document
            pass 
开发者ID:FlyRanch,项目名称:figurefirst,代码行数:25,代码来源:tag_figure.py

示例5: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self):
        """
        Constructor.
        Defines the "--spinespec" option of a script.
        """
        # Call the base class constructor.
        inkex.Effect.__init__(self)
        #import matplotlib
        #Define string option "--spinespec" with "-sp" shortcut and default value "left,bottom".
        self.arg_parser.add_argument('-s', '--spinespec', action = 'store',
          type =str, dest = 'spinespec', default = 'left,bottom',
          help = "Add a spine specification as a comma separated list of spine locations. \n Valid values are: top,bottom,right or left")
        inkex.NSS[u"figurefirst"] = u"http://flyranch.github.io/figurefirst/"
        try:
            etree.register_namespace("figurefirst","http://flyranch.github.io/figurefirst/")
        except AttributeError:
            #inkex.etree._NamespaceRegistry.update(inkex.addNS("name", "figurefirst"))
            #This happens on windows version of inkscape - it might be good to check
            #and see if the namespace has been correctly added to the document
            pass 
开发者ID:FlyRanch,项目名称:figurefirst,代码行数:22,代码来源:tag_spinespec.py

示例6: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self):
        """
        Constructor.
        Defines the "--name" option of a script.
        """
        # Call the base class constructor.
        inkex.Effect.__init__(self)
        #Define string option "--mplmethod" with "-m" shortcut and default value "none".
        self.arg_parser.add_argument('-m', '--mplmethod', action = 'store',
          type = str, dest = 'mplmethod', default = 'none',
          help = 'Method name')
        #Define string option "--mplmethodarg" with "-z" shortcut and default value "none".
        self.arg_parser.add_argument('-a', '--mplmethodarg', action = 'store',
          type = str, dest = 'mplmethodarg', default = 'none',
          help = 'Method arguments')
        inkex.NSS[u"figurefirst"] = u"http://flyranch.github.io/figurefirst/"
        try:
            etree.register_namespace("figurefirst","http://flyranch.github.io/figurefirst/")
        except AttributeError:
            #inkex.etree._NamespaceRegistry.update(inkex.addNS("name", "figurefirst"))
            #This happens on windows version of inkscape - it might be good to check
            #and see if the namespace has been correctly added to the document
            pass 
开发者ID:FlyRanch,项目名称:figurefirst,代码行数:25,代码来源:tag_mplmethods.py

示例7: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self):
        """
        Constructor.
        Defines the "--name" option of a script.
        """
        # Call the base class constructor.
        inkex.Effect.__init__(self)
        #import matplotlib
        #Define string option "--name" with "-n" shortcut and default value "World".
        self.arg_parser.add_argument('-n', '--name', action = 'store',
          type = str, dest = 'name', default = 'none',
          help = 'Name patch')
        inkex.NSS[u"figurefirst"] = u"http://flyranch.github.io/figurefirst/"
        try:
            etree.register_namespace("figurefirst","http://flyranch.github.io/figurefirst/")
        except AttributeError:
            #inkex.etree._NamespaceRegistry.update(inkex.addNS("name", "figurefirst"))
            #This happens on windows version of inkscape - it might be good to check
            #and see if the namespace has been correctly added to the document
            pass 
开发者ID:FlyRanch,项目名称:figurefirst,代码行数:22,代码来源:tag_patchspec.py

示例8: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self):
        """
        Constructor.
        Defines the "--name" option of a script.
        """
        # Call the base class constructor.
        inkex.Effect.__init__(self)
        #import matplotlib
        #Define string option "--name" with "-n" shortcut and default value "World".
        self.arg_parser.add_argument('-n', '--name', action = 'store',
          type = str, dest = 'name', default = 'none',
          help = 'Name axis')
        inkex.NSS[u"figurefirst"] = u"http://flyranch.github.io/figurefirst/"
        try:
            etree.register_namespace("figurefirst","http://flyranch.github.io/figurefirst/")
        except AttributeError:
            #inkex.etree._NamespaceRegistry.update(inkex.addNS("name", "figurefirst"))
            #This happens on windows version of inkscape - it might be good to check
            #and see if the namespace has been correctly added to the document
            pass 
开发者ID:FlyRanch,项目名称:figurefirst,代码行数:22,代码来源:tag_axis.py

示例9: to_etree

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def to_etree(self, source):
        etree.register_namespace("junos", NS_JUNOS)

        configuration = {
            XML_NS: 'http://xml.juniper.net/xnm/1.1/xnm',
            XML_ATTRIBUTES: {
                "xmlns":"http://xml.juniper.net/xnm/1.1/xnm",
                "{" + NS_JUNOS + "}commit-seconds": "1411928899",
                "{" + NS_JUNOS + "}commit-localtime": "2014-09-28 14:28:19 EDT",
                "{" + NS_JUNOS + "}commit-user": "admin"
            }
        }

        _add_if_not_empty(configuration, "interfaces", self._extract_interfaces(self.configurations[source]))

        _add_if_not_empty(configuration, "protocols", self._extract_protocols(self.configurations[source]))

        _add_if_not_empty(configuration, self.VLANS_COLLECTION,
                         [{self.VLANS_COLLECTION_OBJ: self.vlan_to_etree(vlan)} for vlan in self.configurations[source].vlans])

        return dict_2_etree({"data": {"configuration": configuration}}) 
开发者ID:internap,项目名称:fake-switches,代码行数:23,代码来源:juniper_netconf_datastore.py

示例10: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self, *args, **kwargs):
        ET.register_namespace("svg", self._SVG_namespace)
        super(SvgFragmentImage, self).__init__(*args, **kwargs)
        # Save the unit size, for example the default box_size of 10 is '1mm'.
        self.unit_size = self.units(self.box_size) 
开发者ID:tp4a,项目名称:teleport,代码行数:7,代码来源:svg.py

示例11: test_rml_bug

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def test_rml_bug(self):
        etree.register_namespace(formatting.DIFF_PREFIX, formatting.DIFF_NS)
        before_diff = u"""<document xmlns:diff="http://namespaces.shoobx.com/diff">
  <section>
    <para>
      <ref>4</ref>.
      <u><b>At Will Employment</b></u>
      .\u201cText\u201d
    </para>
  </section>
</document>"""
        tree = etree.fromstring(before_diff)
        replacer = formatting.PlaceholderMaker(
            text_tags=('para',), formatting_tags=('b', 'u', 'i',))
        replacer.do_tree(tree)
        after_diff = u"""<document xmlns:diff="http://namespaces.shoobx.com/diff">
  <section>
    <para>
      <insert>\ue005</insert>.
      \ue007\ue009At Will Employment\ue008\ue006
      .\u201c<insert>New </insert>Text\u201d
    </para>
  </section>
</document>"""

        # The diff formatting will find some text to insert.
        delete_attrib = u'{%s}delete-format' % formatting.DIFF_NS
        replacer.placeholder2tag[u'\ue006'
                                 ].element.attrib[delete_attrib] = ''
        replacer.placeholder2tag[u'\ue007'
                                 ].element.attrib[delete_attrib] = ''
        tree = etree.fromstring(after_diff)
        replacer.undo_tree(tree)
        result = etree.tounicode(tree)
        expected = u"""<document xmlns:diff="http://namespaces.shoobx.com/diff">
  <section>
    <para>
      <insert><ref>4</ref></insert>.
      <u diff:delete-format=""><b>At Will Employment</b></u>
      .\u201c<insert>New </insert>Text\u201d
    </para>
  </section>
</document>"""
        self.assertEqual(result, expected) 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:46,代码来源:test_formatting.py

示例12: __init__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import register_namespace [as 别名]
def __init__(self, test_name, server, port, username, password, ssl, path,
                 auth):
        """
        This is a fake transport stub that takes in known requests and responds
        back with the already created response. This is used in cases when a
        real WinRM endpoint is not available or a fake one was requested for
        a predefined apth

        :param test_name: The name of the test which is used to get the
            messages to send to the server
        """
        self.server = server
        self.port = port
        self.username = username
        self.password = password
        self.ssl = ssl
        self.path = path
        self.auth = auth
        self.endpoint = "%s://%s:%d/%s" \
                        % ("https" if ssl else "http", server, port, path)
        self.session = None

        # used in the test only
        for key, value in NAMESPACES.items():
            ET.register_namespace(key, value)

        self._uuid_pattern = re.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]"
                                        "{4}-[0-9a-f]{4}-[0-9a-f]{12}", re.I)
        self._test_name = test_name
        self._msg_counter = 0
        self._psrp_fragments = {}  # used to store PSRP fragments as they come in
        meta_path = os.path.join(os.path.dirname(__file__),
                                 'responses/%s.yml' % test_name)

        if os.path.exists(meta_path):
            with open(meta_path, 'rb') as o:
                self._test_meta = yaml.load(o)
        else:
            raise Exception("Test metadata yml file does not exist at %s"
                            % meta_path)

        # override the messages used if a particular python version is set
        # lxml serializes messages a bit differently which is quite
        # problemtatic for the PSRP messages embeded in the WSMAN bodies
        current_version = "%s%s" % (sys.version_info[0], sys.version_info[1])
        node_entries = self._test_meta.keys()
        if "messages-py%s" % current_version in node_entries:
            self._test_msg_key = "messages-py%s" % current_version
        else:
            self._test_msg_key = "messages" 
开发者ID:jborean93,项目名称:pypsrp,代码行数:52,代码来源:conftest.py


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