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


Python request.quote函数代码示例

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


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


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