python类unescape()的实例源码

oss_xml_handler.py 文件源码 项目:mongodb_backup_script 作者: hxt168 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, xml_string):
        self.xml_unescape_table = {}
        self.xml_map = {}
        try:
            self.xml = minidom.parseString(xml_string)
        except:
            print xml_string
            self.xml_unescape_tabl = get_xml_unescape_table()
            self.xml_map = get_xml_unescape_map()
            for k, v in self.xml_map.items():
                xml_string = xml_string.replace(k, v)
            self.xml = minidom.parseString(xml_string)
        self.bucket = get_tag_text(self.xml, 'Bucket', convert_to_bool = False)
        self.object = get_tag_text(self.xml, 'Key', convert_to_bool = False)
        if self.xml_map:
            for k, v in self.xml_map.items():
                self.object = self.object.replace(v, k)
            self.object = unescape(self.object, self.xml_unescape_table)
        self.key = get_tag_text(self.xml, 'Key', convert_to_bool = False)
        self.upload_id = get_tag_text(self.xml, 'UploadId')
        self.marker = get_tag_text(self.xml, 'Marker', convert_to_bool = False)
rss_feeds.py 文件源码 项目:audio-feeder 作者: pganssle 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def wrap_field(field):
    """
    Given a field, detect if it has special characters <, > or & and if so
    wrap it in a CDATA field.
    """
    if not isinstance(field, str):
        return field

    if html_chars.search(field):
        return '<![CDATA[' + field + ']]>'
    else:
        # If there's already escaped data like &amp;, I want to unescape it
        # first, so I can re-escape *everything*
        field = saxutils.unescape(field)

        return saxutils.escape(field)
test_connection.py 文件源码 项目:cuny-bdif 作者: aristotle-tek 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_single_download(self):
        self.set_http_response(status_code=200)
        response = self.service_connection.get_log_file('db1', 'foo.log')

        self.assertTrue(isinstance(response, LogFileObject))
        self.assertEqual(response.marker, '0:4485')
        self.assertEqual(response.dbinstance_id, 'db1')
        self.assertEqual(response.log_filename, 'foo.log')

        self.assertEqual(response.data, saxutils.unescape(self.logfile_sample))

        self.assert_request_parameters({
            'Action': 'DownloadDBLogFilePortion',
            'DBInstanceIdentifier': 'db1',
            'LogFileName': 'foo.log',
        }, ignore_params_values=['Version'])
XML.py 文件源码 项目:taf 作者: taf3 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def append_skipped(self, report):
        """Append xml reports with skipped TC.

        Args:
            report(dict):  Skipped report

        """
        self.class_logger.info("Appending XML report with skip.")
        # filename, lineno, skipreason = report['longrepr']
        # self.class_logger.debug("Received longrepr: {0}".format(xml_unescape(report['longrepr'])))
        longrepr = xml_unescape(report['longrepr'])
        # TODO: fixed bug with longrepr crashing
        skipreason = get_skipped_reason(report['longrepr'])
        self.append(self.Junit.skipped("%s" % longrepr,  # pylint: disable=no-member
                                       type="pytest.skip", message=skipreason))
#        self.append(self.Junit.skipped("%s:%s: %s" % longrepr, type="pytest.skip", message=skipreason))
        self.skipped += 1
xmlclass.py 文件源码 项目:beremiz 作者: nucleron 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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 unicode(unescape(attr.childNodes[0].data))
    else:
        # content is a CDATA
        text = u''
        for node in attr.childNodes:
            if not (node.nodeName == "#text" and node.data.strip() == u''):
                text += unicode(unescape(node.data))
        return text
report_generator.py 文件源码 项目:Deploy_XXNET_Server 作者: jzp820927 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
mbquiz.py 文件源码 项目:murderbot 作者: glubbert 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def quiz_func(nick,match,target):
    if 'quiz' in mb.responses:
        mb.tell("weak! the answer was "+mb.responses['quiz']['param']['answer'],target)
        del mb.responses['quiz']
    req=urllib2.Request('http://jservice.io/api/random')
    response=urllib2.urlopen(req).read().decode('utf-8')
    data=choice(json.loads(response))
    answer=re.sub(html_tags,"",data['answer'])
    answer=answer.replace(r"\'","'")    
    answer=unescape(answer)
    mb.tell("Category: {}".format(data['category']['title']),target)
    mb.tell(re.sub(html_tags,"",unescape(data['question']))+" Answer: "+re.sub("[a-zA-Z0-9]","*",answer),target)            
    pattern=re.compile("^(?:murderb[o0]t|mb)?[,\s:!]*"+re.escape(answer)+"\s*$",flags=re.IGNORECASE)
    answer_response={'func':quiz_answer,'pattern':pattern,'nick':".*",'param':{'answer':answer},'target':target}
    mb.responses['quiz']=answer_response
    print(data['question'])
    print(data['answer'])
    return
views.py 文件源码 项目:legal 作者: tompecina 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def s2i(keys, inp, out):

    for key in keys:
        ind = inp.find(key)
        if ind:
            typ = TYPES[key]
            if ind.contents:
                val = ind.contents[0].strip()
                try:
                    if typ == B:
                        res = (val == 'true')
                    elif typ == S:
                        res = str(unescape(val))
                    elif typ == I:
                        res = int(round(float(c2p(str(val)))))
                    else:
                        res = float(c2p(str(val)))
                    out.__setattr__(key, res)
                except:
                    pass
fancytitles.py 文件源码 项目:deviation-manual 作者: DeviationTX 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
        # The inicialization is taken from rst2pdf.flowables.Heading
        hstyle = kwargs.pop('hstyle')
        level = 0
        text = kwargs.pop('text')
        self.snum = kwargs.pop('snum')
        self.parent_id= kwargs.pop('parent_id')
        #self.stext = 
        Heading.__init__(self,text,hstyle,level=level,
            parent_id=self.parent_id)
        # Cleanup title text
        #self.stext = re.sub(r'<[^>]*?>', '', unescape(self.stext))
        #self.stext = self.stext.strip()

        # Stuff needed for the outline entry
        MyImage.__init__(self, *args, **kwargs)
plugin.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def getWeatherReport(self,output):
        self.loadinginprogress = False
        trans = { '&szlig;' : 'ß' , '&auml;' : 'ä' , '&ouml;' : 'ö' , '&uuml;' : 'ü' , '&Auml;' : 'Ä', '&Ouml;' : 'Ö' , '&Uuml;' : 'Ü'}
        output= util.unescape(output,trans)
        if self.land == "de":
            startpos = output.find('<!-- Anfang msg_Box Content -->')
            endpos = output.find('<!-- Ende msg_Box Content -->')
            bereich = output[startpos:endpos]
            bereich = bereich.replace('<strong>', '\n')
        else:
            startpos = output.find('<div class="content"')
            endpos = output.find('</div>', startpos)
            bereich = output[startpos:endpos]

        bereich = sub('<br\s*/?>',"\n",bereich)
        bereich = sub('<[^>]*>',"",bereich)
        bereich = sub('Fronten- und Isobarenkarte.*',"",bereich)
        bereich = bereich.strip()
        bereich = sub("\n[\s\n]+", "\n\n", bereich)

        f = open(self.reportfile, "w")
        f.write("%s" % bereich)
        f.close()
        self.session.open(Console,_("Warnlagebericht"),["cat %s" % self.reportfile])
editor.py 文件源码 项目:txt2evernote 作者: Xunius 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def HTMLUnescape(text):
        return unescape(text, Editor.getHtmlUnescapeTable())
oss_xml_handler.py 文件源码 项目:mongodb_backup_script 作者: hxt168 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def list(self):
        cl = []
        pl = []
        for c in self.content_list:
            key = c.key
            if self.xml_map:
                for k, v in self.xml_map.items():
                    key = key.replace(v, k)
                key = unescape(key, self.xml_unescape_table)
            cl.append((key, c.last_modified, c.etag, c.size, c.owner.id, c.owner.display_name, c.storage_class))
        for p in self.prefix_list:
            pl.append(p)

        return (cl, pl)
oss_xml_handler.py 文件源码 项目:mongodb_backup_script 作者: hxt168 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def list(self):
        cl = []
        pl = []
        for c in self.content_list:
            key = c.key
            if self.xml_map:
                for k, v in self.xml_map.items():
                    key = key.replace(v, k)
                key = unescape(key, self.xml_unescape_table)
            cl.append((key, c.upload_id, c.init_time))
        for p in self.prefix_list:
            pl.append(p)

        return (cl, pl)
linter.py 文件源码 项目:sublime-text-3-packages 作者: nickjj 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def replace_entity(match):
        """Return the character corresponding to an HTML entity."""
        number = match.group(2)

        if number:
            hex = match.group(1) is not None
            result = chr(int(number, 16 if hex else 10))
        else:
            entity = match.group(3)
            result = unescape(entity, html.entities.html5)

        return result
cleanmxbot.py 文件源码 项目:abusehelper 作者: Exploit-install 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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)
utils.py 文件源码 项目:coursera-downloader 作者: yingchi 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def unescape_html(s):
    h = html_parser.HTMLParser()
    s = h.unescape(s)
    s = unquote_plus(s)
    return unescape(s, HTML_UNESCAPE_TABLE)
utils.py 文件源码 项目:coursera-downloader 作者: yingchi 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def clean_filename(s, minimal_change=False):
    """
    Sanitize a string to be used as a filename.
    If minimal_change is set to true, then we only strip the bare minimum of
    characters that are problematic for filesystems (namely, ':', '/' and
    '\x00', '\n').
    """

    # First, deal with URL encoded strings
    h = html_parser.HTMLParser()
    s = h.unescape(s)
    s = unquote_plus(s)

    # Strip forbidden characters
    s = (
        s.replace(':', '-')
        .replace('/', '-')
        .replace('\x00', '-')
        .replace('\n', '')
    )

    if minimal_change:
        return s

    s = s.replace('(', '').replace(')', '')
    s = s.rstrip('.')  # Remove excess of trailing dots

    s = s.strip().replace(' ', '_')
    valid_chars = '-_.()%s%s' % (string.ascii_letters, string.digits)
    return ''.join(c for c in s if c in valid_chars)
HtmlFactory.py 文件源码 项目:jumpscale_portal 作者: jumpscale7 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def unescape(self, text):
        return unescape(text, html_unescape_table)
feedback.py 文件源码 项目:alfred-alarmcom 作者: schwark 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get(self, unescape = False):
        ele_tree = ElementTree.Element('items')
        for item in self.items:
            ele_tree.append(item.getXMLElement())
        res = ElementTree.tostring(ele_tree) #! ????encoding='utf-8'????????????????alfred????
        if unescape:
            return saxutils.unescape(res)
        return res
xmlExtract.py 文件源码 项目:lawsofindia 作者: sushant354 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_unescaped_data(xmlNode):
    return saxutils.unescape(xmlNode.childNodes[0].data)
rename.py 文件源码 项目:lawsofindia 作者: sushant354 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def get_data(xmlnode):
    data = []

    for childnode in xmlnode.childNodes:
        if childnode.nodeType == Node.ELEMENT_NODE:
            data.append(get_data(childnode))
        elif childnode.nodeType == Node.TEXT_NODE:
            data.append(saxutils.unescape(childnode.data))

    return u''.join(data)
XML.py 文件源码 项目:taf 作者: taf3 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def append_error(self, report, when=""):
        """Append xml report with error (in case TC failed on setup or teardown).

        Args:
            report(dict):  Error report
            when(str):  Error occurance stage (setup|call|teardown)

        """
        self.class_logger.info("Appending XML report with error.")
        if 'longrepr' in list(report.keys()):
            longrepr = xml_unescape(report['longrepr'])
            if self.fail_traceback is not None:
                failure_reason = None
                if len(self.tests[-1]) > 0:
                    failure_reason = self.tests[-1].pop()
                if self.update is not None and len(self.tests[-1]) > 0:
                    self.tests[-1].pop()
                    try:
                        self.tests[-1].pop()
                    except IndexError:
                        pass
                self.append(
                    self.Junit.error(longrepr,  # pylint: disable=no-member
                                     message="Test error on %s and Test failure" % (when, )))
                if hasattr(failure_reason.attr, "message") and failure_reason.attr.message == "Failure Reason":
                    self.tests[-1].append(failure_reason)
                self.tests[-1][0].extend("\n" + "-" * 80 + "\nTest Case Failure\n" + "-" * 80 + "\n")
                self.tests[-1][0].extend(self.fail_traceback)
            else:
                self.append(
                    self.Junit.error(longrepr,  # pylint: disable=no-member
                                     message="Test error on %s" % (when, )))
        self.errors += 1
        self.failed += 1
XML.py 文件源码 项目:taf 作者: taf3 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def append_xfail(self, report):
        """Append xml report with xfailed TC.

        Args:
            report(dict):  XFail report

        """
        self.class_logger.info("Appending XML report with xfail.")
        self.append(
            self.Junit.skipped(str(xml_unescape(report['keywords']['xfail'])),  # pylint: disable=no-member
                               message="expected test failure"))
XML.py 文件源码 项目:taf 作者: taf3 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def append_failure(self, report):
        """Append xml report with failed TC.

        Args:
            report(dict):  Failure report

        """
        self.class_logger.info("Appending XML report with fail.")
        report['sections'] = [xml_unescape(section) for section in report['sections']]  # pylint: disable=no-member
        sec = dict(report['sections'])
        self.fail_traceback = self.Junit.failure(message="Test failure")  # pylint: disable=no-member
        # Removing BASH escape symbols (decolorizing)
        # longrepr = xml_unescape(re_sub(r"\x1b.*?m", "", report['longrepr']))
        longrepr = xml_unescape(report['longrepr'])
        # TODO: Change str to encode for unicode text

        try:
            self.fail_traceback.append(str(longrepr))
        except UnicodeEncodeError as err:
            self.fail_traceback.append(ud.normalize('NFKD', longrepr))
            self.class_logger.warning("Unicode data in traceback: %s" % (err, ))

        self.append(self.fail_traceback)

        for name in ("out", "err"):
            content = sec.get("Captured std{0}".format(name))
            if content:
                tag = getattr(self.Junit, "system-{0}".format(name))
                self.append(tag(content))
        self.failed += 1
actors.py 文件源码 项目:bernard 作者: leviroth 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _transform_page(self, content):
        content = unescape(content)
        for placeholder, buffer in self.placeholder_dict.items():
            new_text = ", ".join([placeholder] + buffer)
            content = content.replace(placeholder, new_text)
        return content
tableofcontents.py 文件源码 项目:tichu-tournament 作者: aragos 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def unquote(txt):
    from xml.sax.saxutils import unescape
    return unescape(txt, {"&apos;": "'", "&quot;": '"'})
linter.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def replace_entity(match):
        """Return the character corresponding to an HTML entity."""
        number = match.group(2)

        if number:
            hex = match.group(1) is not None
            result = chr(int(number, 16 if hex else 10))
        else:
            entity = match.group(3)
            result = unescape(entity, html.entities.html5)

        return result
utils.py 文件源码 项目:xblock-video 作者: appsembler 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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))
    )
utils.py 文件源码 项目:xblock-video 作者: appsembler 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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))
    )
utils.py 文件源码 项目:xblock-video 作者: appsembler 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def remove_escaping(text):
    """
    Clean text from special `escape` symbols.

    Reference: https://wiki.python.org/moin/EscapingHtml.
    """
    html_unescape_table = {
        "&amp;": "&",
        "&quot;": '"',
        "&amp;#39;": "'",
        "&apos;": "'",
        "&gt;": ">",
        "&lt;": "<"
    }
    return unescape(text, html_unescape_table)


问题


面经


文章

微信
公众号

扫码关注公众号