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

Python request.quote函数代码示例

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

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



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

示例1: download

def download(file_type):
    '''下载接口'''

    if file_type not in ['form','scheme']:abort(404)
    id = request.form.get('id')
    type = request.form.get('type')
    data = query_data(type,id)
    #下载策划
    if file_type == 'scheme':
        if data.filename == 'Nothing':abort(404)
        content = send_file(path.join(Upload_path,data.rand_filename))
        filename = quote(data.filename)
    #if data.applicant!=current_user.name :abort(404)
    else :
        #生成context并进行渲染
        context=make_context(data,type)
        for key,value in context.items() :
            context[key] = RichText(value)     
        doc = DocxTemplate(path.join(Docx_path,type+'.docx'))
        doc.render(context)
        temp_file = path.join(Upload_path,str(current_user.id) +'result.docx')
        doc.save(temp_file)
        #读取渲染后的文件并将之删除
        with open(temp_file,'rb') as f:
            content = f.read()
        if path.exists(temp_file):
            remove(temp_file)
        filename = quote(data.association+'-'+types[type][1]+'.docx')     
 
    response = make_response(content)
    response.headers['Content-Disposition'] = \
    "attachment;filename*=UTF-8''" + filename
    response.headers['Content-Type'] = 'application/octet-stream'
    return response
开发者ID:SicunStudio,项目名称:aunet-flask,代码行数:34,代码来源:views.py


示例2: quote

def quote(stuff_to_quote):
  if PY3:
    from urllib.request import quote
    return quote(stuff_to_quote)
  else:
    from urllib2 import quote
    return quote(stuff_to_quote)
开发者ID:Kaushik512,项目名称:h2o-3,代码行数:7,代码来源:shared_utils.py


示例3: get_lyrics

def get_lyrics(artist, title, recurse_count=0):
    addr = BASE_URL + 'title=%s:%s&action=edit' % (quote(artist), quote(title))

    logger.info("Downloading lyrics from %r", addr)
    content = urlopen(addr).read().decode('utf-8')

    if RE_REDIRECT.search(content):
        if recurse_count >= 10:
            # OK, we looped a bit too much, just suppose we couldn't find any
            # lyrics
            logger.info("Too many redirects to find lyrics for %r: %r",
                        artist, title)
            return None

        new_artist, new_title = RE_REDIRECT.search(content).groups()
        logger.debug("Lyrics for '%s: %s' redirects to '%s: %s'",
                     artist, title, new_artist, new_title)
        return get_lyrics(new_artist, new_title, recurse_count + 1)

    lyrics = content.split("<lyrics>")[1].split("</lyrics>")[0].strip()

    if lyrics != "" and lyrics != EMPTY_LYRICS:
        return lyrics
    else:
        return None
开发者ID:Brijen,项目名称:sonata,代码行数:25,代码来源:lyricwiki.py


示例4: get

 def get(self,method,args=None):
     """ GET to DeepDetect server """
     u = self.__ddurl
     u += method
     headers = {}
     if args is not None:
         sep = "?"
         for arg,argv in args.iteritems():
             u += sep
             sep = "&"
             u += urllib2.quote(arg)
             u += '='
             if argv is not None:
                 u += urllib2.quote(argv)
                 
     LOG("GET %s"%u)
     response = None
     try:
         req = urllib2.Request(u)
         response = urllib2.urlopen(req, timeout=DD_TIMEOUT)
         jsonresponse=response.read()
     except:
         raise DDCommunicationError(u,"GET",headers,None,response)
     LOG(jsonresponse)
     try:
         return self.__return_format(jsonresponse)
     except:
         raise DDDataError(u,"GET",headers,None,jsonresponse)
开发者ID:AI42,项目名称:deepdetect,代码行数:28,代码来源:dd_client.py


示例5: data_detail

def data_detail(request, project, name):
    url = "http://localhost:8080/dmcapi-rest/" + "user/" + quote(request.session['user'], '') + "/project/" + quote(
        project, '') + "/dataType/metaData/" + quote(name, '')

    h = httplib2.Http()
    h.add_credentials(request.session['user'], request.session['password'])
    resp, content = h.request(url, method='GET', headers={'accept': 'application/json'})
    string = content.decode('utf-8')
    json_data = json.loads(string)

    data_name = json_data['dataName']
    data_path = json_data['dataPath']
    data_type = json_data['dataType']
    attribute = json_data['attribute']

    attributeContaners = attribute['attributeContaners']

    data = {}

    for attr in attributeContaners:
        for k, v in attr.items():
            if k == 'physicalDTO':
                name = v['name']
                val = v['dataType']
                data[name] = val

    user_name = request.session['user']
    project_name = project

    return render(request, 'data/detail.html', {'name': data_name,
                                                'path': data_path,
                                                'type': data_type,
                                                'data': data,
                                                'user': user_name,
                                                'project_name': project_name})
开发者ID:rkvtsn,项目名称:dxelopesgui,代码行数:35,代码来源:views.py


示例6: 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


示例7: tasks

def tasks(request, project):
    user = request.session['user']
    password = request.session['password']

    # url for get data sets
    url_data = MAIN_URL + "user/" + quote(user, '') + "/project/" + quote(project, '') + "/dataType/metaData"

    # url for get saved tasks
    url_task = MAIN_URL + "user/" + quote(user, '') + "/project/" + quote(project, '') + "/miningTask"

    # get data sets
    resp_data, content_data = get_message(user, password, url_data, "GET", {'accept': 'application/json'})
    json_data = decode_json(content_data)
    list_physical_data_set = json_data

    # get saved tasks
    resp_task, content_task = get_message(user, password, url_task, "GET", {'accept': 'application/json'})
    saved_data = decode_json(content_task)

    # get environment list
    # environment_list = []#["environment 1", "environment 2", "environment 3"]

    # get mining function list
    mining_function_list = []  # ["mining function 1", "mining function 2", "mining function 3"]

    # result inf
    result_data = {'listPhysicalDataSet': list_physical_data_set, 'saved_data': saved_data,
                   'user': user, 'project_name': project, 'environment_list': [],
                   'mining_function_list': mining_function_list}

    return render(request, 'tasks/tasks.html', result_data)
开发者ID:rkvtsn,项目名称:dxelopesgui,代码行数:31,代码来源:views.py


示例8: find

def find(unsortedMoviesFolder, sortedMoviesFolder):
    for movie in os.listdir(unsortedMoviesFolder):
        year = None
        movieName = movie
        for y in range(1500, 2100):
            if (str(y) in movie):
                year = str(y)
                movie = movie.replace(str(y), " ")
        for z in values:
            if (str(z) in movie):
                movie = movie.replace(str(z), " ")
            if ("  " in movie):
                movie = movie.replace("  ", " ")
        if (year == None):
            url = 'http://www.omdbapi.com/?t=' + quote(str(movie))
        else:
            url = 'http://www.omdbapi.com/?t=' + quote(str(movie)) + '&y=' + year
        response = urlopen(url).read()
        response = response.decode('utf-8')
        jsonvalues = json.loads(response)
        if jsonvalues["Response"] == "True":
            imdbrating = jsonvalues['imdbRating']
            destinationDirLocation = sortedMoviesFolder + '\\' + imdbrating + '_' + movieName
            srcFileLocation = unsortedMoviesFolder + '\\' + movieName
            if not os.path.exists(destinationDirLocation):
                os.makedirs(destinationDirLocation)
            shutil.move(srcFileLocation, destinationDirLocation)
开发者ID:vaibhavguptabits,项目名称:ImdbMovieSortingScript,代码行数:27,代码来源:ImdbMovieSortingUtility.py


示例9: login_redirect

def login_redirect():
  args = {
          'client_id':app.config['GOOGLE_CLIENT_ID'],
          'redirect_url':quote(app.config['GOOGLE_CALLBACK_URL']),
          'scope':quote('profile email') # we really only care if the user exists and has accepted our app
  }
  redirect_url = 'https://accounts.google.com/o/oauth2/auth?scope={scope}&redirect_uri={redirect_url}&client_id={client_id}&response_type=code'.format(**args)
  return redirect(redirect_url)
开发者ID:bobtwinkles,项目名称:hours_tracker,代码行数:8,代码来源:__init__.py


示例10: getweatherinfo

    def getweatherinfo(self, latitude, longitude):
        url = "http://api.openweathermap.org/data/2.5/forecast/daily?lat=%s&lon=%s&units=metric&cnt=2" % (
            quote(str(latitude)), quote(str(longitude))
        )
        data = urlopen(url).read().decode('utf-8')
        dataopenweathermap = json.loads(data)

        return dataopenweathermap['list']
开发者ID:badele,项目名称:domolib,代码行数:8,代码来源:__init__.py


示例11: parsWikiEn

def parsWikiEn(wordObj):
    if "noParsed" in wordObj:
        return
    if "noEnglish" in wordObj:
        return
    for typ in typs:
        if typ in wordObj:
            return
    html = ""
    text = wordObj["text"]
    url = "/wiki/" + quote(text)
    urls = [url]
    urls.append("/wiki/" + quote(text.upper()))
    urls.append("/wiki/" + quote(text.lower()))
    urls.append("/wiki/" + quote(text[0].upper() + text[1:].lower()))
    urls.append("/w/index.php?search=" + quote(text))
    for url in urls:
        try:
            fullurl = "http://en.wiktionary.org" + url
            response = urlopen(fullurl)
            html = response.read()
            break
        except HTTPError as e:
            if str(e) != "HTTP Error 404: Not Found":
                logging.exception(e)
        except Exception as e:
            print(url, e)
            logging.exception(e)
    if html == "":
        wordObj["noParsed"] = 1
        logging.warning(' no downloaded "' + text + '" by urls: ' + str(urls))
        return
    start = html.find(b' id="English"')
    end = html.find(b"<hr />", start)
    if start == -1:
        wordObj["noEnglish"] = 1
    else:
        html = html[start:end]
        countTypes = 0
        nounPart = getTypPart(html, "Noun")
        if nounPart:
            parseNounPart(nounPart, wordObj)
            countTypes += 1
        verbPart = getTypPart(html, "Verb")
        if verbPart:
            parseVerbPart(verbPart, wordObj)
            countTypes += 1
        adjectivePart = getTypPart(html, "Adjective")
        if adjectivePart:
            parseAdjectivePart(adjectivePart, wordObj)
            countTypes += 1
        adverbPart = getTypPart(html, "Adverb")
        if adverbPart:
            parseAdverbPart(adverbPart, wordObj)
            countTypes += 1
        wordObj["countTypes"] = countTypes
开发者ID:rogallic,项目名称:learnen.ru,代码行数:56,代码来源:parsWikiEn.py


示例12: get_param_value

def get_param_value(param,value):
     if isinstance(value, dict):
        if('contains' in value):
           return  param +'=.*?'+ re.escape(urllib2.quote(value['contains'])).replace('\%','%')+'.*?'
        elif('equalto' in value):
            return param +'='+  re.escape(urllib2.quote(value['equalto'])).replace('\%','%')
        elif('matches' in value):
            return param +'='+  value['matches'].replace(' ','%20')
     else:
        return param +'='+ value.replace(' ','%20')
开发者ID:sheltonpaul89,项目名称:web-mocker3,代码行数:10,代码来源:pretend_helpers.py


示例13: search

def search(keyword,filename,isFist):
    #需要查询的url
    url = "http://www.lagou.com/jobs/positionAjax.json?"
    #添加关键词查询
    logger.info("添加城市查询条件,关键字为:"+ keyword)
    url = url + "&kd="+request.quote(keyword)
    #第一次查询,获取总记录数
    url = url + "&first=true&pn=1"
    logger.info("第一次查询的URL为:"+url)
    #查询到的总条数
    totalCount = 0
    #记录总页数
    totalPage = 0

    with request.urlopen(url) as resultF:
        if resultF.status == 200 and resultF.reason == 'OK':
            #获得所返回的记录
            data = resultF.read().decode('utf-8')
            #将data进行JSON格式化
            dataJson = json.loads(data)
            #获得总记录数
            totalCount = int(dataJson['content']['totalCount'])
            #获得总页数
            totalPage = int(dataJson['content']['totalPageCount'])
            logger.info("查询出的总记录数为:"+ str(totalCount))
            logger.info("查询出的总页数为:"+ str(totalPage))
            logger.info("查询出的每页总数为:"+ str(dataJson['content']['pageSize']))
        else:
            logger.error("第一次打开url出错,没有正常连接,返回代码为:"+str(resultF.status))
            #结束程序
            return
    #查询的当前日期
    dateStr = datetime.now().strftime('%Y%m%d')
    #根据总页数进行循环读取
    for i in range(totalPage):
        #转码操作
        if i == 0 :
            url = "http://www.lagou.com/jobs/positionAjax.json?" + "&kd="+request.quote(keyword)+"&first=true&pn=1"
        else:
            url = "http://www.lagou.com/jobs/positionAjax.json?" + "&kd="+request.quote(keyword)+"&first=false&pn="+str((i+1))
        logger.info("查询的URL为:"+url)
        #模拟谷歌浏览器发送请求
        req = request.Request(url)
        req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36")
        with request.urlopen(req) as result:
            if resultF.status == 200 and resultF.reason == 'OK':
                #获得所返回的记录
                data = str(result.read().decode('utf-8'))
                #增加日期区分,以及记录总条数,ex 20151210_981;内容
                #将data进行JSON格式化
                dataJson = json.loads(data, encoding='utf-8')
                saveDataForHbase(dataJson['content']['result'], filename, isFist)
        #访问每条链接,休眠1秒,防止被反爬虫
        time.sleep(1)
开发者ID:LinJiaYue,项目名称:BigDataSalaryAnaliySystem,代码行数:54,代码来源:LGCrawlerForLinux.py


示例14: stream_id

 def stream_id(self):
     if self.stream_type() == FeedlyStreamType.FEED:
         return quote('feed/{}'.format(self.stream_name()),
                      safe='')
     if self.stream_type() == FeedlyStreamType.TAG:
         return quote('user/{}/tag/{}'.format(self.user_id(),
                                              self.stream_name()),
                      safe='')
     else:  # FeedlyStreamType.CATEGORY
         return quote('user/{}/category/{}'.format(self.user_id(),
                                                   self.stream_name()),
                      safe='')
开发者ID:nio-blocks,项目名称:feedly,代码行数:12,代码来源:feedly_streams_block.py


示例15: data_delete

def data_delete(request, project, name):
    user = request.session['user']
    password = request.session['password']

    url = "http://localhost:8080/dmcapi-rest/" + "user/" + quote(user, '') + "/project/" + quote(
        project, '') + "/dataType/metaData/" + quote(name, '')

    resp, content = get_message(user, password, url, "DELETE", {'accept': 'application/json'})

    if resp.status == 200:
        return JsonResponse({"result": "success"})
    else:
        return JsonResponse({"result": "error", "error": resp.status})
开发者ID:rkvtsn,项目名称:dxelopesgui,代码行数:13,代码来源:views.py


示例16: env_delete

def env_delete(request, project):
    result = {'result': 'error'}
    user = request.session['user']
    password = request.session['password']

    id = request.POST['id']

    url = MAIN_URL + "user/%s/project/%s/env/%s" % (quote(user, ''), quote(project, ''), quote(id, ''))

    resp, content = make_request(url, 'DELETE', request)
    if resp.status == 200:
        result = {'result': 'success'}

    return JsonResponse(result)
开发者ID:rkvtsn,项目名称:dxelopesgui,代码行数:14,代码来源:views.py


示例17: delete_task

def delete_task(request, project, name):
    user = request.session['user']
    password = request.session['password']

    url = MAIN_URL + "user/" + quote(user, '') + "/project/" + quote(project, '') + "/miningTask/" + quote(name, '')

    resp, content = get_message(user, password, url, "DELETE", {'accept': 'application/json'})

    if resp.status == 200:
        result = {'result': 'success', 'error': resp.status}
    else:
        result = {'result': 'error', 'error': resp.status}

    return JsonResponse(result)
开发者ID:rkvtsn,项目名称:dxelopesgui,代码行数:14,代码来源:views.py


示例18: youtube_search

def youtube_search(query, limit):

    ret_url_list = list()

    for tries in range(1, 10):
        try:
            response = tools.retrieve_web_page('https://www.youtube.com/results?search_query=' +
                                               quote(query.encode('utf-8')),
                                               'youtube search result')

        except KeyboardInterrupt:
            raise

        except:
            e = sys.exc_info()[0]
            if tries > 3:
                print('Failed to download google search result. Reason: ' + str(e))
                raise

            print('Failed to download google search result, retrying. Reason: ' + str(e))
            sleep(1)

        else:
            if response:
                soup = BeautifulSoup(response, "html.parser")
                for item in soup.findAll(attrs={'class': 'yt-uix-tile-link'}):
                    url = 'https://www.youtube.com' + item['href']
                    ret_url_list.append(url.split('&')[0])
            break

    return ret_url_list[:limit]
开发者ID:ned-kelly,项目名称:Movie-Extra-Downloader,代码行数:31,代码来源:url_finders.py


示例19: issues_search_text

def issues_search_text(request):
    text = request.GET.get('search')
    if text is None or len(text) < 1:
        return HttpResponse('{ "msg" : "Search term must be at least 1 character long" }', 400)
    url = 'http://dev.hel.fi/openahjo/v1/issue/search/?text=%s&format=json&order_by=-latest_decision_date%s'\
          % (quote(text), get_paging_info(request))
    return JsonResponse(get_url_as_json(url))
开发者ID:viht0ri,项目名称:somekratia,代码行数:7,代码来源:views.py


示例20: send_sms

 def send_sms(self, obj_mobile, sms_content):
     try:
         send_url = "http://%s:%s%s?srcmobile=%s&password=%s&objmobile=%s&smsid=%s%s&smstext=%s" % \
                    (self.sms_host, self.sms_port, self.sms_send_uri, self.sms_user, self.sms_passwd,
                     obj_mobile, obj_mobile, int(time.time()*1000), request.quote(sms_content))
         response = request.urlopen(send_url, timeout=10)
         result = response.read()
         err_code = int(result)
         if not response is None:
             response.close()
         if err_code == 0:
             self._write_log("send sms to <%s> --> %s" % (obj_mobile, sms_content))
             return err_code
         else:
             self._write_log("send sms fail, error code: %s" % err_code)
             return err_code
     except error.HTTPError as e:
         self._write_log("request send sms url fail, HTTP status code: %s" % e.code)
         #raise error.HTTPError
     except error.URLError as e:
         self._write_log("request send sms url fail, Reason: %s" % e.reason)
         #raise error.URLError
     except:
         self._write_log("runtime error: send_sms")
         raise
开发者ID:flowsha,项目名称:cdma,代码行数:25,代码来源:cdma_sms.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python request.read函数代码示例发布时间:2022-05-27
下一篇:
Python request.pathname2url函数代码示例发布时间: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