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


Python saxutils.unescape方法代码示例

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


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

示例1: getUniqueElementValueFromXmlString

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def getUniqueElementValueFromXmlString(xmlString, elementName):
    """
    Extracts an element value from an XML string.

    For example, invoking
    getUniqueElementValueFromXmlString(
        '<?xml version="1.0" encoding="UTF-8"?><foo>bar</foo>', 'foo')
    should return the value 'bar'.
    """
    xmlStringAsDom = xml.dom.minidom.parseString(xmlString)
    elementsByName = xmlStringAsDom.getElementsByTagName(elementName)
    elementValue = None
    if len(elementsByName) > 0:
        elementValue = elementsByName[0].toxml().replace(
            '<' + elementName + '>', '').replace('</' + elementName + '>', '')
    return unescape(elementValue) 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:18,代码来源:util.py

示例2: __init__

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def __init__(self, name, req, attributes={}):
        """Construct a tag.

        @param name: The name of the tag. Should be a string, generally
            a short one.
        @param attributes: Allow having initial set of attributes without
            calling _save callback
        """
        super().__init__(name)
        self._name = saxutils.unescape(str(name))
        self.req = req
        self._save = None
        self._attributes = {'name': self._name}
        for key, value in attributes.items():
            self.set_attribute(key, value)

        self.viewcount = None 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:19,代码来源:tag.py

示例3: _email_html

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def _email_html(to, subject, body):
  """Sends an email including a textual representation of the HTML body.

  The body must not contain <html> or <body> tags.
  """
  mail_args = {
    'body': saxutils.unescape(re.sub(r'<[^>]+>', r'', body)),
    'html': '<html><body>%s</body></html>' % body,
    'sender': 'no_reply@%s.appspotmail.com' % app_identity.get_application_id(),
    'subject': subject,
  }
  try:
    if to:
      mail_args['to'] = to
      mail.send_mail(**mail_args)
    else:
      mail.send_mail_to_admins(**mail_args)
    return True
  except mail_errors.BadRequestError:
    return False 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:ui.py

示例4: SendReport

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def SendReport(self, report):
    """Emails an exception report.

    Args:
      report: A string containing the report to send.
    """
    subject = ('Daily exception report for app "%s", major version "%s"'
               % (self.app_id, self.major_version))
    report_text = saxutils.unescape(re.sub('<[^>]+>', '', report))
    mail_args = {
        'sender': self.sender,
        'subject': subject,
        'body': report_text,
        'html': report,
    }
    if self.to:
      mail_args['to'] = self.to
      self.send_mail(**mail_args)
    else:
      self.send_mail_to_admins(**mail_args) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:22,代码来源:report_generator.py

示例5: check_iscsi

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def check_iscsi(self, ref, name, host, port, scsiid, targetiqn, user, password):
        sr = {"port": port,
              "target": host,
              "SCSIid": scsiid,
              "targetIQN": targetiqn}
        if user:
            sr["chapuser"] = user
        if password:
            sr["chappassword"] = password
        value = self.connection.Async.SR.probe(self.session_uuid, ref, sr, "lvmoiscsi", {})['Value']
        task = self.connection.task.get_record(self.session_uuid, value)['Value']
        while task["status"] == "pending":
            task = self.connection.task.get_record(self.session_uuid, value)['Value']
        result = saxutils.unescape(task['result']).replace("<value>", "").replace("</value>", "").replace("&quot;", '"')
        print result
        dom = xml.dom.minidom.parseString(result)
        nodes = dom.getElementsByTagName("UUID")
        if len(nodes):
            return nodes[0].childNodes[0].data.strip()
        else:
            return None 
开发者ID:OpenXenManager,项目名称:openxenmanager,代码行数:23,代码来源:oxcSERVER_storage.py

示例6: scan_nfs_vhd

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def scan_nfs_vhd(self, ref, list, host, path, options):
        sr = {"serverpath": path,
              "server": host,
              "options": options}
        value = self.connection.Async.SR.probe(self.session_uuid, ref, sr, "nfs", {})['Value']
        task = self.connection.task.get_record(self.session_uuid, value)['Value']
        while task["status"] == "pending":
            task = self.connection.task.get_record(self.session_uuid, value)['Value']
        if task['result'].count("<value>"):
            result = saxutils.unescape(task['result']).replace("<value>", "").replace("</value>", "").replace("&quot;", '"')
            dom = xml.dom.minidom.parseString(result)
            nodes = dom.getElementsByTagName("SRlist")
            if len(nodes[0].childNodes):
                for i in range(1, len(nodes[0].childNodes), 2):
                    ref = nodes[0].childNodes[i].childNodes[1].childNodes[0].data.strip()
                    if not self.search_storage_uuid(ref):
                        list.append([ref, ref])
            if list.__len__() > 0:
                return 2
            else:
                return 1
        else:
            self.wine.show_error_dlg(task["error_info"][2])
            self.connection.task.destroy(self.session_uuid, value)
            return 0 
开发者ID:OpenXenManager,项目名称:openxenmanager,代码行数:27,代码来源:oxcSERVER_storage.py

示例7: __init__

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def __init__(
        self,
        text,
        style,
        bulletText=None,
        caseSensitive=1,
        level=0,
        snum=None,
        parent_id=None,
        node=None,
        section_header_depth=2,
    ):
        # Issue 114: need to convert "&amp;" to "&" and such.
        # Issue 140: need to make it plain text
        self.stext = re.sub(r'<[^>]*?>', '', unescape(text))
        self.stext = self.stext.strip()
        self.level = int(level)
        self.snum = snum
        self.parent_id = parent_id
        self.node = node
        self.section_header_depth = section_header_depth
        Paragraph.__init__(self, text, style, bulletText) 
开发者ID:rst2pdf,项目名称:rst2pdf,代码行数:24,代码来源:flowables.py

示例8: GetAttributeValue

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def GetAttributeValue(attr, extract=True):
    """
    Function that extracts data from a tree node
    @param attr: tree node containing data to extract
    @param extract: attr is a tree node or not
    @return: data extracted as string
    """
    if not extract:
        return attr
    if len(attr.childNodes) == 1:
        return text(unescape(attr.childNodes[0].data))
    else:
        # content is a CDATA
        txt = u''
        for node in attr.childNodes:
            if not (node.nodeName == "#text" and node.data.strip() == u''):
                txt += text(unescape(node.data))
        return text 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:20,代码来源:xmlclass.py

示例9: _formalize

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def _formalize(self, html):
        html = html.replace("\r\n", " ").replace("\n", " ")
        html = re.sub(r"[ \t]+", " ", html)
        html = re.sub(r"[ ]*>[ ]*", ">", html)
        html = re.sub(r"[ ]*<[ ]*", "<", html)
        return unescape(html) 
开发者ID:elsigh,项目名称:browserscope,代码行数:8,代码来源:gaeunit.py

示例10: xml_unescape

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def xml_unescape(text):
    """
    This function transforms the "escaped" version suitable
    for well-formed XML formatting into humanly-readable string.
    Note that the default xml.sax.saxutils.unescape() function don't unescape
    some characters that Moses does so we have to manually add them to the
    entities dictionary.

        >>> from xml.sax.saxutils import unescape
        >>> s = ')&#124; &amp; &lt; &gt; &apos; &quot; &#93; &#91;'
        >>> expected = ''')| & < > \' " ] ['''
        >>> xml_unescape(s) == expected
        True

    :param text: The text that needs to be unescaped.
    :type text: str
    :rtype: str
    """
    return unescape(
        text,
        entities={
            r"&apos;": r"'",
            r"&quot;": r'"',
            r"&#124;": r"|",
            r"&#91;": r"[",
            r"&#93;": r"]",
        },
    ) 
开发者ID:alvations,项目名称:sacremoses,代码行数:30,代码来源:util.py

示例11: unescape

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def unescape(string):
    """
    >>> unescape("one&nbsp;<![CDATA[two&nbsp;]]>three")
    'one two&nbsp;three'
    """

    result = list()

    for index, data in enumerate(cdata.split(string)):
        if index % 3 != 2:
            data = _unescape(data, {"&nbsp;": " "})
        result.append(data)

    return "".join(result) 
开发者ID:abusesa,项目名称:abusehelper,代码行数:16,代码来源:cleanmxbot.py

示例12: xml_unescape

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def xml_unescape(string):
    if string is None:
        return

    return _xml_unescape(string) 
开发者ID:ssorj,项目名称:quiver,代码行数:7,代码来源:pencil.py

示例13: anime

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def anime(self, ctx, *, name:str):
        """Searches MyAnimeList for the specified anime"""
        await ctx.channel.trigger_typing()
        r = requests.get("https://myanimelist.net/api/anime/search.xml?q={}".format(name), auth=requests.auth.HTTPBasicAuth(config._malUsername, config._malPassword))
        if r.status_code == 401:
            log.critical("The MyAnimeList credinals are incorrect, please check your MyAnimeList login information in the config.")
            await ctx.send(Language.get("myanimelist.incorrect_creds", ctx))
            return
        try:
            xmldoc = minidom.parseString(r.text)
        except XmlParserErrors.ExpatError:
            await ctx.send(Language.get("myanimelist.no_anime_found", ctx).format(name))
            return
        # pls no flame
        anime = xmldoc.getElementsByTagName("entry")[0]
        id = anime.getElementsByTagName("id")[0].firstChild.nodeValue
        title = anime.getElementsByTagName("title")[0].firstChild.nodeValue
        try:
            english = anime.getElementsByTagName("english")[0].firstChild.nodeValue
        except:
            english = title
        episodes = anime.getElementsByTagName("episodes")[0].firstChild.nodeValue
        score = anime.getElementsByTagName("score")[0].firstChild.nodeValue
        type = anime.getElementsByTagName("type")[0].firstChild.nodeValue
        status = anime.getElementsByTagName("status")[0].firstChild.nodeValue
        start_date = anime.getElementsByTagName("start_date")[0].firstChild.nodeValue
        end_date = anime.getElementsByTagName("end_date")[0].firstChild.nodeValue
        image = anime.getElementsByTagName("image")[0].firstChild.nodeValue
        synopsis = saxutils.unescape(anime.getElementsByTagName("synopsis")[0].firstChild.nodeValue)
        synopsis = remove_html(synopsis)
        if len(synopsis) > 300:
            synopsis = synopsis[:300] + "..."
        url = "https://myanimelist.net/anime/{}".format(id)
        fields = {Language.get("myanimelist.english_title", ctx):english, Language.get("myanimelist.episodes", ctx):episodes, Language.get("myanimelist.mal_line", ctx):score, Language.get("myanimelist.type", ctx):type, Language.get("myanimelist.status", ctx):status, Language.get("myanimelist.start_date", ctx):start_date, Language.get("myanimelist.end_date", ctx):end_date}
        embed = make_list_embed(fields)
        embed.title = title
        embed.description = synopsis
        embed.url = url
        embed.color = 0xFF0000
        embed.set_thumbnail(url=image)
        await ctx.send(embed=embed) 
开发者ID:ZeroEpoch1969,项目名称:RubyRoseBot,代码行数:43,代码来源:myanimelist.py

示例14: render_resource

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def render_resource(path, **context):
    """
    Render static resource using provided context.

    Returns: django.utils.safestring.SafeText
    """
    html = Template(resource_string(path))
    return html_parser.unescape(
        html.render(Context(context))
    ) 
开发者ID:appsembler,项目名称:xblock-video,代码行数:12,代码来源:utils.py

示例15: render_template

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import unescape [as 别名]
def render_template(template_name, **context):
    """
    Render static resource using provided context.

    Returns: django.utils.safestring.SafeText
    """
    template_dirs = [os.path.join(os.path.dirname(__file__), 'static/html')]
    engine = Engine(dirs=template_dirs, debug=True)
    html = engine.get_template(template_name)

    return html_parser.unescape(
        html.render(Context(context))
    ) 
开发者ID:appsembler,项目名称:xblock-video,代码行数:15,代码来源:utils.py


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