All Samples(4566) | Call(3898) | Derive(0) | Import(668)
quote('abc def') -> 'abc%20def'
Each part of a URL, e.g. the path info, the query, etc., has a
different set of reserved characters that must be quoted.
RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists
the following reserved characters.
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
Each of these characters is reserved in some component of a URL,
but not necessarily in all of them.
By default, the quote function is intended for quoting the path
section of a URL. Thus, it will not encode '/'. This character
is reserved, but in typical usage the quote function is being
called on a path where the existing slash characters are used as
reserved characters.
def quote(s, safe='/'):
"""quote('abc def') -> 'abc%20def'
Each part of a URL, e.g. the path info, the query, etc., has a
different set of reserved characters that must be quoted.
RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists
the following reserved characters.
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
Each of these characters is reserved in some component of a URL,
but not necessarily in all of them.
By default, the quote function is intended for quoting the path
section of a URL. Thus, it will not encode '/'. This character
is reserved, but in typical usage the quote function is being
called on a path where the existing slash characters are used as
reserved characters.
"""
# fastpath
if not s:
return s
cachekey = (safe, always_safe)
try:
(quoter, safe) = _safe_quoters[cachekey]
except KeyError:
safe_map = _safe_map.copy()
safe_map.update([(c, c) for c in safe])
quoter = safe_map.__getitem__
safe = always_safe + safe
_safe_quoters[cachekey] = (quoter, safe)
if not s.rstrip(safe):
return s
return ''.join(map(quoter, s))
def escape(s):
"""Escape a URL including any /."""
return urllib.quote(s, safe='~')
def generate_timestamp():
"""Get seconds since epoch (UTC)."""
src/f/r/freebase-1.0.6/examples/freebase-images-appengine/freebase/uritemplate.py freebase(Download)
def _uri_encode_var(v):
return urllib.quote(v, safe="-_.~!$&'()*+,;=:/?[]#@")
class URITemplate(object):
"""a URITemplate is a URI with simple variable substitution.
"""
src/q/u/querychinesesto-HEAD/prog/gbk-encode-example.py querychinesesto(Download)
u'²âÊÔ'.encode('gbk')
#=========
from urllib import quote, quote_plus, unquote, urlencode
value = unicode('²âÊÔ','cp936')
quote(value.encode('utf-8'), '/')
src/g/o/google-app-engine-HEAD/lib/webob/docs/comment-example-code/example.py google-app-engine(Download)
def url_filename(self, url):
return os.path.join(self.storage_dir, urllib.quote(url, ''))
_end_body_re = re.compile(r'</body.*?>', re.I|re.S)
def add_to_end(self, html, extra_html):
"""
src/g/a/gaesdk-python-HEAD/lib/webob/docs/comment-example-code/example.py gaesdk-python(Download)
def url_filename(self, url):
return os.path.join(self.storage_dir, urllib.quote(url, ''))
_end_body_re = re.compile(r'</body.*?>', re.I|re.S)
def add_to_end(self, html, extra_html):
"""
src/g/o/google_appengine-HEAD/lib/webob/docs/comment-example-code/example.py google_appengine(Download)
def url_filename(self, url):
return os.path.join(self.storage_dir, urllib.quote(url, ''))
_end_body_re = re.compile(r'</body.*?>', re.I|re.S)
def add_to_end(self, html, extra_html):
"""
src/r/e/REST-Client-HEAD/sample/webapi/auth/oauth.py REST-Client(Download)
def _quote(self, query):
return urllib.quote(unicode(query).encode(self.encode), '')
src/b/r/braintree_python_examples-HEAD/tr_checkout_app_engine/web/webapi.py braintree_python_examples(Download)
kargs['secure'] = secure
# @@ should we limit cookies to a different path?
cookie = Cookie.SimpleCookie()
cookie[name] = urllib.quote(utf8(value))
for key, val in kargs.iteritems():
cookie[name][key] = val
header('Set-Cookie', cookie.items()[0][1].OutputString())
src/p/y/python-tumblr-HEAD/samples/pygooglechart.py python-tumblr(Download)
def set_title(self, title):
if title:
self.title = urllib.quote(title)
else:
self.title = None
def set_legend(self, legend):
"""legend needs to be a list, tuple or None"""
assert(isinstance(legend, list) or isinstance(legend, tuple) or
legend is None)
if legend:
self.legend = [urllib.quote(a) for a in legend]
def set_axis_labels(self, axis_type, values):
assert(axis_type in Axis.TYPES)
values = [ urllib.quote(a) for a in values ]
axis_index = len(self.axis)
axis = LabelAxis(axis_index, axis_type, values)
self.axis.append(axis)
return axis_index
def set_pie_labels(self, labels):
self.pie_labels = [urllib.quote(a) for a in labels]
def get_url_bits(self, data_class=None):
url_bits = Chart.get_url_bits(self, data_class=data_class)
if self.pie_labels:
url_bits.append('chl=%s' % '|'.join(self.pie_labels))
src/e/v/evserver-HEAD/evserver/examples/django_chat/views.py evserver(Download)
def document(request, key):
key = urllib.quote(key)
context = {
'key': key.replace('%',''),
}
return render_to_response('index.html', context)
def ajax_push(request, key):
key = urllib.quote(key)
payload = request.raw_post_data
if not isinstance(payload, unicode):
payload = payload.encode('utf-8')
payload = payload.replace('<', '<').replace('>','>')
def comet(request, key):
key = urllib.quote(key)
# setup the amqp subscriber
msgs = []
def callback(msg):
msgs.append(msg.body)
msg.channel.basic_ack(msg.delivery_tag)
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next