Esempio n. 1
0
 def test_decode_2(self):
     """
     Test that we haven't broken normal encoding
     """
     c = CompatCookie()
     c['test'] = "\xf0"
     c2 = CompatCookie()
     c2.load(c.output())
     self.assertEqual(c['test'].value, c2['test'].value)
Esempio n. 2
0
 def test_decode(self):
     """
     Test that we can still preserve semi-colons and commas
     """
     c = CompatCookie()
     c['test'] = "An,awkward;value"
     c2 = CompatCookie()
     c2.load(c.output())
     self.assertEqual(c['test'].value, c2['test'].value)
    def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
        """
        Stores the messages to a cookie, returning a list of any messages which
        could not be stored.

        If the encoded data is larger than ``max_cookie_size``, removes
        messages until the data fits (these are the messages which are
        returned), and add the not_finished sentinel value to indicate as much.
        """
        unstored_messages = []
        encoded_data = self._encode(messages)
        if self.max_cookie_size:
            # data is going to be stored eventually by CompatCookie, which
            # adds it's own overhead, which we must account for.
            cookie = CompatCookie()  # create outside the loop

            def stored_length(val):
                return len(cookie.value_encode(val)[1])

            while encoded_data and stored_length(
                    encoded_data) > self.max_cookie_size:
                if remove_oldest:
                    unstored_messages.append(messages.pop(0))
                else:
                    unstored_messages.insert(0, messages.pop())
                encoded_data = self._encode(messages + [self.not_finished],
                                            encode_empty=unstored_messages)
        self._update_cookie(encoded_data, response)
        return unstored_messages
Esempio n. 4
0
 def test_encode(self):
     """
     Test that we don't output tricky characters in encoded value
     """
     # Python 2.4 compatibility note: Python 2.4's cookie implementation
     # always returns Set-Cookie headers terminating in semi-colons.
     # That's not the bug this test is looking for, so ignore it.
     c = CompatCookie()
     c['test'] = "An,awkward;value"
     self.assert_(";" not in c.output().rstrip(';'))  # IE compat
     self.assert_("," not in c.output().rstrip(';'))  # Safari compat
Esempio n. 5
0
    def process_request(self, request):

        request._resp_cookies = CompatCookie()
        request.set_cookie = MethodType(_set_cookie, request, HttpRequest)
        request.delete_cookie = MethodType(_delete_cookie, request, HttpRequest)