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


Python urllib2.quote方法代码示例

本文整理汇总了Python中urllib2.quote方法的典型用法代码示例。如果您正苦于以下问题:Python urllib2.quote方法的具体用法?Python urllib2.quote怎么用?Python urllib2.quote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib2的用法示例。


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

示例1: _get_proxy_info

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def _get_proxy_info(context):
    if not context.get('proxy_hostname') or not context.get('proxy_port'):
        return None

    user_pass = ''
    if context.get('proxy_username') and context.get('proxy_password'):
        username = quote(context['proxy_username'], safe='')
        password = quote(context['proxy_password'], safe='')
        user_pass = '{user}:{password}@'.format(
            user=username, password=password)

    proxy = 'http://{user_pass}{host}:{port}'.format(
        user_pass=user_pass, host=context['proxy_hostname'],
        port=context['proxy_port'])
    proxies = {
        'http': proxy,
        'https': proxy,
    }
    return proxies 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:splunk_rest_client.py

示例2: get_distance

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def get_distance(self, userID):
        """ Fetches the distance from another user
            :param userID User ID of target user.
        """

        # Create and send HTTP Get to Happn server
        h=headers
        h.update({
            'Authorization' : 'OAuth="' + self.oauth+'"',
            'Content-Type'  : 'application/json',
        })
        #@TODO Trim query to just distance request
        query='{"fields":"spotify_tracks,modification_date,my_relations,social_synchronization.fields(facebook.fields(id),instagram.fields(pictures.fields(id),username)),school,age,clickable_profile_link,is_invited,type,gender,is_charmed,picture.fields(id,url,is_default).height(92).mode(0).width(92),last_meet_position,profiles.fields(id,url,is_default).height(1136).mode(1).width(640),has_charmed_me,job,first_name,last_invite_received,distance,availability,about,id,workplace,is_accepted"}'
        url = 'https://api.happn.fr/api/users/' + str(userID) + '?' + urllib2.quote(query)

        try:
            r = requests.get(url, headers=h)
        except Exception as e:
            raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))

        if r.status_code == 200: #200 = 'OK'
            self.distance = r.json()['data']['distance']
            logging.info('Sybil %d m from target',self.distance)
        else:
            raise HTTP_MethodError(httpErrors[r.status_code]) 
开发者ID:rickhousley,项目名称:happn,代码行数:27,代码来源:happn.py

示例3: downloadSingleType

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def downloadSingleType(bigCate,smallCate,baseDir):
    """
    下载某一分类的词库,实际作用是修改全局变量让多线程可以获取到正确的下载路径和存储目录
    :param bigCate:   一级分类
    :param smallCate: 二级分类
    :param baseDir:   下载目录
    :return: None
    """
    global smallCateURL, downloadDir, queue, logFile
    smallCateURL = 'http://dict.qq.pinyin.cn/dict_list?sort1=%s&sort2=%s' %(urllib2.quote(bigCate), urllib2.quote(smallCate))  # url编码
    if baseDir[-1] == '/':
        print '路径 '+baseDir+' 末尾不能有/'
        return
    downloadDir = baseDir+'/'+bigCate+'/'+smallCate
    logFile = baseDir+'/download.log'
    if not os.path.exists(downloadDir.decode('utf8')):  # 目录不存在的时候创建目录
        os.makedirs(downloadDir.decode('utf8'))
    queue.put(smallCateURL) 
开发者ID:WuLC,项目名称:ThesaurusSpider,代码行数:20,代码来源:multiThreadDownload.py

示例4: sync_song

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def sync_song(self):
        for song_detail in self.source_playlist:
            song = song_detail[0]
            singer = song_detail[1]
            search_word = u"{} {}".format(song, singer)
            url_sw = quote(search_word.encode('utf8'))
            self.browser.get(qq_search_url.format(url_sw))
            self.wait.until(lambda browser: browser.find_element_by_class_name("songlist__list"))
            sleep(0.5)

            @retry(retry_times=3)
            def _add(browser):
                browser.execute_script("document.getElementsByClassName('songlist__list')[0].firstElementChild.getElementsByClassName('list_menu__add')[0].click()")
                sleep(0.5)
                browser.find_element_by_css_selector("a[data-dirid='{}']".format(self.target_playlist_tag)).click()
                _print(u"song:{} success".format(song))

            try:
                _add(self.browser)
            except RetryException:
                _print(u"song:{}, sync error".format(song))
                self.failed_list.append(search_word)
            else:
                self.success_list.append(search_word) 
开发者ID:Denon,项目名称:syncPlaylist,代码行数:26,代码来源:WYtoQQ.py

示例5: getcloudvideourl

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def getcloudvideourl(bturl, title):
    '''
    resolve video url
    '''
    dlpre = '{0}/req_get_method_vod'.format(cloudurlpre)
    # dl = '{0}/vod_dl_all?userid={1}&gcid={2}&filename={3}&t={4}'.format(
    #    cloudurlpre, xl.userid, gcid,
    #    urllib2.quote(title), cachetime)
    dl = '{0}?url={1}&platform=0&userid={2}&sessionid={3}&cache={4}'.format(
        dlpre, urllib.quote(bturl), xl.userid, xl.sid, cachetime)
    rsp = xl.urlopen(dl)

    vturls = json.loads(rsp)
    typ = {'356608': '1080P', '282880': '720P', '225536': '标清'}

    vtyps = [(typ[str(i['spec_id'])], i['vod_url_dt17'])
             for i in vturls['resp']['vodinfo_list']
             if str(i['spec_id']) in typ]
    # vtyps = [(typ[k], v['url'])
    #         for (k, v) in vturls.iteritems() if 'url' in v]
    # vtyps.insert(0, ('源码', surl))
    # selitem = dialog.select('清晰度', [v[0] for v in vtyps])
    # if selitem is -1: return
    # vtyp = vtyps[selitem]
    return vtyps 
开发者ID:tacy,项目名称:plugin.video.xunleicloud,代码行数:27,代码来源:addon.py

示例6: track_download_request

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def track_download_request(download_url, download_title):
    """Track a download in Piwik"""
    from indico_piwik.plugin import PiwikPlugin

    if not download_url:
        raise ValueError("download_url can't be empty")
    if not download_title:
        raise ValueError("download_title can't be empty")

    request = PiwikRequest(server_url=PiwikPlugin.settings.get('server_api_url'),
                           site_id=PiwikPlugin.settings.get('site_id_events'),
                           api_token=PiwikPlugin.settings.get('server_token'),
                           query_script=PiwikPlugin.track_script)

    action_url = quote(download_url)
    dt = datetime.now()
    request.call(idsite=request.site_id,
                 rec=1,
                 action_name=quote(download_title.encode('utf-8')),
                 url=action_url,
                 download=action_url,
                 h=dt.hour, m=dt.minute, s=dt.second) 
开发者ID:indico,项目名称:indico-plugins,代码行数:24,代码来源:tracking.py

示例7: search_track

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def search_track(keyword):
    '''
    return matched qq music songs
    '''
    keyword = urllib2.quote(keyword.encode("utf8"))
    url = 'http://i.y.qq.com/s.music/fcgi-bin/search_for_qq_cp?' + \
        'g_tk=938407465&uin=0&format=jsonp&inCharset=utf-8' + \
        '&outCharset=utf-8&notice=0&platform=h5&needNewCode=1' + \
        '&w=%s&zhidaqu=1&catZhida=1' + \
        '&t=0&flag=1&ie=utf-8&sem=1&aggr=0&perpage=20&n=20&p=1' + \
        '&remoteplace=txt.mqq.all&_=1459991037831&jsonpCallback=jsonp4'
    response = _qq_h(url % keyword)
    data = json.loads(response[len('jsonp4('):-len(')')])

    result = []
    for song in data["data"]["song"]["list"]:
        result.append(_convert_song(song))
    return result 
开发者ID:listen1,项目名称:listen1,代码行数:20,代码来源:qq.py

示例8: emit

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def emit(self, record):
        try:
            msg = record.getMessage()
            log_data = "PLAINTEXT=" + urllib2.quote(simplejson.dumps(
                {
                    'msg':msg,
                    'localip':self.localip,
                    'publicip':self.publicip,
                    'tenant':'TODO :)'
                }
            ))
            urllib2.urlopen(self.base_url, log_data)
        except(KeyboardInterrupt, SystemExit):
            raise
        except:
            self.handleError(record) 
开发者ID:gosquadron,项目名称:squadron,代码行数:18,代码来源:LogglyHandler.py

示例9: find

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def find(self, query):
        """return the first 100 compounds that match the query"""
        this = "Search.asmx/SimpleSearch?query=%s&token=%s" % (quote(query), self._token)
        res = self.http_get(this, frmt="xml")
        res = self.easyXML(res)
        Ids = [int(x.text) for x in res.findAll("int")]
        return Ids 
开发者ID:cokelaer,项目名称:bioservices,代码行数:9,代码来源:chemspider.py

示例10: get_json_result

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def get_json_result(self, query_items, arguments=None):
        path = '/json/' + '/'.join(urllib2.quote(item)
                                   for item in query_items)
        if arguments is not None:
            path += '?' + urllib2.urlencode(arguments)

        url = self.master_url + path
        try:
            request = urllib2.urlopen(url)
        except urllib2.HTTPError, err:
            # Turn 404 into a result missing error.
            if err.code == 404:
                raise ResultMissing

            # Log this failure.
            os = StringIO.StringIO()
            print >>os, "*** ERROR: failure in 'get_json_result(%r, %r)' ***" %(
                query_items, arguments)
            print >>os, "URL: %r" % url
            print >>os, "\n-- Traceback --"
            traceback.print_exc(file = os)
            if self.logger:
                self.logger.warning(os.getvalue())
            else:
                print >>sys.stderr, os.getvalue()
            raise UnknownFailure 
开发者ID:llvm,项目名称:llvm-zorg,代码行数:28,代码来源:statusclient.py

示例11: get_conversations

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def get_conversations(self, offset=0,limit=64):
        """ Get conversations with userID from Happn server
            :param userID User ID of target user.
            :param offset Offset of conversations to recieve
            :param limit Number of conversations to recieve
        """

        # Create and send HTTP Get to Happn server
        h={ #For some reason header update doesnt work
            'http.useragent' : 'Happn/1.0 AndroidSDK/0',
            'Authorization'  : 'OAuth="' + self.oauth+'"',
            'Content-Type'   : 'application/json',
            'User-Agent'     : 'Happn/19.1.0 AndroidSDK/19',
            'Host'           : 'api.happn.fr',
            'Connection'     : 'Keep-Alive',
            'Accept-Encoding': 'gzip, deflate'
        }
        query ='fields=creation%5Fdate%2Cparticipants%2Efields%28user%2Efields%28picture%2Efields%28id%2Curl%2Cis%5Fdefault%29%2Eheight%28120%29%2Emode%280%29%2Ewidth%28120%29%2Cage%2Cclickable%5Fmessage%5Flink%2Cid%2Cfirst%5Fname%2Cis%5Fmoderator%29%29%2Cmodification%5Fdate%2Cid%2Cmessages%2Efields%28sender%2Efields%28id%2Cfirst%5Fname%29%2Ccreation%5Fdate%2Cmessage%2Cid%29%2Eoffset%280%29%2Elimit%283%29%2Cis%5Fread&offset=' + str(offset) + '&limit=' + str(limit)
        #'{"fields":"creation_date,participants.fields(user.fields(picture.fields(id,url,is_default).height(120).mode(0).width(120),age,clickable_message_link,id,first_name,is_moderator)),modification_date,id,messages.fields(sender.fields(id,first_name),creation_date,message,id).offset(0).limit(3),is_read", "offset": '+str(offset)+'}'

        url = 'https://api.happn.fr/api/users/' + str(self.id) + '/conversations?' + urllib2.quote(query)

        logging.debug("Using url = {}".format(url))
        logging.debug("SenderID: {}".format(self.id))

        try:
            r = requests.get(url, headers=h)
        except Exception as e:
            raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))

        if r.status_code == 200: #200 = 'OK'
            logging.debug("Return code: {}".format(r.status_code))
            return json.loads(json.dumps(r.json()['data'], sort_keys=True, indent=4, separators=(',', ': ')))
        else:
            logging.warn("Error: {}".format(r.status_code))
            raise HTTP_MethodError(httpErrors[r.status_code]) 
开发者ID:rickhousley,项目名称:happn,代码行数:38,代码来源:happn.py

示例12: get_messages

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def get_messages(self, conversationID, offset=0,limit=64):
        """ Get conversations with userID from Happn server
            :param conversationID ID of conversation between user1 and user2.
            :param offset Offset of messages to recieve
            :param limit Number of messages to recieve
        """

        # Create and send HTTP Get to Happn server
        h={ #For some reason header update doesnt work
            'http.useragent' : 'Happn/1.0 AndroidSDK/0',
            'Authorization'  : 'OAuth="' + self.oauth+'"',
            'Content-Type'   : 'application/json',
            'User-Agent'     : 'Happn/19.1.0 AndroidSDK/19',
            'Host'           : 'api.happn.fr',
            'Connection'     : 'Keep-Alive',
            'Accept-Encoding': 'gzip, deflate'
        }
        query = '{fields":"sender.fields(picture.fields(id,url,is_default).height(70).mode(0).width(70),clickable_message_link,id,first_name,is_moderator),creation_date,message,id"}'

        #fields=sender%2Efields%28picture%2Efields%28id%2Curl%2Cis%5Fdefault%29%2Eheight%2870%29%2Emode%280%29%2Ewidth%2870%29%2Cclickable%5Fmessage%5Flink%2Cid%2Cfirst%5Fname%2Cis%5Fmoderator%29%2Ccreation%5Fdate%2Cmessage%2Cid&offset=0&limit=27

        url = 'https://api.happn.fr/api/conversations/' + str(conversationID) + '/messages?' + urllib2.quote(query) + "%offset="+str(offset)+"&limit="+str(limit)
        #
        logging.debug("Using url = {}".format(url))
        logging.debug("convoID: {}".format(conversationID))

        try:
            r = requests.get(url, headers=h)
        except Exception as e:
            raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))

        if r.status_code == 200: #200 = 'OK'
            logging.debug("Return code: {}".format(r.status_code))
            return json.loads(json.dumps(r.json()['data'], sort_keys=True, indent=4, separators=(',', ': ')))
        else:
            logging.warn("Error: {}".format(r.status_code))
            raise HTTP_MethodError(httpErrors[r.status_code]) 
开发者ID:rickhousley,项目名称:happn,代码行数:39,代码来源:happn.py

示例13: get_recommendations

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def get_recommendations(self, limit=16, offset=0):
        """ Get recs from Happn server
            :param limit Number of reccomendations to recieve
            :param offset Offset index for reccomendation list
        """
        
        # Create and send HTTP Get to Happn server
        h={ #For some reason header update doesnt work
            'http.useragent' : 'Happn/1.0 AndroidSDK/0',
            'Authorization'  : 'OAuth="' + self.oauth+'"',
            'Content-Type'   : 'application/json',
            'User-Agent'     : 'Happn/19.1.0 AndroidSDK/19',
            'Host'           : 'api.happn.fr',
            'Connection'     : 'Keep-Alive',
            'Accept-Encoding': 'gzip'
        }
        query = '{"types":"468","limit":'+str(limit)+',"offset":'+str(offset)+',"fields":"id,modification_date,notification_type,nb_times,notifier.fields(id,job,is_accepted,workplace,my_relation,distance,gender,my_conversation,is_charmed,nb_photos,first_name,age,profiles.mode(1).width(360).height(640).fields(width,height,mode,url))"}'
        url = 'https://api.happn.fr/api/users/' + self.id +'/notifications/?query=' + urllib2.quote(query)

        try:
            r = requests.get(url, headers=h)
        except Exception as e:
            raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))
            
        if r.status_code == 200: #200 = 'OK'
            return json.loads(json.dumps(r.json()['data'], sort_keys=True, indent=4, separators=(',', ': ')))
        else:
            raise HTTP_MethodError(httpErrors[r.status_code]) 
开发者ID:rickhousley,项目名称:happn,代码行数:30,代码来源:happn.py

示例14: get_declined

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def get_declined(self, limit=128, offset=0):
        """ Get declined people from Happn server
            :param limit Number of people to recieve
            :param offset Offset index for reccomendation list
        """
        
        # Create and send HTTP Get to Happn server
        h={ #For some reason header update doesnt work
            'http.useragent' : 'Happn/1.0 AndroidSDK/0',
            'Authorization'  : 'OAuth="' + self.oauth+'"',
            'Content-Type'   : 'application/json',
            'User-Agent'     : 'Happn/19.1.0 AndroidSDK/19',
            'Host'           : 'api.happn.fr',
            'Connection'     : 'Keep-Alive',
            'Accept-Encoding': 'gzip'
        }
        query = '{"types":"468","limit":'+str(limit)+',"offset":'+str(offset)+',"fields":"is_charmed,modification_date,age,id,my_relation,distance,first_name"}'
        url = 'https://api.happn.fr/api/users/me/rejected?' + urllib2.quote(query)

        try:
            r = requests.get(url, headers=h)
        except Exception as e:
            raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))
            
        if r.status_code == 200: #200 = 'OK'
            return json.loads(json.dumps(r.json()['data'], sort_keys=True, indent=4, separators=(',', ': ')))
        else:
            raise HTTP_MethodError(httpErrors[r.status_code]) 
开发者ID:rickhousley,项目名称:happn,代码行数:30,代码来源:happn.py

示例15: _pam_auth

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import quote [as 别名]
def _pam_auth(self, query, apicode=0, callback=None, error=None):

        if 'timestamp' not in query:
            query['timestamp'] = int(time.time())

        ## Global Grant?
        if 'auth' in query and not query['auth']:
            del query['auth']

        if 'channel' in query and not query['channel']:
            del query['channel']

        if 'channel-group' in query and not query['channel-group']:
            del query['channel-group']


        params = "&".join([
            x + "=" + quote(
                str(query[x]), safe=""
            ) for x in sorted(query)
        ])
        sign_input = "{subkey}\n{pubkey}\n{apitype}\n{params}".format(
            subkey=self.subscribe_key,
            pubkey=self.publish_key,
            apitype="audit" if (apicode) else "grant",
            params=params
        )
        query['signature'] = self._pam_sign(sign_input)

        return self._request({"urlcomponents": [
            'v1', 'auth', "audit" if (apicode) else "grant",
            'sub-key',
            self.subscribe_key
        ], 'urlparams': query},
            self._return_wrapped_callback(callback),
            self._return_wrapped_callback(error)) 
开发者ID:fangpenlin,项目名称:bugbuzz-python,代码行数:38,代码来源:__init__.py


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