當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。