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

Python request.unquote函数代码示例

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

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



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

示例1: handle_request

    def handle_request(self, data=None):
        """Handles both POST and GET reqs.
        
        In case of GET there's no data. 
        It also extracts data from the url path (regex groups) and passes it to
        the appropriate end-handler func. """
        
        thread_name = threading.current_thread().name
        print(thread_name, self.raw_requestline)
        
        # resolve request path to end-handler function
        # (url) unquote the request path so that eventual unicode codes (%<code>) are converted back to unicode chars
        delegations = [(re.fullmatch(url_pattern, unquote(self.path)), action) 
                for url_pattern, action in BackOfficeReqHandler.REQUEST_HANDLERS.items() 
                if re.fullmatch(url_pattern, unquote(self.path)) is not None]

        # for an existing request path there should be exactly one handler func.
        if len(delegations) == 1:
            delegate = delegations[0]
            args = self,
            if data is not None: # if there is POST data
                args = args + (data,)
            for group in delegate[0].groups(): # if there are more args to be extracted from the request url (e.g. user, month, year)
                args = args + (group,)
            try:
                return delegate[1](*args) # call the appropriate handler func
            finally:
                self.wfile.flush()
        else: # error: page doesn't exist
            self.send_response(404)
            self.end_headers()
            self.wfile.write(str.encode("The requested page {page} is not found!".format(page=self.path), 'utf-8'))
            self.wfile.flush()
            return
开发者ID:goroglev,项目名称:Levente-Karoly-Gorog,代码行数:34,代码来源:back_office.py


示例2: google

def google(bot, nick, chan, arg):
    """ google <arg> -> Return the google result for <arg> """
    if not arg:
        return bot.msg(chan, get_doc())
    args = arg.split()
    print(args)
    if re.match(r"-\d*", args[0]):
        count = int(args[0][1:])
        query = ' '.join(args[1:])
        print(count, query)
    else:
        count = 1
        query = arg

    url = "http://ajax.googleapis.com/ajax/services/search/web"
    params = {"v": "1.0", "safe": "off", "q":  query}
    data = requests.get(url, params=params)
    data = data.json()

    results = data["responseData"]["results"]

    if not results:
        bot.msg(chan, "%s: No results found." % (nick))

    for i in range(0, count):
        result_url = unquote(unquote(results[i]["url"]))
        result_title = unescape(results[i]["titleNoFormatting"])
        bot.msg(chan, "\x02%s\x02 ⟶ %s" % (bot.style.color(result_title, color="grey"), bot.style.underline(bot.hicolor(result_url))))
开发者ID:svkampen,项目名称:James,代码行数:28,代码来源:google.py


示例3: get_file_route

def get_file_route(path, filename):
	path = path.replace('//', '/')
	save_location = client_settings['LOCAL_SAVE_LOCATION']
	file_location = '%s/%s' % (save_location, path)
	response_file = '%s/%s' % (file_location, filename)
	if os.path.isdir(response_file):
		return redirect('%s/' % response_file, 301)
	else:
		return send_from_directory(unquote(file_location), unquote(filename))
开发者ID:StackIQ,项目名称:stacki,代码行数:9,代码来源:ludicrous-client.py


示例4: prefix_query

    def prefix_query(self, prefix, include_doc=True):
        prefix_path = self.get_path(prefix)

        ret = []
        for k,v in self.data.items():
            if k.startswith(prefix_path):
                if include_doc:
                    ret.append({'key':unquote(k).split('!'), 'doc':v})
                else:
                    ret.append(unquote(k).split('!'))

        return ret
开发者ID:cafeinecake,项目名称:Hearthy,代码行数:12,代码来源:memorydb.py


示例5: add_song

 def add_song(self):
     # Get stuff out of the URL
     path = self.path.split("/")
     artist = unquote(path[2])
     album = unquote(path[3])
     song = unquote(path[4])
     # Get the corresponding objects
     artist = collection.get_artist(artist)
     album = artist.find_album(album)
     song = album.find_song(song)
     # Add the song to the queue
     music.add_song(song.path)
开发者ID:jlucas95,项目名称:music_server,代码行数:12,代码来源:httpTest.py


示例6: parseRequest

 def parseRequest(self, strng, encoding):
     
     self.original_request=strng
     x=strng.split('&')
     for v in x:
         y=v.split('=')
         if len(y)>1:
             if(self.parameters.get(y[0]))==None:
                 self.parameters[REQUEST.unquote(y[0],encoding).replace('+',' ')]=[REQUEST.unquote(y[1],encoding).replace('+',' ')]
             else:
                 self.parameters[REQUEST.unquote(y[0],encoding).replace('+',' ')].append(REQUEST.unquote(y[1],encoding).replace('+',' '))
                          
     pass   
开发者ID:mgshow,项目名称:xlews,代码行数:13,代码来源:IO.py


示例7: buildRequest

    def buildRequest(self, strVar, query, isCmd, isHeader, header=None):
        if "[random]" in strVar:
            strVar = strVar.replace("[random]", core.txtproc.rndString(16))
        if isHeader:
            if (header == "cookie"):
                query = request.quote(query)
                strVar = strVar.replace("%3b", "[semicolon]")
                strVar = request.unquote(strVar)            
                strVar = strVar.replace("; ", "COOKIESEPARATOR").replace("=", "COOKIEEQUAL").replace(";", "COOKIESEPARATOR")
                strVar = strVar.replace("[semicolon]", ";")
                strVar = strVar.replace("[eq]", "=")
                strVar = strVar.replace("[", "LEFTSQBRK").replace("]", "RIGHTSQBRK")
                strVar = request.quote(strVar)
                strVar = strVar.replace("COOKIESEPARATOR", "; ").replace("COOKIEEQUAL", "=")\
                .replace("LEFTSQBRK", "[").replace("RIGHTSQBRK", "]")
        else:
            strVar = strVar.replace("[eq]", "=")

        if isCmd:
            if "[cmd]" in strVar:
                strVar = strVar.replace("[cmd]", query)
                if "[sub]" in strVar:
                    strVar = strVar.replace("[sub]", "null")
        else:
            if "[cmd]" in strVar:
                strVar = strVar.replace(";[cmd]", "").replace("%3B[cmd]", "")
            strVar = strVar.replace("[sub]", query)

        if "[blind]" in strVar:
            strVar = strVar.replace("[blind]", query)
            
        return strVar
开发者ID:Lookindir,项目名称:enema,代码行数:32,代码来源:http.py


示例8: _imageinfo_from_filename

    def _imageinfo_from_filename(self, path):
        """Parse some format:

        >>> fmt = "rootfs:<vendor>:<arch>:<version>.<suffix.es>"
        >>> ImageDiscoverer(None)._imageinfo_from_filename(fmt)
        <Image vendorid=<vendor> version=<version> \
path=rootfs:<vendor>:<arch>:<version>.<suffix.es> />
        """
        filename = os.path.basename(path)
        log.debug("Parsing filename: %s" % filename)

        # We need to unquote the filename, because it can be an ULR with
        # escaped chars (like the :)
        parts = unquote(filename).split(":")

        assert parts.pop(0) == "rootfs", "Only supporting rootfs images"

        info = RemoteImage(self.remote)
        info.path = path
        info.vendorid = parts.pop(0)
        info.arch = parts.pop(0)
        # Strip an eventual suffix
        info.version, sep, info.suffix = parts.pop(0).partition(".")

        return info
开发者ID:evol262,项目名称:imgbased,代码行数:25,代码来源:remote.py


示例9: __init__

    def __init__(self, url, request = None, is_url_page = False):
        if request:
            url += '{}/'.format(request)

        if not is_url_page:
            super().__init__(url)
            self.url = unquote(split(r'\?', url)[0]) + '/'
            # get name of the city
            city = split(r'/', url)[3]
            self.city = ''
            for (ru, en) in cities.items():
                if en == city:
                    self.city = ru
                    break
        else:
            self.page = url
            self.url = None

        self._bs = BeautifulSoup(self.page, 'html.parser')
        firm_num = split(' ',
                            self._bs.find('h1', class_='searchResults__headerName').text
                         )[0]

        num = toint(firm_num)
        if num:
            self.num_pages = ceil(num/12)
        else:
            self.num_pages = 1

        self.page_num = int(self._bs.find('span', class_='pagination__page _current').string)
开发者ID:artemutin,项目名称:outsourceScraper,代码行数:30,代码来源:GisDictionaryScraper.py


示例10: _on_success

    def _on_success(self, resp, paging):
        """ This can be overridden in user-defined blocks.

        Defines how successful polling requests will be handled.

        """
        self._reset_retry_cycle()

        signals, paging = self._process_response(resp)
        self.logger.debug('signals pre-remove-duplicates: %s' % signals)
        signals = self._discard_duplicate_posts(signals)
        self.logger.debug('signals post-remove-duplicates: %s' % signals)

        # add the include_query attribute if it is configured
        if self.include_query() and signals is not None:
            for s in signals:
                setattr(
                    s, self.include_query(), unquote(self.current_query)
                )

        if signals:
            self.notify_signals(signals)

        if paging:
            self.page_num += 1
            self._paging()
        else:
            self._epilogue()
开发者ID:nio-blocks,项目名称:http_blocks,代码行数:28,代码来源:rest_polling_base.py


示例11: do_GET

    def do_GET(self):
        assert self.path[0] == "/"
        target = unquote(self.path[1:])

        if target == "":
            self.send_response(302)
            self.send_header("Location", "?" + args.initial_target)
            self.end_headers()
            return

        if not target.startswith("?"):
            self.send_response(404)
            self.end_headers()
            return
        target = target[1:]

        ninja_output, ninja_error, exit_code = ninja_dump(target)
        if exit_code == 0:
            page_body = generate_html(parse(ninja_output.strip()))
        else:
            # Relay ninja's error message.
            page_body = "<h1><tt>%s</tt></h1>" % ninja_error

        self.send_response(200)
        self.end_headers()
        self.wfile.write(create_page(page_body).encode("utf-8"))
开发者ID:sphawk,项目名称:ninja,代码行数:26,代码来源:browse.py


示例12: xml_get_text

def xml_get_text(_node):
    """Helper function to get character data from an XML tree"""
    rc = list()
    for node in _node.childNodes:
        if node.nodeType == node.TEXT_NODE:
            rc.append(node.data)
    return unquote(''.join(rc))
开发者ID:OptimalBPM,项目名称:qal,代码行数:7,代码来源:xml_utils.py


示例13: get_mp3_from_url

def get_mp3_from_url(url, folder, converse=True):
    """
    Results are saved in folder folder.
    folder must end with / or \\.
    Relative and absolute paths accepted
    """
    prefix = 'http://incompetech.com'
    split_by = '/music/royalty-free/mp3-royaltyfree/'
    middle = split_by
    try: webpage = urlreq.urlopen(prefix + url).read().decode('utf-8')
    except Exception as e:
        print(e, 'while doing', url)
        return -1
    splitted = webpage.split(split_by)[1]
    extracted = splitted.split('>')[0].strip('"')
    prettier_name = urlreq.unquote(extracted)
    mp3 = prefix + \
          middle + \
          extracted
    f = open(folder + prettier_name, 'wb')
    mp3 = urlreq.urlopen(mp3).read()
    f.write(mp3)
    f.close()
    size = os.stat(folder + prettier_name).st_size
    if converse: print('Downloaded', prettier_name, '\twith size of', size_to_units(size), '.')
    return size
开发者ID:goskas,项目名称:Incompetech-Bulk-Downloader,代码行数:26,代码来源:incompetech_music_downloader.py


示例14: match_data_request

def match_data_request(url):
    html = page_request(url)
    xhash = unquote(re.search('"xhash":"(.+?)"', html).group(1))
    id_match = re.search('"id":"(.+?)"', html).group(1)
    id_sport = re.search('"sportId":(.+?)', html).group(1)
    id_version = re.search('"versionId":(.+?)', html).group(1)
    return id_version, id_sport, id_match, xhash
开发者ID:GaPanda,项目名称:oddsparser,代码行数:7,代码来源:request.py


示例15: get_access_token

    def get_access_token(self,xrenew=False):
        """
        生成人人网认证请求链接
        
        :param xrenew: 如果此值为真,则会强制重新获取access_token,用于更换用户
        """
        
        #获取人人网认证信息
        url = self.info["AUTHORIZE"]

        #拼接请求字段
        
        param = {   "client_id": self.info["API_KEY"],
                    "redirect_uri": self.info["REDIRECT_URL"],
                    "response_type": "token",
                    "display": "popup"
                }
        if xrenew:
            param["x_renew"] = "True"
            
        #生成请求链接  
        request = urlencode(param)
        r_url = "%s?%s" % (url,request)
        
        open_new_tab(r_url)
        self.info["ACCESS_TOKEN"] = \
            unquote(input("请输入浏览器中的access_token:\n"))
        self.config.set("Renren", "access_token", self.info["ACCESS_TOKEN"])          
开发者ID:flymaxty,项目名称:Google-Renren-Sync,代码行数:28,代码来源:RenrenApi.py


示例16: validate

def validate(root, f):
    root = os.path.abspath(root)
    try:
        if os.path.getsize(f) < 80:
            # this is probably a texttest place holder file
            # it is definitely too small to contain a schema
            return
        doc = etree.parse(f)
        schemaLoc = doc.getroot().get(
            '{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation')
        if schemaLoc:
            localSchema = os.path.join(os.path.dirname(
                __file__), '..', '..', 'data', 'xsd', os.path.basename(schemaLoc))
            if os.path.exists(localSchema):
                schemaLoc = localSchema
# if schemaLoc not in schemes: // temporarily disabled due to lxml bug
# https://bugs.launchpad.net/lxml/+bug/1222132
            schemes[schemaLoc] = etree.XMLSchema(etree.parse(schemaLoc))
            schemes[schemaLoc].validate(doc)
            for entry in schemes[schemaLoc].error_log:
                s = unquote(str(entry))
                # remove everything before (and including) the filename
                s = s[s.find(f.replace('\\', '/')) + len(f):]
                print(os.path.abspath(
                    f)[len(root) + 1:].replace('\\', '/') + s, file=sys.stderr)
    except Exception:
        print("Error on parsing '%s'!" % os.path.abspath(
            f)[len(root) + 1:].replace('\\', '/'), file=sys.stderr)
        traceback.print_exc()
开发者ID:fieryzig,项目名称:sumo,代码行数:29,代码来源:schemaCheck.py


示例17: do_GET

    def do_GET(self):
        assert self.path[0] == '/'
        target = unquote(self.path[1:])

        if target == '':
            self.send_response(302)
            self.send_header('Location', '?' + args.initial_target)
            self.end_headers()
            return

        if not target.startswith('?'):
            self.send_response(404)
            self.end_headers()
            return
        target = target[1:]

        ninja_output, ninja_error, exit_code = ninja_dump(target)
        if exit_code == 0:
            page_body = generate_html(parse(ninja_output.strip()))
        else:
            # Relay ninja's error message.
            page_body = '<h1><tt>%s</tt></h1>' % html_escape(ninja_error)

        self.send_response(200)
        self.end_headers()
        self.wfile.write(create_page(page_body).encode('utf-8'))
开发者ID:Lekensteyn,项目名称:ninja,代码行数:26,代码来源:browse.py


示例18: webhook_test

    def webhook_test(self, _, args):
        """
            Test your webhooks from within err.

        The syntax is :
        !webhook test [relative_url] [post content]

        It triggers the notification and generate also a little test report.
        """
        url = args[0] if PY3 else args[0].encode()  # PY2 needs a str not unicode
        content = ' '.join(args[1:])

        # try to guess the content-type of what has been passed
        try:
            # try if it is plain json
            loads(content)
            contenttype = 'application/json'
        except ValueError:
            # try if it is a form
            splitted = content.split('=')
            # noinspection PyBroadException
            try:
                payload = '='.join(splitted[1:])
                loads(unquote(payload))
                contenttype = 'application/x-www-form-urlencoded'
            except Exception as _:
                contenttype = 'text/plain'  # dunno what it is

        log.debug('Detected your post as : %s' % contenttype)

        response = self.test_app.post(url, params=content, content_type=contenttype)
        return TEST_REPORT % (url, contenttype, response.status_code)
开发者ID:revcozmo,项目名称:err,代码行数:32,代码来源:webserver.py


示例19: google

def google(message, keywords):
    """
    google で検索した結果を返す

    https://github.com/llimllib/limbo/blob/master/limbo/plugins/google.py
    """

    if keywords == 'help':
        return

    query = quote(keywords)
    url = "https://encrypted.google.com/search?q={0}".format(query)
    soup = BeautifulSoup(requests.get(url).text, "html.parser")

    answer = soup.findAll("h3", attrs={"class": "r"})
    if not answer:
        botsend(message, "`{}` での検索結果はありませんでした".format(keywords))

    try:
        _, url = answer[0].a['href'].split('=', 1)
        url, _ = url.split('&', 1)
        botsend(message, unquote(url))
    except IndexError:
        # in this case there is a first answer without a link, which is a
        # google response! Let's grab it and display it to the user.
        return ' '.join(answer[0].stripped_strings)
开发者ID:pyconjp,项目名称:pyconjpbot,代码行数:26,代码来源:google.py


示例20: uri_metadata

def uri_metadata(uri):
    '''Discover media-file metadata using GStreamer.'''
    discoverer = GstPbutils.Discoverer()

    uri = uri.split("://")
    info = discoverer.discover_uri(uri[0] + "://" + quote(unquote(uri[1])))

    return info
开发者ID:tornel,项目名称:linux-show-player,代码行数:8,代码来源:audio_utils.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python request.url2pathname函数代码示例发布时间:2022-05-27
下一篇:
Python request.read函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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