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


Python saxutils.escape函数代码示例

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


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

示例1: output_difference

def output_difference(difference, print_func, parents):
    logger.debug('html output for %s', difference.source1)
    sources = parents + [difference.source1]
    print_func(u"<div class='difference'>")
    try:
        print_func(u"<div class='diffheader'>")
        if difference.source1 == difference.source2:
            print_func(u"<div><span class='source'>%s<span>"
                       % escape(difference.source1))
        else:
            print_func(u"<div><span class='source'>%s</span> vs.</div>"
                       % escape(difference.source1))
            print_func(u"<div><span class='source'>%s</span>"
                       % escape(difference.source2))
        anchor = '/'.join(sources[1:])
        print_func(u" <a class='anchor' href='#%s' name='%s'>&para;</a>" % (anchor, anchor))
        print_func(u"</div>")
        if difference.comment:
            print_func(u"<div class='comment'>%s</div>"
                       % escape(difference.comment).replace('\n', '<br />'))
        print_func(u"</div>")
        if difference.unified_diff:
            output_unified_diff(print_func, difference.unified_diff)
        for detail in difference.details:
            output_difference(detail, print_func, sources)
    except PrintLimitReached:
        logger.debug('print limit reached')
        raise
    finally:
        print_func(u"</div>", force=True)
开发者ID:dezgeg,项目名称:debbindiff,代码行数:30,代码来源:html.py

示例2: _get_add_xml

def _get_add_xml(array_of_hash, overwrite=True):
    """ Creates add XML message to send to Solr based on the array of hashes
    (documents) provided.

    :param overwrite: Newer documents will replace previously added documents
                      with the same uniqueKey (default is True)

    """
    xml = '<add overwrite="%s">' % ('true' if overwrite else 'false')
    for doc_hash in array_of_hash:
        doc = '<doc>'
        for key, value in doc_hash.items():
            if type(value) == type(list()):
                for v in value:
                    if isinstance(v, basestring):
                        v = escape(v)
                    doc = '%s<field name="%s">%s</field>' % (doc, key, v)
            else:
                if isinstance(value, basestring):
                    value = escape(value)
                doc = '%s<field name="%s">%s</field>' % (doc, key, value)
        doc = '%s</doc>' % (doc)
        xml = '%s%s' % (xml, doc)
    xml = '%s</add>' % (xml)
    return xml
开发者ID:pombredanne,项目名称:mysolr,代码行数:25,代码来源:mysolr.py

示例3: get_cell_data_cb

    def get_cell_data_cb(self, column, cell, model, piter, user_data=None):
        tool = model.get_value(piter, self.TOOL_COLUMN)

        if tool == None or not isinstance(tool, Tool):
            if tool == None:
                label = _('All Languages')
            elif not isinstance(tool, GtkSource.Language):
                label = _('Plain Text')
            else:
                label = tool.get_name()

            markup = saxutils.escape(label)
            editable = False
        else:
            escaped = saxutils.escape(tool.name)

            if tool.shortcut:
                key, mods = Gtk.accelerator_parse(tool.shortcut)
                label = Gtk.accelerator_get_label(key, mods)
                markup = '%s (<b>%s</b>)' % (escaped, label)
            else:
                markup = escaped

            editable = True

        cell.set_properties(markup=markup, editable=editable)
开发者ID:GNOME,项目名称:gedit,代码行数:26,代码来源:manager.py

示例4: tooltip_helper

def tooltip_helper(desc):
    """Widget tooltip construction helper.

    """
    tooltip = []
    tooltip.append("<b>{name}</b>".format(name=escape(desc.name)))

    if desc.project_name and desc.project_name != "Orange":
        tooltip[0] += " (from {0})".format(desc.project_name)

    if desc.description:
        tooltip.append("{0}".format(
                            escape(desc.description)))

    inputs_fmt = "<li>{name}</li>"

    if desc.inputs:
        inputs = "".join(inputs_fmt.format(name=inp.name)
                         for inp in desc.inputs)
        tooltip.append("Inputs:<ul>{0}</ul>".format(inputs))
    else:
        tooltip.append("No inputs")

    if desc.outputs:
        outputs = "".join(inputs_fmt.format(name=out.name)
                          for out in desc.outputs)
        tooltip.append("Outputs:<ul>{0}</ul>".format(outputs))
    else:
        tooltip.append("No outputs")

    return "<hr/>".join(tooltip)
开发者ID:Coding4Sec,项目名称:orange3,代码行数:31,代码来源:qt.py

示例5: whats_this_helper

def whats_this_helper(desc, include_more_link=False):
    """
    A `What's this` text construction helper. If `include_more_link` is
    True then the text will include a `more...` link.

    """
    title = desc.name
    help_url = desc.help

    if not help_url:
        help_url = "help://search?" + urlencode({"id": desc.id})

    description = desc.description
    long_description = desc.long_description

    template = ["<h3>{0}</h3>".format(escape(title))]

    if description:
        template.append("<p>{0}</p>".format(escape(description)))

    if long_description:
        template.append("<p>{0}</p>".format(escape(long_description[:100])))

    if help_url and include_more_link:
        template.append("<a href='{0}'>more...</a>".format(escape(help_url)))

    return "\n".join(template)
开发者ID:AutumnLight,项目名称:orange,代码行数:27,代码来源:qt.py

示例6: _detailed_text

    def _detailed_text(self, item):
        if isinstance(item, Installed):
            remote, dist = item
            if remote is None:
                description = get_dist_meta(dist).get("Description")
                description = description
            else:
                description = remote.description
        else:
            description = item[0].description

        if docutils is not None:
            try:
                html = docutils.core.publish_string(
                    trim(description),
                    writer_name="html",
                    settings_overrides={
                        "output-encoding": "utf-8",
#                         "embed-stylesheet": False,
#                         "stylesheet": [],
#                         "stylesheet_path": []
                    }
                ).decode("utf-8")

            except docutils.utils.SystemMessage:
                html = "<pre>{}<pre>".format(escape(description))
            except Exception:
                html = "<pre>{}<pre>".format(escape(description))
        else:
            html = "<pre>{}<pre>".format(escape(description))
        return html
开发者ID:Micseb,项目名称:orange3,代码行数:31,代码来源:addons.py

示例7: process

    def process(self, node):
        """ Process the given xml `node`: collect `todo` and `done` items. """
        if (
            isinstance(node, SKIPPED_ELEMENT_TYPES) or
            node.tag in SKIPPED_ELEMENTS or
            node.get("translation", "").strip() == "off" or
            node.tag == "attribute" and node.get("name") not in TRANSLATED_ATTRS
        ):
            # do not translate the contents of the node
            tail, node.tail = node.tail, None
            self.done(etree.tostring(node))
            self.todo(escape(tail or ""))
            return

        # process children nodes locally in child_trans
        child_trans = XMLTranslator(self.callback)
        child_trans.todo(escape(node.text or ""))
        for child in node:
            child_trans.process(child)

        if (child_trans.all_todo() and
                node.tag in TRANSLATED_ELEMENTS and
                not any(attr.startswith("t-") for attr in node.attrib)):
            # serialize the node element as todo
            self.todo(serialize(node.tag, node.attrib, child_trans.get_todo()),
                      child_trans.needs_trans)
        else:
            # complete translations and serialize result as done
            for attr in TRANSLATED_ATTRS:
                if node.get(attr):
                    node.set(attr, self.process_text(node.get(attr)))
            self.done(serialize(node.tag, node.attrib, child_trans.get_done()))

        # add node tail as todo
        self.todo(escape(node.tail or ""))
开发者ID:mkieszek,项目名称:odoo,代码行数:35,代码来源:translate.py

示例8: set_personal_message

    def set_personal_message(self, personal_message='', current_media=None,
            signature_sound=None):
        """Sets the new personal message

            @param personal_message: the new personal message
            @type personal_message: string"""
        cm = ''
        if current_media is not None:
            cm ='\\0Music\\01\\0{0} - {1}\\0%s\\0%s\\0\\0' % \
                (xml_utils.escape(current_media[0]),
                 xml_utils.escape(current_media[1]))

        if signature_sound is not None:
            signature_sound = xml_utils.escape(signature_sound)
            ss = '<SignatureSound>%s</SignatureSound>' % signature_sound

        message = xml_utils.escape(personal_message)
        pm = '<Data>'\
                '<PSM>%s</PSM>'\
                '<CurrentMedia>%s</CurrentMedia>'\
                '<MachineGuid>%s</MachineGuid>'\
            '</Data>' % (message, cm, self._client.machine_guid.upper())
        self._send_command('UUX', payload=pm)
        self._client.profile._server_property_changed("personal-message",
                personal_message)
        if current_media is not None:
            self._client.profile._server_property_changed("current-media",
                current_media)
开发者ID:DarKprince,项目名称:emesene2,代码行数:28,代码来源:notification.py

示例9: html_elements

        def html_elements(fullfilename, title, caption, identifier):

            return '<div class="item"><img class="content" src="' +\
                escape(fullfilename) + '" title="' +\
                escape(title) + '" identifier="' +\
                identifier + '"/> <div class="caption">' +\
                escape(caption) + '</div> </div>'
开发者ID:coolono,项目名称:coverart-browser,代码行数:7,代码来源:coverart_coverflowview.py

示例10: as_xml

    def as_xml (self, encoding="UTF-8"):
        """(str): str

        Return the XML representation of the collection.  The 'encoding'
        parameter will be substituted into the XML document's header,
        but it's the caller's responsibility to encode the string returned
        from this method.
        """
        from qel import QEL_HEADER, QEL_FOOTER
        s = QEL_HEADER % encoding
        if self.title:
            s += '  <title>%s</title>\n' % escape(self.title)
        if self.editor:
            s += '  <editor>%s</editor>\n' % escape(self.editor)
        if self.description:
            s += '  <description>%s</description>\n' % escape(self.description)
        if self.copyright:
            s += '  <copyright>%s</copyright>\n' % escape(self.copyright)
        if self.license:
            s += '  <license>'
            for t in self.license:
                if isinstance(t, str):
                    s += escape(t)
                else:
                    s += t.as_xml()
            s += '\n  </license>\n'
        for qt in self:
            s += qt.as_xml()
        s += QEL_FOOTER
        return s
开发者ID:akuchling,项目名称:quotation-tools,代码行数:30,代码来源:quotation.py

示例11: listToRokuXml

def listToRokuXml(listTag, itemTag, l):
    xml = '<' + saxutils.escape(listTag) + '>\n'
    for item in l:
        if type(item) is dict:
            xml += dictionaryToRokuXml(itemTag, item)
    xml += '</' + saxutils.escape(listTag) + '>\n'
    return xml
开发者ID:carbonDVR,项目名称:carbonDVR,代码行数:7,代码来源:restServer.py

示例12: _build_health_report

def _build_health_report(incarnation, container_id, role_instance_id,
                         status, substatus, description):
    #Escape '&', '<' and '>'
    description = saxutils.escape(ustr(description))
    detail = u''
    if substatus is not None:
        substatus = saxutils.escape(ustr(substatus))
        detail = (u"<Details>"
                  u"<SubStatus>{0}</SubStatus>"
                  u"<Description>{1}</Description>"
                  u"</Details>").format(substatus, description)
    xml = (u"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
           u"<Health "
           u"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
           u" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"
           u"<GoalStateIncarnation>{0}</GoalStateIncarnation>"
           u"<Container>"
           u"<ContainerId>{1}</ContainerId>"
           u"<RoleInstanceList>"
           u"<Role>"
           u"<InstanceId>{2}</InstanceId>"
           u"<Health>"
           u"<State>{3}</State>"
           u"{4}"
           u"</Health>"
           u"</Role>"
           u"</RoleInstanceList>"
           u"</Container>"
           u"</Health>"
           u"").format(incarnation,
                       container_id,
                       role_instance_id,
                       status,
                       detail)
    return xml
开发者ID:Artoria2e5,项目名称:WALinuxAgent,代码行数:35,代码来源:wire.py

示例13: on_display_text

    def on_display_text(self):
        # Now do the stuff that takes a bit longer...
        heading = self.episode.title
        subheading = _('from %s') % (self.episode.channel.title)
        description = self.episode.description

        if self.have_webkit:
            global SHOWNOTES_HTML_TEMPLATE

            # Get the description - if it looks like plaintext, replace the
            # newline characters with line breaks for the HTML view
            description = self.episode.description
            if '<' not in description:
                description = description.replace('\n', '<br>')

            args = (
                    saxutils.escape(heading),
                    saxutils.escape(subheading),
                    description,
            )
            url = os.path.dirname(self.episode.channel.url)
            self.htmlview.load_html_string(SHOWNOTES_HTML_TEMPLATE % args, url)
        else:
            self.b.create_tag('heading', scale=pango.SCALE_LARGE, weight=pango.WEIGHT_BOLD)
            self.b.create_tag('subheading', scale=pango.SCALE_SMALL)

            self.b.insert_with_tags_by_name(self.b.get_end_iter(), heading, 'heading')
            self.b.insert_at_cursor('\n')
            self.b.insert_with_tags_by_name(self.b.get_end_iter(), subheading, 'subheading')
            self.b.insert_at_cursor('\n\n')
            self.b.insert(self.b.get_end_iter(), util.remove_html_tags(description))
            self.b.place_cursor(self.b.get_start_iter())
开发者ID:xerxes2,项目名称:gpodder,代码行数:32,代码来源:shownotes.py

示例14: ToTagUri

  def ToTagUri(self):
    """Returns a tag: URI for this entity for use in XML output.

    Foreign keys for entities may be represented in XML output as tag URIs.
    RFC 4151 describes the tag URI scheme. From http://taguri.org/:

      The tag algorithm lets people mint - create - identifiers that no one
      else using the same algorithm could ever mint. It is simple enough to do
      in your head, and the resulting identifiers can be easy to read, write,
      and remember. The identifiers conform to the URI (URL) Syntax.

    Tag URIs for entities use the app's auth domain and the date that the URI
     is generated. The namespace-specific part is <kind>[<key>].

    For example, here is the tag URI for a Kitten with the key "Fluffy" in the
    catsinsinks app:

      tag:catsinsinks.googleapps.com,2006-08-29:Kitten[Fluffy]

    Raises a BadKeyError if this entity's key is incomplete.
    """
    if not self.has_id_or_name():
      raise datastore_errors.BadKeyError(
        'ToTagUri() called for an entity with an incomplete key.')

    return u'tag:%s.%s,%s:%s[%s]' % (saxutils.escape(self.app()),
                                     os.environ['AUTH_DOMAIN'],
                                     datetime.date.today().isoformat(),
                                     saxutils.escape(self.kind()),
                                     saxutils.escape(str(self)))
开发者ID:simonpure,项目名称:google-app-engine,代码行数:30,代码来源:datastore_types.py

示例15: escape_html

def escape_html(input_file, output_file=os.getcwd() + '/'):
    f = file(input_file, 'r')
    for line in f.xreadlines():
        if output_file == os.getcwd() + '/':
            save_result_file(escape(line, html_escape_dict), output_file + input_file + '_escape')
        else:
            save_result_file(escape(line, html_escape_dict), output_file + '_escape')
开发者ID:fc500110,项目名称:iamrobot,代码行数:7,代码来源:htmlEscape.py


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