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

Python web.decode函数代码示例

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

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



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

示例1: tr

def tr(jenni, context):
    """Translates a phrase, with an optional language hint."""
    input, output, phrase = context.groups()

    phrase = phrase.encode('utf-8')

    if (len(phrase) > 350) and (not context.admin):
        return jenni.reply('Phrase must be under 350 characters.')

    input = input or 'auto'
    input = input.encode('utf-8')
    output = (output or 'en').encode('utf-8')

    if input != output:
        msg, input = translate(phrase, input, output)
        if isinstance(msg, str):
            msg = msg.decode('utf-8')
        if msg:
            msg = web.decode(msg)
            msg = '"%s" (%s to %s, translate.google.com)' % (msg, input, output)
        else:
            msg = 'The %s to %s translation failed, sorry!' % (input, output)

        jenni.reply(msg)
    else:
        jenni.reply('Language guessing failed, so try suggesting one!')
开发者ID:Dippyskoodlez,项目名称:brittbot,代码行数:26,代码来源:translate.py


示例2: tr

def tr(jenni, context): 
    """Translates a phrase, with an optional language hint."""
    input, output, phrase = context.groups()

    phrase = phrase.encode('utf-8')

    if (len(phrase) > 350) and (not context.admin): 
        return jenni.reply('Phrase must be under 350 characters.')

    input = input or detect(phrase)
    if not input: 
        err = 'Unable to guess your crazy moon language, sorry.'
        return jenni.reply(err)
    input = input.encode('utf-8')
    output = (output or 'en').encode('utf-8')

    if input != output: 
        msg = translate(phrase, input, output)
        if msg: 
            msg = web.decode(msg) # msg.replace(''', "'")
            msg = '"%s" (%s to %s, translate.google.com)' % (msg, input, output)
        else: msg = 'The %s to %s translation failed, sorry!' % (input, output)

        jenni.reply(msg)
    else: jenni.reply('Language guessing failed, so try suggesting one!')
开发者ID:Kitsueki,项目名称:jenni,代码行数:25,代码来源:translate.py


示例3: escape

 def escape(seq):
     seq = seq.decode('unicode-escape')
     seq = seq.replace(u'\xc2\xa0', ',')
     seq = seq.replace('<sup>', '^(')
     seq = seq.replace('</sup>', ')')
     seq = web.decode(seq)
     return seq
开发者ID:Kitsueki,项目名称:jenni,代码行数:7,代码来源:calc.py


示例4: tr

def tr(phenny, context):
    """Translates a phrase, with an optional language hint."""
    input, output, phrase = context.groups()

    phrase = phrase.encode("utf-8")

    if (len(phrase) > 350) and (not context.admin):
        return phenny.reply("Phrase must be under 350 characters.")

    input = input or "auto"
    input = input.encode("utf-8")
    output = (output or "en").encode("utf-8")

    if input != output:
        msg, input = translate(phrase, input, output)
        if isinstance(msg, str):
            msg = msg.decode("utf-8")
        if msg:
            msg = web.decode(msg)  # msg.replace('&#39;', "'")
            msg = '"%s" (%s to %s, translate.google.com)' % (msg, input, output)
        else:
            msg = "The %s to %s translation failed, sorry!" % (input, output)

        phenny.reply(msg)
    else:
        phenny.reply("Unable to guess your crazy moon language, sorry. Maybe you can suggest one?")
开发者ID:andreaja,项目名称:ircbot,代码行数:26,代码来源:translate.py


示例5: tr

def tr(torp, context):
    """Translates a phrase, with an optional language hint."""
    input, output, phrase = context.groups()

    phrase = phrase.encode("utf-8")

    if (len(phrase) > 350) and (not context.admin):
        return torp.reply("Phrase must be under 350 characters.")

    input = input or detect(phrase)
    if not input:
        err = "Unable to guess your crazy moon language, sorry."
        return torp.reply(err)
    input = input.encode("utf-8")
    output = (output or "en").encode("utf-8")

    if input != output:
        msg = translate(phrase, input, output)
        if isinstance(msg, str):
            msg = msg.decode("utf-8")
        if msg:
            msg = web.decode(msg)  # msg.replace('&#39;', "'")
            msg = '"%s" (%s to %s, translate.google.com)' % (msg, input, output)
        else:
            msg = "The %s to %s translation failed, sorry!" % (input, output)

        torp.reply(msg)
    else:
        torp.reply("Language guessing failed, so try suggesting one!")
开发者ID:endenizen,项目名称:torp,代码行数:29,代码来源:translate.py


示例6: tr2

def tr2(phenny, input): 
   """Translates a phrase, with an optional language hint."""
   command = input.group(2).encode('utf-8')

   def langcode(p): 
      return p.startswith(':') and (2 < len(p) < 10) and p[1:].isalpha()

   args = ['auto', 'en']

   for i in xrange(2): 
      if not ' ' in command: break
      prefix, cmd = command.split(' ', 1)
      if langcode(prefix): 
         args[i] = prefix[1:]
         command = cmd
   phrase = command

   if (len(phrase) > 350) and (not input.admin): 
      return phenny.reply('Phrase must be under 350 characters.')

   src, dest = args
   if src != dest: 
      msg, src = translate(phrase, src, dest)
      if isinstance(msg, str): 
         msg = msg.decode('utf-8')
      if msg: 
         msg = web.decode(msg) # msg.replace('&#39;', "'")
         msg = '"%s" (%s to %s, translate.google.com)' % (msg, src, dest)
      else: msg = 'The %s to %s translation failed, sorry!' % (src, dest)

      phenny.reply(msg)
   else: phenny.reply('Language guessing failed, so try suggesting one!')
开发者ID:CreamCoderz,项目名称:phenny,代码行数:32,代码来源:translate.py


示例7: calc

def calc(phenny, input): 
   """Google calculator."""
   if not input.group(2):
      return phenny.reply("Nothing to calculate.")
   q = input.group(2).encode('utf-8')
   q = q.replace('\xcf\x95', 'phi') # utf-8 U+03D5
   q = q.replace('\xcf\x80', 'pi') # utf-8 U+03C0
   uri = 'http://www.google.com/search?q='
   bytes = web.get(uri + web.urllib.quote(q))
   html = lxml.html.fromstring(bytes)
   try:
      answer = html.get_element_by_id("cwos").text_content().strip()
   except KeyError:
      try:
         answer = lxml.etree.tostring(html.find_class("vk_ans")[0])
         answer = answer[answer.find('>')+1:answer.rfind('<')]
      except IndexError:
         answer = None
   if answer:
      answer = web.decode(answer)
      answer = answer.replace(u'\xc2\xa0', ',')
      answer = answer.replace('<sup>', '^(')
      answer = answer.replace('</sup>', ')')
      answer = answer.encode('utf-8')
      phenny.say(answer)
   else: phenny.say('Sorry, no result.')
开发者ID:Mithorium,项目名称:Mithnet,代码行数:26,代码来源:calc.py


示例8: duck_search

def duck_search(query): 
   query = query.replace('!', '')
   query = web.urllib.quote(query)
   uri = 'http://duckduckgo.com/html/?q=%s&kl=uk-en' % query
   bytes = web.get(uri)
   m = r_duck.search(bytes)
   if m: return web.decode(m.group(1))
开发者ID:embolalia,项目名称:phenny,代码行数:7,代码来源:search.py


示例9: c

def c(phenny, input): 
   """Google calculator."""
   for x in phenny.bot.commands["high"].values():
      if x[0].__name__ == "aa_hook":
         if x[0](phenny, input):
            return # Abort function
   if not input.group(2):
      return phenny.reply("Nothing to calculate.")
   q = input.group(2).encode('utf-8')
   q = q.replace('\xcf\x95', 'phi') # utf-8 U+03D5
   q = q.replace('\xcf\x80', 'pi') # utf-8 U+03C0
   print("[LOG]: %s calculated '%s'" % (input.nick,q))
   uri = 'http://www.google.com/ig/calculator?q='
   bytes = web.get(uri + web.urllib.quote(q))
   parts = bytes.split('",')
   answer = [p for p in parts if p.startswith('rhs: "')][0][6:]
   if answer: 
      answer = answer.decode('unicode-escape')
      answer = ''.join(chr(ord(c)) for c in answer)
      answer = answer.decode('utf-8')
      answer = answer.replace(u'\xc2\xa0', ',')
      answer = answer.replace('<sup>', '^(')
      answer = answer.replace('</sup>', ')')
      answer = web.decode(answer)
      phenny.say(answer)
   else: phenny.say('Sorry, no result.')
开发者ID:Jordach,项目名称:minetestbot-modules,代码行数:26,代码来源:calc.py


示例10: c

def c(jenni, input):
    """.c -- Google calculator."""
    if not input.group(2):
        return jenni.reply('Nothing to calculate.')
    q = input.group(2).encode('utf-8')
    q = q.replace('\xcf\x95', 'phi')  # utf-8 U+03D5
    q = q.replace('\xcf\x80', 'pi')  # utf-8 U+03C0
    uri = 'https://www.google.com/ig/calculator?q='
    bytes = web.get(uri + web.urllib.quote(q))
    parts = bytes.split('",')
    equation = [p for p in parts if p.startswith('{lhs: "')][0][7:]
    answer = [p for p in parts if p.startswith('rhs: "')][0][6:]
    if answer and equation:
        answer = answer.decode('unicode-escape')
        answer = ''.join(chr(ord(c)) for c in answer)
        answer = uc.decode(answer)
        answer = answer.replace(u'\xc2\xa0', ',')
        answer = answer.replace('<sup>', '^(')
        answer = answer.replace('</sup>', ')')
        answer = web.decode(answer)
        answer = answer.strip()
        equation = uc.decode(equation)
        equation = equation.strip()
        max_len = 450 - len(answer) - 6
        new_eq = equation
        if len(new_eq) > max_len:
            end = max_len - 10
            new_eq = new_eq[:end]
            new_eq += '[..]'
        output = '\x02' + answer + '\x02' + ' == ' + new_eq
        jenni.say(output)
    else:
        jenni.say('Sorry, no result.')
开发者ID:jfriedly,项目名称:jenni,代码行数:33,代码来源:calc.py


示例11: clean_up_answer

def clean_up_answer(answer):
    answer = answer.encode('utf-8')
    answer = answer.decode('utf-8')
    answer = ''.join(chr(ord(c)) for c in answer)
    answer = uc.decode(answer)
    answer = answer.replace('<sup>', '^(')
    answer = answer.replace('</sup>', ')')
    answer = web.decode(answer)
    answer = answer.strip()
    answer += ' [GC]'
    return answer
开发者ID:jkfresh,项目名称:jenni,代码行数:11,代码来源:calc.py


示例12: c

def c(phenny, input):
    """Google calculator."""
    if not input.group(2):
        return phenny.reply("Nothing to calculate.")
    q = input.group(2)
    bytes = generic_google(q)
    m = r_google_calc_exp.search(bytes)
    if not m:
        m = r_google_calc.search(bytes)

    if not m:
        num = None
    elif m.lastindex == 1:
        num = web.decode(m.group(1))
    else:
        num = "^".join((web.decode(m.group(1)), web.decode(m.group(2))))

    if num:
        num = num.replace('×', '*')
        phenny.say(num)
    else:
        phenny.reply("Sorry, no result.")
开发者ID:mutantmonkey,项目名称:phenny,代码行数:22,代码来源:calc.py


示例13: imdb_search

def imdb_search(query):
    query = query.replace('!', '')
    query = web.quote(query)
    uri = 'http://imdb.com/find?q=%s' % query
    bytes = web.get(uri)
    m = r_imdb_find.search(bytes)
    if not m: return m
    ID = web.decode(m.group(1))
    uri = 'http://imdb.com/title/%s' % ID
    bytes = web.get(uri)
    bytes = bytes.replace('\n', '')
    info = r_imdb_details.search(bytes)
    info = {'Title': info.group(1), 'Year': info.group(2), 'Plot': info.group(3), 'imdbID': ID}
    return info
开发者ID:mutantmonkey,项目名称:phenny,代码行数:14,代码来源:imdb.py


示例14: c

def c(phenny, input): 
   """Google calculator."""
   q = input.group(2).encode('utf-8')
   q = q.replace('\xcf\x95', 'phi') # utf-8 U+03D5
   q = q.replace('\xcf\x80', 'pi') # utf-8 U+03C0
   uri = 'http://www.google.com/ig/calculator?q='
   bytes = web.get(uri + web.urllib.quote(q))
   parts = bytes.split('",')
   answer = [p for p in parts if p.startswith('rhs: "')][0][6:]
   if answer: 
      answer = answer.decode('unicode-escape')
      answer = answer.replace(u'\xc2\xa0', ',')
      answer = answer.replace('<sup>', '^(')
      answer = answer.replace('</sup>', ')')
      answer = web.decode(answer)
      phenny.say(answer)
   else: phenny.say('Sorry, no result.')
开发者ID:Robopoly,项目名称:phenny,代码行数:17,代码来源:calc.py


示例15: apertium_translate

def apertium_translate(phenny, input): 
   """Translates a phrase using the apertium API"""
   line = input.group(2)
   if not line:
      raise GrumbleError("Need something to translate!")
   #line = line.encode('utf-8')

   pairs = []
   guidelines = line.split('|')
   if len(guidelines) > 1:
      for guideline in guidelines[1:]:
         #phenny.say(guideline)
         pairs.append(guideline.strip().split('-'))
   guidelines = guidelines[0]
   #phenny.say("guidelines: "+str(guidelines))
   stuff = re.search('(.*) ([a-z]+-[a-z]+)', guidelines)
   #phenny.say('groups: '+str(stuff.groups()))
   pairs.insert(0, stuff.group(2).split('-'))
   translate_me = stuff.group(1)
   #phenny.say(str(pairs))

   #output_lang = line.split(' ')[-1]
   #input_lang = line.split(' ')[-2]
   #translate_me = ' '.join(line.split(' ')[:-2])

   if (len(translate_me) > 350) and (not input.admin): 
      raise GrumbleError('Phrase must be under 350 characters.')

   msg = translate_me
   finalmsg = False
   translated = ""
   for (input_lang, output_lang) in pairs:
      if input_lang == output_lang: 
         raise GrumbleError('Stop trying to confuse me!  Pick different languages ;)')
      msg = translate(msg, input_lang, output_lang)
      if not msg:
         raise GrumbleError('The %s to %s translation failed, sorry!' % (input_lang, output_lang))
      msg = web.decode(msg) # msg.replace('&#39;', "'")
      this_translated = "(%s-%s) %s" % (input_lang, output_lang, msg)
      translated = msg

   #if not finalmsg:
   #   finalmsg = translated
   #phenny.reply(finalmsg)
   phenny.reply(translated)
开发者ID:KaiCode2,项目名称:phenny,代码行数:45,代码来源:apertium_translate.py


示例16: convertvals

def convertvals(imperial):
   q = imperial
   q = q.replace('\xcf\x95', 'phi') # utf-8 U+03D5
   q = q.replace('\xcf\x80', 'pi') # utf-8 U+03C0
   uri = 'http://www.google.com/ig/calculator?q='
   bytes = web.get(uri + web.urllib.quote(q))
   parts = bytes.split('",')
   answer = [p for p in parts if p.startswith('rhs: "')][0][6:]
   if answer:
      answer = answer.decode('unicode-escape')
      answer = ''.join(chr(ord(c)) for c in answer)
      answer = answer.decode('utf-8')
      answer = answer.replace(u'\xc2\xa0', ',')
      answer = answer.replace('<sup>', '^(')
      answer = answer.replace('</sup>', ')')
      answer = web.decode(answer)
      return answer
   else: return 0
开发者ID:evanjfraser,项目名称:bikebot,代码行数:18,代码来源:bikebot.py


示例17: devwiki

def devwiki(phenny, input):
	term = input.group(2)
	if not term:
		return

	log.log("event", "%s queried Developer Wiki for '%s'" % (log.fmt_user(input), term), phenny)
	term = term.replace(" ", "_")
	term = web.urlencode(term)

	data, scode = web.get(wikiuri_g % term)
	if scode == 404:
		return phenny.say("No such page.")
	data = str(data, "utf-8")

	m = re.search(r_content, data)
	if not m:
		return phenny.say("Sorry, did not find any text to display. Here's the link: %s" % (wikiuri_r % term,))
	data = data[m.span()[1]:]

	mi = re.finditer(r_paragraph, data)
	text = ""
	for m in mi:
		abort = False
		for e in nottext:
			if re.search(e, m.group(1)):
				abort = True
				break
		if abort:
			continue
		text = m.group(1)
		break
	if not text:
		m = re.search(r_headline, data)
		if m:
			text = "<b>" + m.group(1) + "</b>"
		else:
			return phenny.say("Sorry, did not find any text to display. Here's the link: %s" % (wikiuri_r % term,))
	for tf in transforms:
		text = re.sub(tf[0], tf[1], text)
	m = re.search(r_sentenceend, text)
	if m:
		text = text[:m.span()[1]-1]
	phenny.say('"%s" - %s' % (web.decode(text), wikiuri_r % term))
开发者ID:jamestait,项目名称:minetestbot-modules,代码行数:43,代码来源:devwiki.py


示例18: c

def c(phenny, input): 
    """Google calculator."""
    if not input.group(2):
        return phenny.reply("Nothing to calculate.")
    q = input.group(2)
    q = q.replace('\xcf\x95', 'phi') # utf-8 U+03D5
    q = q.replace('\xcf\x80', 'pi') # utf-8 U+03C0
    uri = 'http://www.google.com/ig/calculator?q='
    bytes = web.get(uri + web.quote(q))
    parts = bytes.split('",')
    answer = [p for p in parts if p.startswith('rhs: "')][0][6:]
    if answer: 
        #answer = ''.join(chr(ord(c)) for c in answer)
        #answer = answer.decode('utf-8')
        answer = answer.replace('\xc2\xa0', ',')
        answer = answer.replace('<sup>', '^(')
        answer = answer.replace('</sup>', ')')
        answer = web.decode(answer)
        phenny.say(answer)
    else: phenny.say('Sorry, no result.')
开发者ID:LordTroan,项目名称:phenny,代码行数:20,代码来源:calc.py


示例19: tr

def tr(phenny, context): 
    """Translates a phrase, with an optional language hint."""
    input, output, phrase = context.groups()

    phrase = phrase

    if (len(phrase) > 350) and (not context.admin): 
        return phenny.reply('Phrase must be under 350 characters.')

    input = input or 'auto'
    output = (output or 'en')

    if input != output: 
        msg, input = translate(phrase, input, output)
        if msg: 
            msg = web.decode(msg) # msg.replace('&#39;', "'")
            msg = '"%s" (%s to %s, translate.google.com)' % (msg, input, output)
        else: msg = 'The %s to %s translation failed, sorry!' % (input, output)

        phenny.reply(msg)
    else: phenny.reply('Language guessing failed, so try suggesting one!')
开发者ID:Athemis,项目名称:phenny,代码行数:21,代码来源:translate.py


示例20: tr2

def tr2(phenny, input):
    """Translates a phrase, with an optional language hint."""
    command = input.group(2)
    if not command:
        return phenny.reply("Need something to translate!")
    command = command.encode("utf-8")

    def langcode(p):
        return p.startswith(":") and (2 < len(p) < 10) and p[1:].isalpha()

    args = ["auto", "en"]

    for i in xrange(2):
        if not " " in command:
            break
        prefix, cmd = command.split(" ", 1)
        if langcode(prefix):
            args[i] = prefix[1:]
            command = cmd
    phrase = command

    # if (len(phrase) > 350) and (not input.admin):
    #    return phenny.reply('Phrase must be under 350 characters.')

    src, dest = args
    if src != dest:
        msg, src = translate(phrase, src, dest)
        if isinstance(msg, str):
            msg = msg.decode("utf-8")
        if msg:
            msg = web.decode(msg)  # msg.replace('&#39;', "'")
            if len(msg) > 450:
                msg = msg[:450] + "[...]"
            msg = '"%s" (%s to %s, translate.google.com)' % (msg, src, dest)
        else:
            msg = "The %s to %s translation failed, sorry!" % (src, dest)

        phenny.reply(msg)
    else:
        phenny.reply("Unable to guess your crazy moon language, sorry. Maybe you can suggest one?")
开发者ID:andreaja,项目名称:ircbot,代码行数:40,代码来源:translate.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python web.forbidden函数代码示例发布时间:2022-05-26
下一篇:
Python web.debug函数代码示例发布时间: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