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


Python saxutils.escape方法代码示例

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


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

示例1: disallowed_token

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def disallowed_token(self, token):
        token_type = token["type"]
        if token_type == "EndTag":
            token["data"] = "</%s>" % token["name"]
        elif token["data"]:
            assert token_type in ("StartTag", "EmptyTag")
            attrs = []
            for (ns, name), v in token["data"].items():
                attrs.append(' %s="%s"' % (name if ns is None else "%s:%s" % (prefixes[ns], name), escape(v)))
            token["data"] = "<%s%s>" % (token["name"], ''.join(attrs))
        else:
            token["data"] = "<%s>" % token["name"]
        if token.get("selfClosing"):
            token["data"] = token["data"][:-1] + "/>"

        token["type"] = "Characters"

        del token["name"]
        return token 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:sanitizer.py

示例2: disallowed_token

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def disallowed_token(self, token, token_type):
        if token_type == tokenTypes["EndTag"]:
            token["data"] = "</%s>" % token["name"]
        elif token["data"]:
            attrs = ''.join([' %s="%s"' % (k, escape(v)) for k, v in token["data"]])
            token["data"] = "<%s%s>" % (token["name"], attrs)
        else:
            token["data"] = "<%s>" % token["name"]
        if token.get("selfClosing"):
            token["data"] = token["data"][:-1] + "/>"

        if token["type"] in list(tokenTypes.keys()):
            token["type"] = "Characters"
        else:
            token["type"] = tokenTypes["Characters"]

        del token["name"]
        return token 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:sanitizer.py

示例3: _display_xml_table_elem

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def _display_xml_table_elem(doc, first=False, name=None, out=sys.stdout):
    if first:
        assert name is None
    name = '' if name is None else ' key=%s' % saxutils.quoteattr(name)
    if isinstance(doc, list):
        if not first:
            out.write('<table%s>\n' % name)
        for subdoc in doc:
            _display_xml_table_elem(subdoc, out=out)
        if not first:
            out.write('</table>\n')
    elif isinstance(doc, dict):
        if not first:
            out.write('<table%s>\n' % name)
        for key, subdoc in viewitems(doc):
            _display_xml_table_elem(subdoc, name=key, out=out)
        if not first:
            out.write('</table>\n')
    else:
        out.write('<elem%s>%s</elem>\n' % (name,
                                           saxutils.escape(
                                               str(doc),
                                               entities={'\n': '&#10;'},
                                           ))) 
开发者ID:cea-sec,项目名称:ivre,代码行数:26,代码来源:activecli.py

示例4: gtk_listbox_populate_labels

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def gtk_listbox_populate_labels(listbox, label_strings):
	"""
	Formats and adds labels to a listbox. Each label is styled and added as a
	separate entry.

	.. versionadded:: 1.13.0

	:param listbox: Gtk Listbox to put the labels in.
	:type listbox: :py:class:`Gtk.listbox`
	:param list label_strings: List of strings to add to the Gtk Listbox as labels.
	"""
	gtk_widget_destroy_children(listbox)
	for label_text in label_strings:
		label = Gtk.Label()
		label.set_markup("<span font=\"smaller\"><tt>{0}</tt></span>".format(saxutils.escape(label_text)))
		label.set_property('halign', Gtk.Align.START)
		label.set_property('use-markup', True)
		label.set_property('valign', Gtk.Align.START)
		label.set_property('visible', True)
		listbox.add(label) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:22,代码来源:gui_utilities.py

示例5: html_tabulator

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def html_tabulator(rows, items):
    columns, remainder = divmod(len(items), rows)
    if remainder:
        columns += 1
    column = 0
    table = ['<table border="1">\n']
    for item in items:
        if column == 0:
            table.append("<tr>")
        table.append("<td>{}</td>".format(escape(str(item))))
        column += 1
        if column == columns:
            table.append("</tr>\n")
        column %= columns
    if table[-1][-1] != "\n":
        table.append("</tr>\n")
    table.append("</table>\n")
    return "".join(table) 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:20,代码来源:tabulator3.py

示例6: _parse

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def _parse(data, limit):
        output = []
        feed = feedparser.parse(data) # Atom + RSS
        for entry in feed["entries"]:
            title = entry.get("title")
            link = entry.get("link")
            if title:
                if link:
                    output.append('<li><a href="{}">{}</a></li>'.format(
                            link, escape(title)))
                else:
                    output.append('<li>{}</li>'.format(escape(title)))
            if limit and len(output) == limit:
                break
        if output:
            return ["<ul>"] + output + ["</ul>"] 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:18,代码来源:Feed.py

示例7: tabulate

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def tabulate(self, rows, items):
        columns, remainder = divmod(len(items), rows)
        if remainder:
            columns += 1
        column = 0
        table = ['<table border="1">\n']
        for item in items:
            if column == 0:
                table.append("<tr>")
            table.append("<td>{}</td>".format(escape(str(item))))
            column += 1
            if column == columns:
                table.append("</tr>\n")
            column %= columns
        if table[-1][-1] != "\n":
            table.append("</tr>\n")
        table.append("</table>\n")
        return "".join(table) 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:20,代码来源:tabulator1.py

示例8: tabulate

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def tabulate(rows, items):
        columns, remainder = divmod(len(items), rows)
        if remainder:
            columns += 1
        column = 0
        table = ['<table border="1">\n']
        for item in items:
            if column == 0:
                table.append("<tr>")
            table.append("<td>{}</td>".format(escape(str(item))))
            column += 1
            if column == columns:
                table.append("</tr>\n")
            column %= columns
        if table[-1][-1] != "\n":
            table.append("</tr>\n")
        table.append("</table>\n")
        return "".join(table) 
开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:20,代码来源:tabulator2.py

示例9: generateReport

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def generateReport(self, test, result):
        report_attrs = self.getReportAttributes(result)
        generator = 'HTMLTestRunner %s' % __version__
        stylesheet = self._generate_stylesheet()
        heading = self._generate_heading(report_attrs)
        report = self._generate_report(result)
        ending = self._generate_ending()
        output = self.HTML_TMPL % dict(
                title=saxutils.escape(self.title),
                generator=generator,
                stylesheet=stylesheet,
                heading=heading,
                report=report,
                ending=ending,
        )
        self.stream.write(output.encode('utf8')) 
开发者ID:bq,项目名称:web2board,代码行数:18,代码来源:HTMLTestRunner.py

示例10: stopTestRun

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def stopTestRun(self):
        super(HtmlOutput, self).stopTestRun()
        self.stopTime = datetime.datetime.now()
        report_attrs = self._getReportAttributes()
        generator = 'subunit2html %s' % __version__
        heading = self._generate_heading(report_attrs)
        report = self._generate_report()
        ending = self._generate_ending()
        output = TemplateData.HTML_TMPL % dict(
            title=saxutils.escape(TemplateData.DEFAULT_TITLE),
            generator=generator,
            stylesheet=TemplateData.STYLESHEET_TMPL,
            heading=heading,
            report=report,
            ending=ending,
        )
        if self.html_file:
            with open(self.html_file, 'wb') as html_file:
                html_file.write(output.encode('utf8')) 
开发者ID:openstack,项目名称:os-testr,代码行数:21,代码来源:subunit2html.py

示例11: parse_declaration

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def parse_declaration(self, i):
        # override internal declaration handler to handle CDATA blocks
        if self.rawdata[i:i+9] == '<![CDATA[':
            k = self.rawdata.find(']]>', i)
            if k == -1:
                # CDATA block began but didn't finish
                k = len(self.rawdata)
                return k
            self.handle_data(_xmlescape(self.rawdata[i+9:k]), 0)
            return k+3
        else:
            k = self.rawdata.find('>', i)
            if k >= 0:
                return k+1
            else:
                # We have an incomplete CDATA block.
                return k 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:19,代码来源:feedparser.py

示例12: getXML

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def getXML(self, audio_file):
        tag = audio_file.tag

        pprint = not self.args.no_pretty_print
        nl = "\n" if pprint else ""
        indent = (" " * 2) if pprint else ""

        xml = f"<tune xmlns='http://jabber.org/protocol/tune'>{nl}"
        if tag.artist:
            xml += f"{indent}<artist>{escape(tag.artist)}</artist>{nl}"
        if tag.title:
            xml += f"{indent}<title>{escape(tag.title)}</title>{nl}"
        if tag.album:
            xml += f"{indent}<source>{escape(tag.album)}</source>{nl}"
        xml += f"{indent}<track>file://{escape(str(Path(audio_file.path).absolute()))}</track>{nl}"
        if audio_file.info:
            xml += f"{indent}<length>{audio_file.info.time_secs:.2f}</length>{nl}"
        xml += "</tune>"

        return xml 
开发者ID:nicfit,项目名称:eyeD3,代码行数:22,代码来源:xep_118.py

示例13: _set_date_to_xml_text

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def _set_date_to_xml_text(self, date_value, date_error, xml_element_name, xml_attrs):
        """
        Common handling of invalid dates for the date... element handlers.

        Prints warning on console and sets date_value to a text-only date
        with the problematic XML inside.
        """
        xml = "<{element_name} {attrs}/>".format(
            element_name = xml_element_name,
            attrs = " ".join(
                ['{}="{}"'.format(k,escape(v, entities={'"' : "&quot;"}))
                    for k,v in xml_attrs.items()]))
        # TRANSLATORS: leave the {date} and {xml} untranslated in the format string,
        # but you may re-order them if needed.
        LOG.warning(_("Invalid date {date} in XML {xml}, preserving XML as text"
            ).format(date=date_error.date.to_struct(), xml=xml))
        date_value.set(modifier=Date.MOD_TEXTONLY, text=xml) 
开发者ID:GenealogyCollective,项目名称:gprime,代码行数:19,代码来源:importxml.py

示例14: generateReport

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def generateReport(self, test, result):
        report_attrs = self.getReportAttributes(result)
        generator = 'HTMLTestRunner %s' % __version__
        stylesheet = self._generate_stylesheet()
        heading = self._generate_heading(report_attrs)
        report = self._generate_report(result)
        ending = self._generate_ending()
        output = self.HTML_TMPL % dict(
            title=saxutils.escape(self.title),
            generator=generator,
            stylesheet=stylesheet,
            heading=heading,
            report=report,
            ending=ending,
        )
        self.stream.write(output.encode('utf8')) 
开发者ID:qzq1111,项目名称:flask-restful-example,代码行数:18,代码来源:HTMLTestRunner.py

示例15: get_strings_resources

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import escape [as 别名]
def get_strings_resources(self):
        """
        Get the XML (as string) of all resources of type 'string'.
        This is a combined variant, which has all locales and all package names
        stored.
        """
        self._analyse()

        buff = '<?xml version="1.0" encoding="utf-8"?>\n'

        buff += "<packages>\n"
        for package_name in self.get_packages_names():
            buff += "<package name=\"%s\">\n" % package_name

            for locale in self.get_locales(package_name):
                buff += "<locale value=%s>\n" % repr(locale)

                buff += '<resources>\n'
                try:
                    for i in self.values[package_name][locale]["string"]:
                        buff += '<string name="%s">%s</string>\n' % (i[0], escape(i[1]))
                except KeyError:
                    pass

                buff += '</resources>\n'
                buff += '</locale>\n'

            buff += "</package>\n"

        buff += "</packages>\n"

        return buff.encode('utf-8') 
开发者ID:amimo,项目名称:dcc,代码行数:34,代码来源:__init__.py


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