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


Python etree.Comment方法代码示例

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


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

示例1: collect_inserts_aux

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def collect_inserts_aux(child, params, inserts, options):
    roots = []
    save_base_url = params.base_url
    string_content = resolve_ref(child, params, options)
    if string_content is not None:
        root = etree.fromstring(string_content, base_url=params.base_url)
        roots.append(root)
        for child1 in root:
            if not isinstance(child1, etree._Comment):
                namespace = child1.nsmap[child1.prefix]
                if (child1.tag != '{%s}include' % (namespace, ) and
                        child1.tag != '{%s' % (namespace, )):
                    comment = etree.Comment(etree.tostring(child))
                    comment.tail = '\n'
                    inserts.append(comment)
                    inserts.append(child1)
        insert_roots = collect_inserts(root, params, inserts, options)
        roots.extend(insert_roots)
    params.base_url = save_base_url
    return roots 
开发者ID:nyoka-pmml,项目名称:nyoka,代码行数:22,代码来源:process_includes.py

示例2: _extract_composition

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def _extract_composition(element, spec):
    """
    Parse XML spec to extract the composition of a nested structure (Component, Group or MsgType)
    """
    returned = []
    for elem in list(element):
        if elem.tag == "field":
            returned.append((spec.tags.by_name(elem.get('name')),
                             elem.get('required') == "Y"))
        elif elem.tag == 'component':
            returned.append((Component(elem, spec), elem.get('required') == "Y"))
        elif elem.tag == 'group':
            returned.append((Group.from_element(elem, spec), elem.get('required') == "Y"))
        elif (parse.__module__ == 'lxml.etree') and (elem.tag == Comment):
            pass
        else:
            raise ValueError("Could not process element '{}'".format(elem.tag))
    return returned 
开发者ID:Morgan-Stanley,项目名称:pyfixmsg,代码行数:20,代码来源:reference.py

示例3: getNodeDetails

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def getNodeDetails(self, node):
        if isinstance(node, tuple):  # Text node
            node, key = node
            assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
            return base.TEXT, ensure_str(getattr(node, key))

        elif isinstance(node, Root):
            return (base.DOCUMENT,)

        elif isinstance(node, Doctype):
            return base.DOCTYPE, node.name, node.public_id, node.system_id

        elif isinstance(node, FragmentWrapper) and not hasattr(node, "tag"):
            return base.TEXT, ensure_str(node.obj)

        elif node.tag == etree.Comment:
            return base.COMMENT, ensure_str(node.text)

        elif node.tag == etree.Entity:
            return base.ENTITY, ensure_str(node.text)[1:-1]  # strip &;

        else:
            # This is assumed to be an ordinary element
            match = tag_regexp.match(ensure_str(node.tag))
            if match:
                namespace, tag = match.groups()
            else:
                namespace = None
                tag = ensure_str(node.tag)
            attrs = {}
            for name, value in list(node.attrib.items()):
                name = ensure_str(name)
                value = ensure_str(value)
                match = tag_regexp.match(name)
                if match:
                    attrs[(match.group(1), match.group(2))] = value
                else:
                    attrs[(None, name)] = value
            return (base.ELEMENT, namespace, self.filter.fromXmlName(tag),
                    attrs, len(node) > 0 or node.text) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:42,代码来源:etree_lxml.py

示例4: export_xml_to_directory

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def export_xml_to_directory(self, elem):
        '''
        Do this recursively.  If an element is a descriptor, then put that in its own
        subdirectory.
        '''
        def write_xml(x):
            un = x.get('url_name')
            if un is None:
                self.errlog("Oops!  error in export_xml_to_directory, missing url_name:")
                self.errlog(x)
            elem.attrib.pop('url_name')
            if 'url_name_orig' in elem.attrib and self.keep_urls:
                elem.attrib.pop('url_name_orig')
            edir = self.mkdir(self.dir / x.tag)
            open(edir/un + '.xml','w').write(self.pp_xml(x))
            return un

        #print elem
        if elem.tag=='descriptor':
            # print "--> %s" % list(elem)
            self.export_xml_to_directory(elem[0])	# recurse on children, depth first
            elem.tag = elem.get('tag')
            elem.set('url_name',elem.get('url_name'))
            elem.attrib.pop('tag')
            # self.export_xml_to_directory(elem)	# recurse on this tag

        elif elem.tag==etree.Comment:			# comment <!-- foo -->
            pass

        elif elem.get('url_name') is None:
            pass

        else:
            if elem.findall('.//descriptor'):
                for k in elem:
                    self.export_xml_to_directory(k)		# recurse on children
            write_xml(elem)		                # write to file and remove from parent
            elem.getparent().remove(elem) 
开发者ID:mitodl,项目名称:edx2bigquery,代码行数:40,代码来源:xbundle.py

示例5: getNodeDetails

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def getNodeDetails(self, node):
        if isinstance(node, tuple):  # Text node
            node, key = node
            assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
            return _base.TEXT, ensure_str(getattr(node, key))

        elif isinstance(node, Root):
            return (_base.DOCUMENT,)

        elif isinstance(node, Doctype):
            return _base.DOCTYPE, node.name, node.public_id, node.system_id

        elif isinstance(node, FragmentWrapper) and not hasattr(node, "tag"):
            return _base.TEXT, node.obj

        elif node.tag == etree.Comment:
            return _base.COMMENT, ensure_str(node.text)

        elif node.tag == etree.Entity:
            return _base.ENTITY, ensure_str(node.text)[1:-1]  # strip &;

        else:
            # This is assumed to be an ordinary element
            match = tag_regexp.match(ensure_str(node.tag))
            if match:
                namespace, tag = match.groups()
            else:
                namespace = None
                tag = ensure_str(node.tag)
            attrs = {}
            for name, value in list(node.attrib.items()):
                name = ensure_str(name)
                value = ensure_str(value)
                match = tag_regexp.match(name)
                if match:
                    attrs[(match.group(1), match.group(2))] = value
                else:
                    attrs[(None, name)] = value
            return (_base.ELEMENT, namespace, self.filter.fromXmlName(tag),
                    attrs, len(node) > 0 or node.text) 
开发者ID:jpush,项目名称:jbox,代码行数:42,代码来源:lxmletree.py

示例6: getNodeDetails

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def getNodeDetails(self, node):
        if isinstance(node, tuple):  # Text node
            node, key = node
            assert key in ("text", "tail"), _("Text nodes are text or tail, found %s") % key
            return _base.TEXT, ensure_str(getattr(node, key))

        elif isinstance(node, Root):
            return (_base.DOCUMENT,)

        elif isinstance(node, Doctype):
            return _base.DOCTYPE, node.name, node.public_id, node.system_id

        elif isinstance(node, FragmentWrapper) and node.isstring:
            return _base.TEXT, node.obj

        elif node.tag == etree.Comment:
            return _base.COMMENT, ensure_str(node.text)

        elif node.tag == etree.Entity:
            return _base.ENTITY, ensure_str(node.text)[1:-1]  # strip &;

        else:
            # This is assumed to be an ordinary element
            match = tag_regexp.match(ensure_str(node.tag))
            if match:
                namespace, tag = match.groups()
            else:
                namespace = None
                tag = ensure_str(node.tag)
            attrs = {}
            for name, value in list(node.attrib.items()):
                name = ensure_str(name)
                value = ensure_str(value)
                match = tag_regexp.match(name)
                if match:
                    attrs[(match.group(1), match.group(2))] = value
                else:
                    attrs[(None, name)] = value
            return (_base.ELEMENT, namespace, self.filter.fromXmlName(tag),
                    attrs, len(node) > 0 or node.text) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:42,代码来源:lxmletree.py

示例7: clear_includes_and_imports

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def clear_includes_and_imports(node):
    namespace = node.nsmap[node.prefix]
    child_iter1 = node.iterfind('{%s}include' % (namespace, ))
    child_iter2 = node.iterfind('{%s}import' % (namespace, ))
    for child in itertools.chain(child_iter1, child_iter2):
        repl = etree.Comment(etree.tostring(child))
        repl.tail = '\n'
        node.replace(child, repl) 
开发者ID:nyoka-pmml,项目名称:nyoka,代码行数:10,代码来源:process_includes.py

示例8: getNodeDetails

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def getNodeDetails(self, node):
        if isinstance(node, tuple): # Text node
            node, key = node
            assert key in ("text", "tail"), _("Text nodes are text or tail, found %s") % key
            return _base.TEXT, getattr(node, key)

        elif isinstance(node, Root):
            return (_base.DOCUMENT,)

        elif isinstance(node, Doctype):
            return _base.DOCTYPE, node.name, node.public_id, node.system_id

        elif isinstance(node, FragmentWrapper) and node.isstring:
            return _base.TEXT, node

        elif node.tag == etree.Comment:
            return _base.COMMENT, node.text

        elif node.tag == etree.Entity:
            return _base.ENTITY, node.text[1:-1] # strip &;

        else:
            #This is assumed to be an ordinary element
            match = tag_regexp.match(node.tag)
            if match:
                namespace, tag = match.groups()
            else:
                namespace = None
                tag = node.tag
            attrs = {}
            for name, value in node.attrib.items():
                match = tag_regexp.match(name)
                if match:
                    attrs[(match.group(1),match.group(2))] = value
                else:
                    attrs[(None,name)] = value
            return (_base.ELEMENT, namespace, self.filter.fromXmlName(tag), 
                    attrs, len(node) > 0 or node.text) 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:40,代码来源:lxmletree.py

示例9: container

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def container(self, node, elem, module, path):
        """Create a sample container element and proceed with its children."""
        nel, newm, path = self.sample_element(node, elem, module, path)
        if path is None:
            return
        if self.annots:
            pres = node.search_one("presence")
            if pres is not None:
                nel.append(etree.Comment(" presence: %s " % pres.arg))
        self.process_children(node, nel, newm, path) 
开发者ID:mbj4668,项目名称:pyang,代码行数:12,代码来源:sample-xml-skeleton.py

示例10: leaf

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def leaf(self, node, elem, module, path):
        """Create a sample leaf element."""
        if node.i_default is None:
            nel, newm, path = self.sample_element(node, elem, module, path)
            if path is None:
                return
            if self.annots:
                nel.append(etree.Comment(
                    " type: %s " % node.search_one("type").arg))
        elif self.defaults:
            nel, newm, path = self.sample_element(node, elem, module, path)
            if path is None:
                return
            nel.text = str(node.i_default_str) 
开发者ID:mbj4668,项目名称:pyang,代码行数:16,代码来源:sample-xml-skeleton.py

示例11: anyxml

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def anyxml(self, node, elem, module, path):
        """Create a sample anyxml element."""
        nel, newm, path = self.sample_element(node, elem, module, path)
        if path is None:
            return
        if self.annots:
            nel.append(etree.Comment(" anyxml ")) 
开发者ID:mbj4668,项目名称:pyang,代码行数:9,代码来源:sample-xml-skeleton.py

示例12: list_comment

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def list_comment(self, node, elem, minel):
        """Add list annotation to `elem`."""
        lo = "0" if minel is None else minel.arg
        maxel = node.search_one("max-elements")
        hi = "" if maxel is None else maxel.arg
        elem.insert(0, etree.Comment(
            " # entries: %s..%s " % (lo, hi)))
        if node.keyword == 'list':
            elem.insert(0, etree.Comment(
                " # keys: " + ",".join([k.arg for k in node.i_key]))) 
开发者ID:mbj4668,项目名称:pyang,代码行数:12,代码来源:sample-xml-skeleton.py

示例13: _handle_InsertComment

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def _handle_InsertComment(self, action, tree):
        target = tree.xpath(action.target)[0]
        target.insert(action.position, etree.Comment(action.text)) 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:5,代码来源:patch.py

示例14: node_ratio

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import Comment [as 别名]
def node_ratio(self, left, right):
        if left.tag is etree.Comment or right.tag is etree.Comment:
            if left.tag is etree.Comment and right.tag is etree.Comment:
                # comments
                self._sequencematcher.set_seqs(left.text, right.text)
                return self._sequence_ratio()
            # One is a comment the other is not:
            return 0

        for attr in self.uniqueattrs:
            if not isinstance(attr, str):
                # If it's actually a sequence of (tag, attr), the tags must
                # match first.
                tag, attr = attr
                if tag != left.tag or tag != right.tag:
                    continue
            if attr in left.attrib or attr in right.attrib:
                # One of the nodes have a unique attribute, we check only that.
                # If only one node has it, it means they are not the same.
                return int(left.attrib.get(attr) == right.attrib.get(attr))

        match = self.leaf_ratio(left, right)
        child_ratio = self.child_ratio(left, right)

        if child_ratio is not None:
            match = (match + child_ratio) / 2
        return match 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:29,代码来源:diff.py


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