本文整理汇总了Python中mod_python.util.parse_qsl函数的典型用法代码示例。如果您正苦于以下问题:Python parse_qsl函数的具体用法?Python parse_qsl怎么用?Python parse_qsl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_qsl函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, apreq):
self.apreq = apreq
if OSRF_HTTP_HEADER_XID in apreq.headers_in:
osrf.log.log_debug('read XID from client %s' % apreq.headers_in.get(OSRF_HTTP_HEADER_XID))
osrf.log.set_xid(apreq.headers_in.get(OSRF_HTTP_HEADER_XID))
self.local_xid = False
else:
osrf.log.make_xid()
osrf.log.log_debug('created new XID %s' % osrf.log.get_xid())
self.local_xid = True
if apreq.header_only:
return
for k,v in apreq.headers_in.iteritems():
osrf.log.log_internal('HEADER: %s = %s' % (k, v))
try:
#post = util.parse_qsl(apreq.read(int(apreq.headers_in['Content-length'])))
post = util.parse_qsl(apreq.read())
osrf.log.log_debug('post = ' + str(post))
self.body = [d for d in post if d[0] == 'osrf-msg'][0][1]
osrf.log.log_debug(self.body)
except Exception, e:
osrf.log.log_warn("error parsing osrf message: %s" % unicode(e))
self.body = None
return
示例2: track_page_view
def track_page_view(environ):
time_tup = time.localtime(time.time() + COOKIE_USER_PERSISTENCE)
environ['COOKIES'] = parse_cookie(environ.get('HTTP_COOKIE', ''))
environ['GET'] = {}
for key, value in parse_qsl(environ.get('QUERY_STRING', ''), True):
environ['GET'][key] = value
x_utmac = environ['GET'].get('x_utmac', None)
domain = environ.get('HTTP_HOST', '')
document_referer = environ['GET'].get("utmr", "")
if not document_referer or document_referer == "0":
document_referer = "-"
else:
document_referer = unquote(document_referer)
document_path = environ['GET'].get('utmp', "")
if document_path:
document_path = unquote(document_path)
account = environ['GET'].get('utmac', '')
user_agent = environ.get("HTTP_USER_AGENT", '')
cookie = environ['COOKIES'].get(COOKIE_NAME)
visitor_id = get_visitor_id(environ.get("HTTP_X_DCMGUID", ''), account, user_agent, cookie)
cookie = SimpleCookie()
cookie[COOKIE_NAME] = visitor_id
morsel = cookie[COOKIE_NAME]
morsel['expires'] = time.strftime('%a, %d-%b-%Y %H:%M:%S %Z', time_tup)
morsel['path'] = COOKIE_PATH
utm_gif_location = "http://www.google-analytics.com/__utm.gif"
for utmac in [account, x_utmac]:
if not utmac:
continue
utm_url = utm_gif_location + "?" + \
"utmwv=" + VERSION + \
"&utmn=" + get_random_number() + \
"&utmhn=" + quote(domain) + \
"&utmr=" + quote(document_referer) + \
"&utmp=" + quote(document_path) + \
"&utmac=" + utmac + \
"&utmcc=__utma" + "%3D" + gen_utma() + "%3B"
#"&utmvid=" + visitor_id + \
#"&utmip=" + get_ip(environ.get("REMOTE_ADDR",''))
send_request_to_google_analytics(utm_url, environ)
headers = [('Set-Cookie', str(cookie).split(': ')[1])]
if environ['GET'].get('utmdebug', False):
headers.append(('X-GA-MOBILE-URL', utm_url))
response = write_gif_data()
response_headers = response['response_headers']
response_headers.extend(headers)
return response
示例3: __init__
def __init__(self, query_string, mutable=False, encoding=None):
MultiValueDict.__init__(self)
if not encoding:
encoding = settings.DEFAULT_CHARSET
self.encoding = encoding
for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True
self.appendlist(force_unicode(key, encoding, errors='replace'),
force_unicode(value, encoding, errors='replace'))
self._mutable = mutable
示例4: __init__
def __init__(self, query_string, mutable=False, encoding=None):
MultiValueDict.__init__(self)
if not encoding:
# *Important*: do not import settings any earlier because of note
# in core.handlers.modpython.
from django.conf import settings
encoding = settings.DEFAULT_CHARSET
self.encoding = encoding
for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True
self.appendlist(force_unicode(key, encoding, errors='replace'),
force_unicode(value, encoding, errors='replace'))
self._mutable = mutable
示例5: get_post
def get_post(self):
if not hasattr(self, "_post"):
try:
content_length = int(self.environ.get("CONTENT_LENGTH", 0))
except (ValueError, TypeError):
content_length = 0
if content_length > 0:
body = self.environ["wsgi.input"].read(int(self.environ.get("CONTENT_LENGTH", 0)))
self._post = dict((k, v) for k, v in parse_qsl(body, True))
else:
self._post = {}
return self._post
示例6: get_openid_return_url
def get_openid_return_url(request,
return_view_name='openid_auth-complete_openid_login',
redirect_field_name=REDIRECT_FIELD_NAME,
redirect=None):
"""
Get the URL to tell the openid server to redirect back to and, if
available, append the redirect query parameter.
"""
url = urlparse.urljoin(get_openid_return_host(request),
get_openid_return_path(return_view_name))
(scheme, location, path, query, fragment) = urlparse.urlsplit(url)
#If a 'redirect' attribute is provided, append that to the openid_return_url
if redirect and is_valid_redirect_url(redirect):
query_kv = parse_qsl(query)
query_kv.append((redirect_field_name, redirect))
query = urllib.urlencode(query_kv)
return iri_to_uri(urlparse.urlunsplit((scheme, location, path, query, fragment)))
示例7: grab
def grab(req):
req.content_type = 'text/html'
out=""
pairs = dict(util.parse_qsl(req.args))
if pairs.has_key("refresh"):
out+="<p style='background-color: #DDFFEE'>Refresh</p>"
if pairs.has_key("str"):
poss= difflib.get_close_matches(pairs["str"],rules, cutoff=0.3)
out+="<dl>\n"
for i in poss:
out+= "<dt>%s</dt><dd>%s</dd>\n"%(i,r[i])
out+="</dl>\n"
return out
else:
return "NO"
示例8: __init__
def __init__(self, query_string):
try:
from mod_python.util import parse_qsl
except ImportError:
from cgi import parse_qsl
if not query_string:
self.data = {}
self._keys = []
else:
self.data = {}
self._keys = []
for name, value in parse_qsl(query_string, True): # keep_blank_values=True
if name in self.data:
self.data[name].append(value)
else:
self.data[name] = [value]
if name not in self._keys:
self._keys.append(name)
self._mutable = False
示例9: parse_backend_uri
def parse_backend_uri(backend_uri):
"""
Converts the "backend_uri" into a cache scheme ('db', 'memcached', etc), a
host and any extra params that are required for the backend. Returns a
(scheme, host, params) tuple.
"""
if backend_uri.find(':') == -1:
raise InvalidCacheBackendError("Backend URI must start with scheme://")
scheme, rest = backend_uri.split(':', 1)
if not rest.startswith('//'):
raise InvalidCacheBackendError("Backend URI must start with scheme://")
host = rest[2:]
qpos = rest.find('?')
if qpos != -1:
params = dict(parse_qsl(rest[qpos+1:]))
host = rest[2:qpos]
else:
params = {}
if host.endswith('/'):
host = host[:-1]
return scheme, host, params
示例10: __init__
def __init__(self, query_string, mutable=False):
MultiValueDict.__init__(self)
self._mutable = True
for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True
self.appendlist(key, value)
self._mutable = mutable
示例11: track_page_view
def track_page_view(environ):
"""
// Track a page view, updates all the cookies and campaign tracker,
// makes a server side request to Google Analytics and writes the transparent
// gif byte data to the response.
"""
time_tup = time.localtime(time.time() + COOKIE_USER_PERSISTENCE)
# set some useful items in environ:
environ['COOKIES'] = parse_cookie(environ.get('HTTP_COOKIE', ''))
environ['GET'] = {}
for key, value in parse_qsl(environ.get('QUERY_STRING', ''), True):
environ['GET'][key] = value # we only have one value per key name, right? :)
x_utmac = environ['GET'].get('x_utmac', None)
domain = environ.get('HTTP_HOST', '')
# Get the referrer from the utmr parameter, this is the referrer to the
# page that contains the tracking pixel, not the referrer for tracking
# pixel.
document_referer = environ['GET'].get("utmr", "")
if not document_referer or document_referer == "0":
document_referer = "-"
else:
document_referer = unquote(document_referer)
document_path = environ['GET'].get('utmp', "")
if document_path:
document_path = unquote(document_path)
account = environ['GET'].get('utmac', '')
user_agent = environ.get("HTTP_USER_AGENT", '')
# // Try and get visitor cookie from the request.
cookie = environ['COOKIES'].get(COOKIE_NAME)
visitor_id = get_visitor_id(environ.get("HTTP_X_DCMGUID", ''), account, user_agent, cookie)
# // Always try and add the cookie to the response.
cookie = SimpleCookie()
cookie[COOKIE_NAME] = visitor_id
morsel = cookie[COOKIE_NAME]
morsel['expires'] = time.strftime('%a, %d-%b-%Y %H:%M:%S %Z', time_tup)
morsel['path'] = COOKIE_PATH
utm_gif_location = "http://www.google-analytics.com/__utm.gif"
for utmac in [account, x_utmac]:
if not utmac:
continue # ignore empty utmacs
# // Construct the gif hit url.
utm_url = utm_gif_location + "?" + \
"utmwv=" + VERSION + \
"&utmn=" + get_random_number() + \
"&utmhn=" + quote(domain) + \
"&utmsr=" + environ['GET'].get('utmsr', '') + \
"&utme=" + environ['GET'].get('utme', '') + \
"&utmr=" + quote(document_referer) + \
"&utmp=" + quote(document_path) + \
"&utmac=" + utmac + \
"&utmcc=__utma%3D999.999.999.999.999.1%3B" + \
"&utmvid=" + visitor_id + \
"&utmip=" + get_ip(environ.get("REMOTE_ADDR",''))
# dbgMsg("utm_url: " + utm_url)
send_request_to_google_analytics(utm_url, environ)
# // If the debug parameter is on, add a header to the response that contains
# // the url that was used to contact Google Analytics.
headers = [('Set-Cookie', str(cookie).split(': ')[1])]
if environ['GET'].get('utmdebug', False):
headers.append(('X-GA-MOBILE-URL', utm_url))
# Finally write the gif data to the response
response = write_gif_data()
response_headers = response['response_headers']
response_headers.extend(headers)
return response
示例12: get_get
def get_get(self):
if not hasattr(self, "_get"):
self._get = dict((k, v) for k, v in parse_qsl(self.environ.get("QUERY_STRING", ""), True))
return self._get