本文整理汇总了Python中urllib.quote_plus函数的典型用法代码示例。如果您正苦于以下问题:Python quote_plus函数的具体用法?Python quote_plus怎么用?Python quote_plus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quote_plus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encode_multipart_formdata
def encode_multipart_formdata(fields, files):
"""
refer from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/572202
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return (content_type, body) ready for httplib.HTTP instance
"""
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(urllib.quote_plus(str(value)))
for (key, filename, value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, urllib.quote_plus(filename)))
L.append('Content-Type: %s' % get_content_type(filename))
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
示例2: addDir
def addDir(name,url,mode,iconimage):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
示例3: prepare_url
def prepare_url(values):
vals = DEFAULT_VALUES.copy()
vals.update(values)
vals["query"] = quote_plus(vals["query"])
vals["query2"] = quote_plus(vals["query2"])
return (
"http://vls2.icm.edu.pl/cgi-bin/search.pl?SearchTemplate=search_form.advanced"
+ "&search_field=%(query)s"
+ "&fields=%(query-fields)s"
+ "&AdvBooleanJoiner=%(query-join)s"
+ "&search_field2=%(query2)s"
+ "&fields2=%(query2-fields)s"
+ "&Database=elsevier_1990"
+ "&Database=springer_1990"
+ "&Category=all_categories"
+ "&ArticleType=All+Types..."
+ "&Language="
+ "&daterange=yearrange"
+ "&fromyear=%(from)d"
+ "&toyear=%(to)d"
+ "&Max=%(num)d"
+ "&Start=%(start)d"
+ "&Order="
+ "&GetSearchResults=Submit+Query"
) % vals
示例4: addDir
def addDir(name, url, mode, iconimage, description, isFolder=True, channelName=None, background=None, isTvGuide=False, channelID=None, categoryID=None):
chName = channelName if channelName is not None else ""
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description} )
if mode==3 or mode==4 or mode==7 or mode==8 or mode==10 or mode==11 or mode==99:
isFolder=False
if mode==3 or mode==4 or mode==10 or mode==11:
liz.setProperty("IsPlayable","true")
items = []
if mode == 3:
items.append((localizedString(30205).encode('utf-8'), 'XBMC.Container.Update({0}?url={1}&mode=9&iconimage={2}&displayname={3}&categoryid={4})'.format(sys.argv[0], urllib.quote_plus(url), iconimage, channelName, categoryID)))
items.append((localizedString(30206).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&categoryid={2}&mode=17)'.format(sys.argv[0], channelID, categoryID)))
elif mode == 4:
items.append((localizedString(30205).encode('utf-8'), 'XBMC.Container.Update({0}?url={1}&mode=9&iconimage={2}&displayname={3}&categoryid={4})'.format(sys.argv[0], urllib.quote_plus(url), iconimage, channelName, categoryID)))
items.append((localizedString(30207).encode('utf-8'), "XBMC.RunPlugin({0}?url={1}&mode=18)".format(sys.argv[0], channelID)))
items.append((localizedString(30021).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=41&iconimage=-1)'.format(sys.argv[0], channelID)))
items.append((localizedString(30022).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=41&iconimage=1)'.format(sys.argv[0], channelID)))
items.append((localizedString(30023).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=41&iconimage=0)'.format(sys.argv[0], channelID)))
elif mode == 10:
if isTvGuide:
items.append((localizedString(30205).encode('utf-8'), 'XBMC.Container.Update({0}?url={1}&mode=5&iconimage={2}&name={3}&categoryid={4})'.format(sys.argv[0], urllib.quote_plus(url), iconimage, channelName, categoryID)))
items.append((localizedString(30206).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&categoryid={2}&mode=17)'.format(sys.argv[0], channelID, categoryID)))
elif mode == 11:
if isTvGuide:
items.append((localizedString(30205).encode('utf-8'), 'XBMC.Container.Update({0}?url={1}&mode=5&iconimage={2}&name={3}&categoryid={4})'.format(sys.argv[0], urllib.quote_plus(url), iconimage, channelName, categoryID)))
items.append((localizedString(30207).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=18)'.format(sys.argv[0], channelID)))
items.append((localizedString(30021).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=41&iconimage=-1)'.format(sys.argv[0], channelID)))
items.append((localizedString(30022).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=41&iconimage=1)'.format(sys.argv[0], channelID)))
items.append((localizedString(30023).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=41&iconimage=0)'.format(sys.argv[0], channelID)))
liz.addContextMenuItems(items = items)
elif mode == 2:
liz.addContextMenuItems(items =
[(localizedString(30210).encode('utf-8'), 'XBMC.Container.Update({0}?mode=37&categoryid={1})'.format(sys.argv[0], urllib.quote_plus(channelName))),
(localizedString(30212).encode('utf-8'), 'XBMC.Container.Update({0}?mode=38&categoryid={1})'.format(sys.argv[0], urllib.quote_plus(channelName))),
(localizedString(30021).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=42&iconimage=-1)'.format(sys.argv[0], channelID)),
(localizedString(30022).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=42&iconimage=1)'.format(sys.argv[0], channelID)),
(localizedString(30023).encode('utf-8'), 'XBMC.RunPlugin({0}?url={1}&mode=42&iconimage=0)'.format(sys.argv[0], channelID))
])
elif mode == 16:
liz.addContextMenuItems(items =
[(localizedString(30211).encode('utf-8'), 'XBMC.Container.Update({0}?mode=39)'.format(sys.argv[0])),
(localizedString(30213).encode('utf-8'), 'XBMC.Container.Update({0}?mode=40)'.format(sys.argv[0]))])
if background is not None:
liz.setProperty("Fanart_Image", background)
fullUrl = "{0}?url={1}&mode={2}&name={3}&iconimage={4}&description={5}".format(sys.argv[0], urllib.quote_plus(url), mode, urllib.quote_plus(name), urllib.quote_plus(iconimage), urllib.quote_plus(description))
if channelName is not None:
fullUrl = "{0}&displayname={1}".format(fullUrl, urllib.quote_plus(channelName))
if categoryID is not None:
fullUrl = "{0}&categoryid={1}".format(fullUrl, urllib.quote_plus(categoryID))
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=fullUrl, listitem=liz, isFolder=isFolder)
return ok
示例5: _edit
def _edit(self, folder=None, file=None):
# set some vars
files = None
success = None
# check for folder
if folder:
# check for the homepage file
if file:
# update the site
success = self._update(folder, file)
# get files in the folder
files = self._make_req('https://www.googleapis.com/drive/v2/files?q=' +
urllib.quote_plus('"%s" in parents and mimeType = "application/vnd.google-apps.document"' % folder))['items']
# get the root folders
folders = self._make_req('https://www.googleapis.com/drive/v2/files?q=' +
urllib.quote_plus('"root" in parents and mimeType = "application/vnd.google-apps.folder"'))['items']
# load the view
template = template_helper.load('admin', {
'folders': folders,
'files': files,
'success': success,
'self_url': self.request.uri
})
self.response.out.write(template)
示例6: instance_url
def instance_url(self):
self.id = util.utf8(self.id)
self.charge = util.utf8(self.transfer)
base = Transfer.class_url()
cust_extn = urllib.quote_plus(self.transfer)
extn = urllib.quote_plus(self.id)
return "%s/%s/reversals/%s" % (base, cust_extn, extn)
示例7: set_proxy
def set_proxy():
proxy = os.getenv('PROXY', '')
if proxy:
interface_ip_list = get_all_interface_ip()
predefine_no_proxy_list = ".xip.io,172.30.0.0/16,172.17.0.0/16,%s" % socket.gethostname()
proxy_user = quote_plus(os.getenv('PROXY_USER',''))
if proxy_user:
proxy_password = quote_plus(os.getenv('PROXY_PASSWORD',''))
http_proxy_url = "http://%s:%[email protected]%s" % (proxy_user, proxy_password, proxy)
https_proxy_url = "https://%s:%[email protected]%s" % (proxy_user, proxy_password, proxy)
else:
http_proxy_url = "http://%s" % proxy
https_proxy_url = "https://%s" % proxy
# openshift proxy setup
if system(('sed -i -e "/^#HTTP_PROXY=*/cHTTP_PROXY=%s"'
' -e "/^#HTTPS_PROXY=*/cHTTPS_PROXY=%s"'
' -e "/^#NO_PROXY=*/cNO_PROXY=%s%s"'
' %s') % (http_proxy_url, http_proxy_url, interface_ip_list,
predefine_no_proxy_list, OPENSHIFT_OPTION))[2]:
return ("Permisison denined: %s" % OPENSHIFT_OPTION)
# docker daemon proxy setup
if not os.path.isdir('/etc/systemd/system/docker.service.d'):
subprocess.call("mkdir /etc/systemd/system/docker.service.d", shell=True)
env_file_content = ('[Service]\n'
'Environment="HTTP_PROXY=%s" "NO_PROXY=localhost,127.0.0.1,::1,.xip.io"\n') \
% (http_proxy_url)
try:
with open('/etc/systemd/system/docker.service.d/http-proxy.conf', 'w') as fh:
fh.write(env_file_content)
subprocess.call('systemctl daemon-reload', shell=True)
return subprocess.call('systemctl restart docker', shell=True)
except IOError as err:
return err
示例8: build_rest_path
def build_rest_path(self, bucket=None, key=None, params=None, prefix=None) :
"""
Given a RiakClient, RiakBucket, Key, LinkSpec, and Params,
construct and return a URL.
"""
# Build 'http://hostname:port/prefix/bucket'
path = ''
path += '/' + (prefix or self._prefix)
# Add '.../bucket'
if bucket is not None:
path += '/' + urllib.quote_plus(bucket._name)
# Add '.../key'
if key is not None:
path += '/' + urllib.quote_plus(key)
# Add query parameters.
if params is not None:
s = ''
for key in params.keys():
if s != '': s += '&'
s += urllib.quote_plus(key) + '=' + urllib.quote_plus(str(params[key]))
path += '?' + s
# Return.
return self._host, self._port, path
示例9: query_lastfm
def query_lastfm(self, artist, title):
"""Use track.getinfo to get track metadata. If it fails, fall back on
track.search"""
encoded_artist = quote_plus(artist.encode('utf-8'))
encoded_title = quote_plus(title.encode('utf-8'))
track_info = self.getinfo(encoded_artist, encoded_title)
if not track_info:
track_info = self.tracksearch(encoded_artist, encoded_title)
if not track_info:
return None
fixed_artist = track_info['artist'][:256]
fixed_title = track_info['name'][:256]
mbid = track_info['mbid']
toptags = self.get_tags(mbid)
else:
fixed_artist = track_info['artist']['name'][:256]
fixed_title = track_info['name'][:256]
mbid = track_info['mbid']
toptags = track_info.get('toptags', [])
if not mbid:
if ';' in artist:
# Try slicing into multiple artists and retry using the first one listed
return self.query_lastfm(artist.split(';')[0], title)
# Cannot continue without an MBID.
return None
mbid, fixed_artist, fixed_title = self.query_musicbrainz(
mbid, fixed_artist, fixed_title)
tags = self.extract_tags(toptags)
return {'artist': fixed_artist, 'title': fixed_title, 'mbid': mbid,
'tags': tags}
示例10: addDirectoryItem
def addDirectoryItem(name, url, mode, label2='', infoType="Music", infoLabels = {}, isFolder=True):
liz=xbmcgui.ListItem(name, label2)
if not infoLabels:
infoLabels = {"Title": name }
liz.setInfo( infoType, infoLabels )
v = "?name=%s&url=%s" % (urllib.quote_plus(name.encode('utf-8')), urllib.quote_plus(url.encode('utf-8')), )
action1 = 'XBMC.RunPlugin(plugin://plugin.audio.listenliveeu/?add%s%s)' % (v, '\n')
action2 = 'XBMC.RunPlugin(plugin://plugin.audio.listenliveeu/?remfav%s%s)' % (v, '\n')
action3 = 'XBMC.RunPlugin(plugin://plugin.audio.listenliveeu/?removeall)'
if mode==2:
try:
liz.addContextMenuItems([(__language__(30004), action1), (__language__(30006), action3)])
except:
errorOK("addDirectoryItem()")
elif mode==3:
try:
liz.addContextMenuItems([(__language__(30005), action2), (__language__(30006), action3)])
except:
errorOK("addDirectoryItem()")
u = "%s?url=%s&mode=%s&name=%s" % (sys.argv[0], urllib.quote_plus(url), mode, urllib.quote_plus(name.encode('utf-8')), )
log("%s" % u)
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=isFolder)
示例11: __call__
def __call__(self, r):
# modify and return the request
parsed = urlparse.urlparse(r.url)
url = parsed.geturl().split('?',1)[0]
url_params= urlparse.parse_qs(parsed.query)
#normalize the list value
for param in url_params:
url_params[param] = url_params[param][0]
url_params['apikey'] = self.apikey
keys = sorted(url_params.keys())
sig_params = []
for k in keys:
sig_params.append(k + '=' + urllib.quote_plus(url_params[k]).replace("+", "%20"))
query = '&'.join(sig_params)
signature = base64.b64encode(hmac.new(
self.secretkey,
msg=query.lower(),
digestmod=hashlib.sha1
).digest())
query += '&signature=' + urllib.quote_plus(signature)
r.url = url + '?' + query
return r
示例12: addDir
def addDir(title, url, mode):
sys_url = sys.argv[0] + '?title=' + urllib.quote_plus(title) + '&url=' + urllib.quote_plus(url) + '&mode=' + urllib.quote_plus(str(mode))
item = xbmcgui.ListItem(title, iconImage='DefaultFolder.png', thumbnailImage='')
item.setInfo( type='Video', infoLabels={'Title': title} )
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=sys_url, listitem=item, isFolder=True)
示例13: connect
def connect():
"""
Test the given login/password agains't the database
If it's ok, save them encrypted in the session
and return the state of the connection
"""
try:
values = {
'engine': request.form['server-engine'],
'username': urllib.quote_plus(request.form['username']),
'password': urllib.quote_plus(request.form['password']) if 'password' in request.form else '',
'host': urllib.quote_plus(request.form['server-hostname']),
'port': int(request.form['server-port'])
}
cnx = create_engine('%s://%s:%[email protected]%s:%d' % (
values['engine'],
values['username'],
values['password'],
values['host'],
values['port'],
))
cnx.connect()
token = uuid.uuid4().hex
g.session = session_store.create(request, token, values)
return jsonify({
'token': token,
'expire': mktime(g.session.expire.timetuple())
})
except OperationalError as e:
response = jsonify ({'code': e.orig[0], 'message': e.orig[1]})
response.status_code = 400
return response
示例14: __init__
def __init__(self, q, start=1, count=100, wait=10, asynchronous=False, cached=True,
sort=SORT_RELEVANCE, match=MATCH_ANY):
try: q = q.encode("utf-8")
except:
pass
if cached:
cache = "flickr"
else:
cache = None
url = "http://api.flickr.com/services/rest/?method="
if q == "recent":
url += "flickr.photos.getRecent"
else:
url += "flickr.photos.search"
if isinstance(q, (list, tuple)):
q = [quote_plus(q) for q in q]
q = ",".join(q)
url += "&tags=" + quote_plus(q)
url += "&tag_mode=" + match
else:
url += "&text=" + quote_plus(q)
url += "&page=" + str(start)
url += "&per_page=" + str(count)
url += "&sort=" + disambiguate_sort(sort)
url += "&api_key=" + API_KEY
URLAccumulator.__init__(self, url, wait, asynchronous, cache, ".xml", 1)
示例15: add
def add(self, service, name, category, title, iconimage, url, desc, page, folder=True, isPlayable=True):
u = (
sys.argv[0]
+ "?service="
+ service
+ "&name="
+ name
+ "&category="
+ category
+ "&title="
+ title
+ "&url="
+ urllib.quote_plus(url)
+ "&icon="
+ urllib.quote_plus(iconimage)
+ "&page="
+ urllib.quote_plus(page)
)
# log.info(str(u))
if name == "main-menu" or name == "categories-menu":
title = category
if iconimage == "":
iconimage = "DefaultVideo.png"
liz = xbmcgui.ListItem(title, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setProperty("fanart_image", iconimage)
if isPlayable:
liz.setProperty("IsPlayable", "true")
liz.setInfo(
type="Video", infoLabels={"Title": title, "Plot": desc, "Episode": "AAA", "Year": "2000", "Genre": "bbb"}
)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=folder)