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
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
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
def __init__(self, req): """ The mod_python FieldStorage implementation, unlike cgi.py, always includes GET parameters, even if they are also defined in the body of a POST request. We work around this to provide the behaviour of cgi.py here. """ class RequestWrapper(object): def __init__(self, req): self.req = req self.args = '' def __getattr__(self, name): return getattr(self.req, name) util.FieldStorage.__init__(self, RequestWrapper(req), keep_blank_values=1) # Populate FieldStorage with the original query string parameters, if # they aren't already defined through the request body if req.args: qsargs = [] for pair in util.parse_qsl(req.args, 1): if self.has_key(pair[0]): continue qsargs.append(util.Field(pair[0], StringIO(pair[1]), "text/plain", {}, None, {})) self.list += qsargs
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
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
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
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
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"
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)))
def get_openid_return_url( request, return_view_name='openid_auth.views.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)))
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
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
def attributes(self): """ A request body, deserialized as a dictionary. This will automatically deserialize form or JSON encoded request bodies. """ if not hasattr(self, '_attributes'): if self.content_length > 0: content = self.body.read(self.content_length) content_type = self.environ.get('CONTENT_TYPE', None) content_type = content_type.split(';')[0] if content_type in JSON_CONTENT_TYPES: self._attributes = JSONDecoder().decode(content) elif content_type == 'application/x-www-form-urlencoded': data = parse_qsl(content, True) self._attributes = dict((k, v) for k, v in data) else: self._attributes = {} return self._attributes
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
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
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
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