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


Python escape.xhtml_unescape函数代码示例

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


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

示例1: replace_post

def replace_post(post_data):
    d = {
        "id": 5,
        "title":        "my blog post title",
        "slug":         "my-blog-post-title",
        "markdown":     "the *markdown* formatted post body",
        #"html":         "the <i>html</i> formatted post body",
        "image":        None,
        "featured":     0,
        "page":         0,
        "status":       "published",
        "language":     "zh_CN",
        "meta_title":   None,
        "meta_description": None,
        "author_id":    1,
        "created_at":   cur_timestamp(),
        "created_by":   1,
        "updated_at":   cur_timestamp(),
        "updated_by":   1,
        "published_at": cur_timestamp(),
        "published_by": 1
    }
    d['id'] = int(post_data['source_url'].rsplit('/', 1)[1].split('.')[0])
    d['title'] = post_data['title'].strip()
    d['slug'] = post_data['title'].strip().replace(' ', '-').lower()
    d['markdown'] = xhtml_unescape(post_data['content'].strip())    # unescape
    return d
开发者ID:PegasusWang,项目名称:articles,代码行数:27,代码来源:sharejs_to_ghost.py

示例2: normalize

def normalize(sentence):
    """
    コメントを正規化する
    :param str sentence: 正規化するコメント
    :return: 正規化されたコメント
    :rtype: str
    """

    dst = escape.xhtml_unescape(sentence)

    if _re_escape.findall(dst):
        return ""

    # か゛(u'\u304b\u309b')" -> が(u'\u304b \u3099')
    #  -> が(u'\u304b\u3099') -> が(u'\u304c')
    # dst = unicodedata.normalize("NFKC", "".join(unicodedata.normalize("NFKC", dst).split()))
    dst = dst.lower()
    dst = "".join(dst.split())
    try:
        dst = _convert_marks(dst)
    except:
        print "convertError"
    dst = _re_remove.sub("", dst)
    dst = _delete_cyclic_word(dst)

    return dst
开发者ID:ItoTomoki,项目名称:ruiternews,代码行数:26,代码来源:normalizer.py

示例3: parse_cases

def parse_cases(filename):
  """Parses the fogbugz data in the file.

  Returns a list of (subject, assigned_to, body) tuples.
  """
  results = []

  tree = ElementTree.parse(filename)

  for case in tree.find('cases').findall('case'):
    subject = 'FB%s: %s' % (case.get('ixBug'), case.findtext('sTitle'))
    body = []
    assigned_to = case.findtext('sPersonAssignedTo')
    body.append('Assigned to: %s' % assigned_to)
    body.append('Project: %s' % case.findtext('sProject'))
    body.append('Area: %s' % case.findtext('sArea'))
    body.append('Priority: %s (%s)' % (case.findtext('ixPriority'), case.findtext('sPriority')))
    body.append('Category: %s' % case.findtext('sCategory'))
    body.append('')
    for event in case.find('events').findall('event'):
      body.append( '%s at %s' % (event.findtext('evtDescription'), event.findtext('dt')))
      if event.findtext('s'):
        body.append('')
        body.append(event.findtext('s'))
        body.append('')
      if event.find('rgAttachments') is not None:
        for attachment in event.find('rgAttachments').findall('attachment'):
          body.append('Attachment: %s' % escape.xhtml_unescape(attachment.findtext('sURL')))
    results.append((subject, USER_MAP[assigned_to], '\n'.join(body)))
  return results
开发者ID:00zhengfu00,项目名称:viewfinder,代码行数:30,代码来源:parse_cases.py

示例4: edit_card

    def edit_card(self, message):
        id = message['data']['id']
        text = xhtml_unescape(message['data']['value'].strip())
        clean_data = {'value': text, 'id': id}

        message_out = self.generate_message('editCard', clean_data)
        self.broadcast(message_out)
        room_id = self.rooms.get_room_id(self)
        self.cards.update_text(room_id, card_id=id, text=xhtml_escape(text))
开发者ID:Hironsan,项目名称:Brain_Hacker,代码行数:9,代码来源:room_handler.py

示例5: test_xhtml_escape

    def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            ("<foo>", "&lt;foo&gt;"),
            (b("<foo>"), b("&lt;foo&gt;")),

            ("<>&\"", "&lt;&gt;&amp;&quot;"),
            ("&amp;", "&amp;amp;"),
            ]
        for unescaped, escaped in tests:
            self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
            self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped)))
开发者ID:e1ven,项目名称:Waymoot,代码行数:12,代码来源:escape_test.py

示例6: test_xhtml_unescape_numeric

 def test_xhtml_unescape_numeric(self):
     tests = [
         ('foo&#32;bar', 'foo bar'),
         ('foo&#x20;bar', 'foo bar'),
         ('foo&#X20;bar', 'foo bar'),
         ('foo&#xabc;bar', u'foo\u0abcbar'),
         ('foo&#xyz;bar', 'foo&#xyz;bar'),  # invalid encoding
         ('foo&#;bar', 'foo&#;bar'),        # invalid encoding
         ('foo&#x;bar', 'foo&#x;bar'),      # invalid encoding
     ]
     for escaped, unescaped in tests:
         self.assertEqual(unescaped, xhtml_unescape(escaped))
开发者ID:leeclemens,项目名称:tornado,代码行数:12,代码来源:escape_test.py

示例7: test_xhtml_escape

 def test_xhtml_escape(self):
     tests = [
         ("<foo>", "&lt;foo&gt;"),
         (u"<foo>", u"&lt;foo&gt;"),
         (b"<foo>", b"&lt;foo&gt;"),
         ("<>&\"'", "&lt;&gt;&amp;&quot;&#39;"),
         ("&amp;", "&amp;amp;"),
         (u"<\u00e9>", u"&lt;\u00e9&gt;"),
         (b"<\xc3\xa9>", b"&lt;\xc3\xa9&gt;"),
     ]  # type: List[Tuple[Union[str, bytes], Union[str, bytes]]]
     for unescaped, escaped in tests:
         self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
         self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped)))
开发者ID:bdarnell,项目名称:tornado,代码行数:13,代码来源:escape_test.py

示例8: post

 def post(self):
     user = self.current_user
     for x in ('location','twitter','github','css','words'):
         user[x] = xhtml_unescape(self.get_argument(x,''))
         for x in set(html_killer.findall(user[x])):
             user[x] = user[x].replace(x,'')
     website = self.get_argument('website','')
     w = urlparse(website)
     if w[0] and w[1]:
         user['website'] = website
     else:
         user['website'] = ''
     self.db.users.save(user)
     self.redirect('/user/%s' % user['username'] )
开发者ID:henter,项目名称:PBB,代码行数:14,代码来源:auth.py

示例9: _get_articel_info

 def _get_articel_info(self, article_info, nick_name, ori_create_time):
     for k, v in article_info.items():
         if isinstance(v, str):
             article_info[k] = xhtml_unescape(v)
     article_dict = {
         'cdn_url': article_info['cover'].replace('\\', ''),
         'title': article_info['title'],
         'nick_name': nick_name,
         'link': ('http://mp.weixin.qq.com' +
                  article_info['content_url'].replace('\\', '')),
         'ori_create_time': ori_create_time,
         'desc': article_info['digest'],
     }
     return article_dict
开发者ID:PegasusWang,项目名称:wechannel,代码行数:14,代码来源:sg.py

示例10: on_message

 def on_message(self, message_json):
   message = json.loads(message_json)
   if message['type'] == 'start':
     self.game.start_game()
   elif message['type'] == 'update':
     self.game.request_update(self)
   elif message['type'] == 'chat':
     self.game.add_chat(xhtml_unescape(message['name']), message['message'], "chat")
   elif message['type'] == 'pause':
     self.game.pause(message['pause'])
   elif message['type'] == 'submit':
     self.game.submit_tau(self, message['cards'])
   elif message['type'] == 'training_option':
     self.game.set_training_option(message['option'], message['value'])
开发者ID:malcolmsharpe,项目名称:websockettau,代码行数:14,代码来源:tau.py

示例11: test_xhtml_escape

    def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u("<foo>"), u("&lt;foo&gt;")),
            (b"<foo>", b"&lt;foo&gt;"),

            ("<>&\"'", "&lt;&gt;&amp;&quot;&#39;"),
            ("&amp;", "&amp;amp;"),

            (u("<\u00e9>"), u("&lt;\u00e9&gt;")),
            (b"<\xc3\xa9>", b"&lt;\xc3\xa9&gt;"),
        ]
        for unescaped, escaped in tests:
            self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
            self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped)))
开发者ID:YoungLeeNENU,项目名称:tornado,代码行数:15,代码来源:escape_test.py

示例12: fun_article_new_src

def fun_article_new_src(user, article_id='-1', article_type='blog', src_type='code',
            title='', body='', source='', code_type='python', math_type='inline', father_id='-1', group_id='-1'):
    if article_type not in Article_Type:
        return [1, '不支持当前文章类型!']
    if src_type not in Agree_Src:
        return [1, '不支持当前类型的资源!']
        
    if title is None:
        return [1, '名称不能为空!']
        
    if body is None:
        if src_type != 'reference':
            return [1, '内容不能为空!']
        else:
            if re.search(r'^(http|https|ftp):\/\/.+$', source) is None:
                return [1, '请填写链接地址或者引用真实内容!']
            body = ''
    else:
        if src_type == 'math':    
            body = math_encode(escape.xhtml_unescape(body))
        elif src_type == 'code':
            if code_type not in Agree_Code:
                return [1, '请选择代码种类!']
    
    if article_type == "about":
        AF_Object = user.about
        article_id = str(user.about._id)
        isnew = False
    elif article_type == "book-about":
        isnew = False
        try:
            book = Catalog(_id=group_id)
            AF_Object = book.about
            limit = book.authority_verify(user)
            if test_auth(limit, A_WRITE) is False:
                return [1, '您无权修改摘要!']
        except Exception, err:
            logging.error(traceback.format_exc())
            logging.error('Catalog not exist, id %s' % group_id)
            return [1, '未找到知识谱!']
开发者ID:deju,项目名称:afw_old,代码行数:40,代码来源:AF_EditTool.py

示例13: clean_url

def clean_url(url):
    """
    Returns an cleaned url starting with a scheme and folder with trailing /
    or an empty string
    """

    if url and url.strip():
        url = xhtml_unescape(url.strip())

        if '://' not in url:
            url = '//' + url

        scheme, netloc, path, query, fragment = parse.urlsplit(url, 'http')
        if not path:
            path += '/'

        cleaned_url = parse.urlunsplit((scheme, netloc, path, query, fragment))

    else:
        cleaned_url = ''

    return cleaned_url
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:22,代码来源:config.py

示例14: convert_text_html

def convert_text_html(message):
    """Linkify URLs and turn newlines into <br/> for HTML"""
    html = xhtml_unescape(tornado_linkify(message))
    return html.replace('\n', '<br/>')
开发者ID:anupriyatripathi,项目名称:qiita,代码行数:4,代码来源:util.py

示例15: make_mobi

    def make_mobi(user, feeds, data_dir, kindle_format='book',
                  mobi_templates=None, **other_services):
        """docstring for make_mobi"""
        is_updated = False
        for feed in feeds:
            if len(feed.items) > 0:
                is_updated = True
        if not is_updated:
            logging.info("no feed update.")
            return None

        if kindle_format not in ['book', 'periodical']:
            kindle_format = 'book'
        logging.info("generate .mobi file start... ")

        if not mobi_templates:
            from kindletemplate import TEMPLATES
            mobi_templates = TEMPLATES
        for tpl in mobi_templates:
            if tpl is 'book.html':
                continue

            t = template.Template(mobi_templates[tpl])
            content = t.generate(
                user=user,
                feeds=feeds,
                uuid=uuid.uuid1(),
                format=kindle_format,
                **other_services
            )

            fp = open(os.path.join(data_dir, tpl), 'wb')
            content = content.decode('utf-8', 'ignore').encode('utf-8')
            fp.write(escape.xhtml_unescape(content))
            # fp.write(content)
            fp.close()

        pre_mobi_file = "TheOldReader_%s" % time.strftime('%m-%dT%Hh%Mm')
        opf_file = os.path.join(data_dir, "content.opf")
        os.environ["PATH"] = os.environ["PATH"] + ":./"
        subprocess.call('%s %s -o "%s" > log.txt' %
                        (Kindle.kindle_gen_prog, opf_file, pre_mobi_file),
                        shell=True)
        pre_mobi_file = os.path.join(data_dir, pre_mobi_file)
        mobi_file = pre_mobi_file+".mobi"
        status = subprocess.call(
            'kindlestrip.py "%s" "%s" >> log.txt' %
            (pre_mobi_file, mobi_file), shell=True)

        if 0 != status:
            import shutil
            shutil.move(pre_mobi_file, mobi_file)

        if os.path.isfile(mobi_file) is False:
            logging.error("failed!")
            return None
        else:
            fsize = os.path.getsize(mobi_file)
            logging.info(".mobi save as: %s(%.2fMB)" %
                         (mobi_file, float(fsize)/(1024*1024)))
            return mobi_file
开发者ID:fireinice,项目名称:kindlereader2,代码行数:61,代码来源:Reader.py


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