• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python saxutils.escape函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: get

    def get(self):
        bind_id = self.get_argument("bind_id")
        youtube_id = self.get_argument("youtube_id", "-1")
        time_watched = self.get_argument("time_watched", -1)
        logger.debug(
            "Set-top box list request received: bind_id: %s, youtube_id: %s, time_watched: %s",
            bind_id,
            youtube_id,
            time_watched,
        )

        try:
            if youtube_id != "-1" and youtube_id != "Title":
                Video.mark_watched(bind_id=bind_id, youtube_id=youtube_id, time_watched=time_watched)
        except:
            dbutils.Session.rollback()

        try:
            container = Video.get_list(bind_id=bind_id, is_stb=True)
            playback_url = fetch_yt_link(container["nowplaying"]["url"])
            playback_url = escape(playback_url + "&title=.mp4")
            container["nowplaying"]["url"] = escape(container["nowplaying"]["url"])
            container["nowplaying"]["title"] = escape(container["nowplaying"]["title"])
            container["nowplaying"]["youtube_id"] = escape(container["nowplaying"]["youtube_id"])
            container["nowplaying"]["playback_url"] = playback_url
        except:
            dbutils.Session.rollback()
            container = []
        logger.info("timewatched: %s youtube_id:%s bind_id:%s", time_watched, youtube_id, bind_id)
        #        self.content_type = 'text/xml' //HACK wtf why doesn't this work..?
        self._headers["Content-Type"] = "text/xml; charset=UTF-8"
        if container != []:
            self.write(dict2xml({"nowplaying": container["nowplaying"]}))
        dbutils.Session.remove()
        self.finish()
开发者ID:sosso,项目名称:eashl_stats2,代码行数:35,代码来源:myapp_tornado.py


示例17: thank_after_registered

 def thank_after_registered(self, name, token, tmp_user_id, user_id, lang):
     url = u"https://sh-hringhorni.appspot.com/activate?t=" + escape(token) + u"&i=" + escape(tmp_user_id) + "&u=" + escape(user_id) + u"\n"
     body = escape(name) + u"さん、\nShourへようこそ。\n\nShourにあなたのメールアドレスが仮登録され、アカウントが発行されました。下記のURLをクリックしてアカウントを有効化してください。\n" + url + u"\nShourは、ちょっとした時間を親しい間柄の人との楽しいひと時に変える新感覚予定共有アプリです。\n\n「今度お茶しよう」\n「久しぶりに会いたいね」\n「また語りましょう」\nそんな友達との約束を、Shourで是非実現してみてください。\n\n日々の生活の中にあるスキマ時間が、シャワータイムのようなリフレッシュのひと時になるよう、Shourはお手伝いします。\n\nShour開発チーム一同\n\n※このメールに覚えがない場合、誤って送信された可能性がございます。大変お手数ですが、破棄してください。"
     if lang:
         if lang == "en":
             body = u"Hi," + escape(name) +".\nYou are the newest member of \"Shour\".\n\nClick here to verify your email address. \n" + url + u"\nWith shour, you can enjoy a pleasant time with your close friends in your spare time. Shour will help you spent refreshing moments like shower time. Please just try it! We hope you enjoy \"SHaring your hOUR\"!! \n\nDevelopment team of Shour\n\nNotice: If you do not know any idea about this email, this may be miscarriaged to wrong email address. We appologize for this inconvenience and thank you for delete this email."
     return body
开发者ID:GATAKAWAKACHICO,项目名称:shour_gae,代码行数:7,代码来源:mailbody.py


示例18: message_to_xmb

def message_to_xmb(message):
    """Converts a single message object to a <msg> tag in the XMB format."""
    # TODO(lschumacher) handle plurals
    message_id = message.id
    if isinstance(message_id, tuple):
        message_id = message_id[0]

    if 'python-format' in message.flags:
        xml_parts = []
        ph_index = 0
        for token in PYTHON_FORMAT_RE.split(message_id):
            if token.startswith('%(') and token.endswith(')s'):
                name = token[2:-2]
                ph_index += 1
                xml_parts.append('<ph name="%s"><ex>%s</ex>%%%d</ph>' %
                                 (name, name, ph_index))
            elif token == '%%':
                xml_parts.append('%')
            elif token:
                xml_parts.append(escape(token))
        xml_message = ''.join(xml_parts) 
    else:
        xml_message = escape(message_id)
    return '<msg desc=%s>%s</msg>' % (
        quoteattr(' '.join(message.user_comments)), xml_message)
开发者ID:google,项目名称:personfinder,代码行数:25,代码来源:find_missing_translations.py


示例19: branchentry

 def branchentry(self, branch):
     # check if this branch must be checked, if not, recurse further
     if not NifSpell._branchinspect(self, branch):
         return True
     blocktype = branch.__class__.__name__
     reports = self.toaster.reports_per_blocktype.get(blocktype)
     if not reports:
         # start a new report for this block type
         row = "<tr>"
         row += "<th>%s</th>" % "file" 
         row +=  "<th>%s</th>" % "id" 
         for attr in branch._get_filtered_attribute_list(data=self.data):
             row += ("<th>%s</th>"
                     % escape(attr.displayname, self.ENTITIES))
         row += "</tr>"
         reports = [row]
         self.toaster.reports_per_blocktype[blocktype] = reports
     
     row = "<tr>"
     row += "<td>%s</td>" % escape(self.stream.name)
     row += "<td>%s</td>" % escape("0x%08X" % id(branch), self.ENTITIES)
     for attr in branch._get_filtered_attribute_list(data=self.data):
         row += ("<td>%s</td>"
                 % escape(dumpAttr(getattr(branch, "_%s_value_"
                                           % attr.name)),
                          self.ENTITIES))
     row += "</tr>"
     reports.append(row)
     # keep looking for blocks of interest
     return True
开发者ID:Dexesttp,项目名称:pyffi,代码行数:30,代码来源:dump.py


示例20: append_text

 def append_text(self, text):
     text1, text2 = (text + '\n').split('\n', 1)
     text = self.text_markup % (self.foreground_color, escape(text1), escape(text2))
     self.text = self.text + "\n" + text
     self.message_label.set_text(self.text)
     self.message_label.set_use_markup(True)
     self.message_label.show()
开发者ID:atilacamurca,项目名称:Hotot,代码行数:7,代码来源:gtknotification.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python saxutils.prepare_input_source函数代码示例发布时间:2022-05-26
下一篇:
Python handler.ContentHandler类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap