Example #1
0
 def __read_cookies(self):
     from Cookie import SimpleCookie
     cookies_raw = SimpleCookie(self.get_env('HTTP_COOKIE'))
     cookies     = {}
     for key, field in cookies_raw.iteritems():
         cookies[key] = field.value
     return Table(cookies, allow_duplicates = False, readonly = True)
Example #2
0
 def cookies(self):
     """Stored Cookies."""
     cookie = SimpleCookie()
     cookie.load(self.environ.get('HTTP_COOKIE', ''))
     result = {}
     for key, value in cookie.iteritems():
         result[key] = value.value.decode(self.charset, 'ignore')
     return result
Example #3
0
 def cookies(self):
     """Stored Cookies."""
     cookie = SimpleCookie()
     cookie.load(self.environ.get('HTTP_COOKIE', ''))
     result = {}
     for key, value in cookie.iteritems():
         result[key] = value.value.decode(self.charset, 'ignore')
     return result
Example #4
0
 def cookies(self):
     from Cookie import SimpleCookie
     cookie = SimpleCookie()
     cookie.load(self.environ.get('HTTP_COOKIE', ''))
     result = {}
     for key, value in cookie.iteritems():
         result[key] = value
     return result
Example #5
0
    def rewrite(self, cookie_str, header='Set-Cookie'):
        results = []
        cookie = SimpleCookie()
        try:
            cookie.load(cookie_str)
        except CookieError:
            return results

        for name, morsel in cookie.iteritems():
            morsel = self.rewrite_cookie(name, morsel)
            if morsel:
                results.append((header, morsel.OutputString()))

        return results
Example #6
0
def dump_cookies(response = None):
    if not response:
        response = current_app.make_response('')
    cookie_headers = (header[1] for header in response.headers if header[0] == 'Set-Cookie')
    cookies = SimpleCookie()
    for header in cookie_headers:
        cookies.load(str(header))
    cookies_dump = []
    cookies_dump += dict(request.cookies),
    cookies_dump += dict((name, dict(value=cookie.coded_value, **cookie))\
                                        for name, cookie in cookies.iteritems()),

    response.data = render_template('dump_cookies.html', dump=dumps(cookies_dump))
    return response
Example #7
0
    def rewrite(self, cookie_str, header='Set-Cookie'):
        results = []
        cookie = SimpleCookie()
        try:
            cookie.load(cookie_str)
        except CookieError:
            return results

        for name, morsel in cookie.iteritems():
            morsel = self.rewrite_cookie(name, morsel)
            if morsel:
                results.append((header, morsel.OutputString()))

        return results
Example #8
0
def parse_cookie(environ):
    """Parse the cookie from request.

    :return A dict(key: cookie name, value: the cookie value, not the instance of Morsel)
            The cookies should be like this:
            {'session_id': '1', 'test': 'xxx'}

    """
    raw_cookie = SimpleCookie(environ.get('HTTP_COOKIE', ''))
    cookie = {}
    for key, value in raw_cookie.iteritems():
        # cookie[key] = value.OutputString()[len(key)+1:]
        cookie_str = value.OutputString()
        k, v = parse_dict_string(cookie_str, split_sign='=', use_tuple=True)
        cookie[k] = v
    return cookie
Example #9
0
def generate_cookies():
    cookies = SimpleCookie()

    cookies['view']        =        view_to_str(options.view)
    cookies['state']       =       state_to_str(remote_state.state)
    cookies['mode']        =        mode_to_str(remote_state.mode)
    cookies['temperature'] = temperature_to_str(remote_state.temperature)
    cookies['fan_speed']   =   fan_speed_to_str(remote_state.fan_speed)
    cookies['full_effect'] = full_effect_to_str(remote_state.full_effect)
    cookies['ion']         =         ion_to_str(remote_state.ion)
    cookies['swing']       =       swing_to_str(remote_state.swing)

    for (k, v) in cookies.iteritems():
        v['path'] = '/'

    return cookies
Example #10
0
    def rewrite(self, cookie_str, header='Set-Cookie'):
        results = []
        cookie = SimpleCookie()
        try:
            cookie.load(cookie_str)
        except CookieError:
            return results

        for name, morsel in cookie.iteritems():
            morsel = self.rewrite_cookie(name, morsel)

            if morsel:
                path = morsel.get('path')
                if path:
                    inx = path.find(self.url_rewriter.rel_prefix)
                    if inx > 0:
                        morsel['path'] = path[inx:]

                results.append((header, morsel.OutputString()))

        return results
Example #11
0
def _parse_cookies(request):
  cookie = Cookie(request["headers"].get("cookie"))
  parsed = {}
  for k, v in cookie.iteritems():
    parsed[k] = v.value
  return parsed
Example #12
0
def _parse_cookies(request):
    cookie = Cookie(request["headers"].get("cookie"))
    parsed = {}
    for k, v in cookie.iteritems():
        parsed[k] = v.value
    return parsed
Example #13
0
def error_reporter(request):
    """ Grab an error submitted as a GET request """
    if not request.GET and not request.POST:
        return HttpResponse(
            '')  ## If someone just hits this page at random, ignore it

    url = request.GET.get('url', "")
    domain = Site.objects.get_current().domain
    if url[:4] == 'http' and (domain not in (url[7:(7 + len(domain))],
                                             url[8:(8 + len(domain))])):
        ## Punt responses not from us
        return HttpResponse(
            '')  ## Return something, so we don't trigger an error

    cookies = StringIO()
    get = StringIO()
    meta = StringIO()
    post = StringIO()

    pprint(dict(request.COOKIES), cookies)
    pprint(dict(request.GET), get)
    pprint(dict(request.META), meta)

    user_str = request.user.username if hasattr(
        request,
        'user') and request.user.is_authenticated() else "(not authenticated)"
    user_agent_str = request.META.get('HTTP_USER_AGENT', "(not specified)")

    msg = request.GET.get('msg', "(no message)")

    json_flag = ""

    if request.POST:
        if request.raw_post_data.strip()[0] == '[':
            ## Probably a JSON error report
            ## Let's try to decode it
            try:
                err = json.loads(request.raw_post_data)

                ## Deal with messages that we don't want to deal with
                if is_quirk_should_be_ignored(err):
                    return HttpResponse('')

                json_flag = " (JSON-encoded)"

                for e in err:
                    try:
                        c = SimpleCookie()
                        c.load(str(e['data']['cookie']))
                        e['data']['cookie'] = dict(
                            (str(x), str(y)) for x, y in c.iteritems())
                    except:  ## Whoops, don't have cookie data after all
                        pass

                    ## Also pull out some data, if we can
                    ## 'err' is an array, and we don't need to do this more than once;
                    ## but it should typically be an array of either 0 or 1 elements,
                    ## and we don't want to do it for a 0-length array,
                    ## so just do it in the loop
                    try:
                        if user_str == "(not authenticated)":
                            user_str = "%s %s" % (user_str,
                                                  e['data']['cookie'])
                    except:
                        pass

                    try:
                        if user_agent_str == "(not specified)":
                            user_agent_str = e['env']['user_agent']
                    except:
                        pass

                    try:
                        if msg == "(no message)":
                            msg = e['exception']['message']
                    except:
                        pass
            except Exception, e:
                print "*** Exception!", e
                print json.__dict__
                err = request.raw_post_data

            pprint(err, post)

        else:
            pprint(dict(request.POST), post)
Example #14
0
File: http.py Project: rivan/w3fu
 def _parse_cookie(self):
     try:
         cookie = SimpleCookie(self._env.get('HTTP_COOKIE'))
     except CookieError:
         cookie = {}
     self.cookie = dict((k, v.value) for k, v in cookie.iteritems())