コード例 #1
0
ファイル: test_http.py プロジェクト: kennym/itools
 def test_example1(self):
     # Client requests a document, and receives in the response:
     a = ('CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday,'
          ' 09-Nov-99 23:12:40 GMT')
     b = {'customer': Cookie('WILE_E_COYOTE', path='/',
                             expires='Wednesday, 09-Nov-99 23:12:40 GMT')}
     self.assertEqual(SetCookieDataType.decode(a), b)
     # When client requests a URL in path "/" on this server, it sends:
     a = 'CUSTOMER=WILE_E_COYOTE'
     b = {'customer': Cookie('WILE_E_COYOTE')}
     self.assertEqual(CookieDataType.decode(a), b)
     # Client requests a document, and receives in the response:
     a = 'PART_NUMBER=ROCKET_LAUNCHER_0001; path=/'
     b = {'part_number': Cookie('ROCKET_LAUNCHER_0001', path='/')}
     self.assertEqual(SetCookieDataType.decode(a), b)
     # When client requests a URL in path "/" on this server, it sends:
     a = 'CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001'
     b = {'customer': Cookie('WILE_E_COYOTE'),
          'part_number': Cookie('ROCKET_LAUNCHER_0001')}
     self.assertEqual(CookieDataType.decode(a), b)
     # Client receives:
     a = 'SHIPPING=FEDEX; path=/foo'
     b = {'shipping': Cookie('FEDEX', path='/foo')}
     self.assertEqual(SetCookieDataType.decode(a), b)
     # When client requests a URL in path "/foo" on this server, it sends:
     a = 'CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX'
     b = {'customer': Cookie('WILE_E_COYOTE'),
          'part_number': Cookie('ROCKET_LAUNCHER_0001'),
          'shipping': Cookie('FEDEX')}
     self.assertEqual(CookieDataType.decode(a), b)
コード例 #2
0
ファイル: context.py プロジェクト: pombredanne/itools
 def del_cookie(self, name):
     self.cookies[name] = None
     # libsoup
     expires = 'Wed, 31-Dec-97 23:59:59 GMT'
     cookie = Cookie('deleted', expires=expires, max_age='0')
     cookie = SetCookieDataType.encode({name: cookie})
     self.soup_message.append_header('Set-Cookie', cookie)
コード例 #3
0
 def test_example1(self):
     # Client requests a document, and receives in the response:
     a = ('CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday,'
          ' 09-Nov-99 23:12:40 GMT')
     b = {
         'customer':
         Cookie('WILE_E_COYOTE',
                path='/',
                expires='Wednesday, 09-Nov-99 23:12:40 GMT')
     }
     self.assertEqual(SetCookieDataType.decode(a), b)
     # When client requests a URL in path "/" on this server, it sends:
     a = 'CUSTOMER=WILE_E_COYOTE'
     b = {'customer': Cookie('WILE_E_COYOTE')}
     self.assertEqual(CookieDataType.decode(a), b)
     # Client requests a document, and receives in the response:
     a = 'PART_NUMBER=ROCKET_LAUNCHER_0001; path=/'
     b = {'part_number': Cookie('ROCKET_LAUNCHER_0001', path='/')}
     self.assertEqual(SetCookieDataType.decode(a), b)
     # When client requests a URL in path "/" on this server, it sends:
     a = 'CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001'
     b = {
         'customer': Cookie('WILE_E_COYOTE'),
         'part_number': Cookie('ROCKET_LAUNCHER_0001')
     }
     self.assertEqual(CookieDataType.decode(a), b)
     # Client receives:
     a = 'SHIPPING=FEDEX; path=/foo'
     b = {'shipping': Cookie('FEDEX', path='/foo')}
     self.assertEqual(SetCookieDataType.decode(a), b)
     # When client requests a URL in path "/foo" on this server, it sends:
     a = 'CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX'
     b = {
         'customer': Cookie('WILE_E_COYOTE'),
         'part_number': Cookie('ROCKET_LAUNCHER_0001'),
         'shipping': Cookie('FEDEX')
     }
     self.assertEqual(CookieDataType.decode(a), b)
コード例 #4
0
ファイル: test_http.py プロジェクト: kennym/itools
 def test_set_cookie_decode_encode_decode(self):
     a = 'Customer="WILE_E_COYOTE"; Path="/acme"'
     b = SetCookieDataType.decode(a)
     c = SetCookieDataType.encode(b)
     d = SetCookieDataType.decode(c)
     self.assertEqual(b, d)
コード例 #5
0
 def test_set_cookie_decode_encode_decode(self):
     a = 'Customer="WILE_E_COYOTE"; Path="/acme"'
     b = SetCookieDataType.decode(a)
     c = SetCookieDataType.encode(b)
     d = SetCookieDataType.decode(c)
     self.assertEqual(b, d)
コード例 #6
0
ファイル: context.py プロジェクト: pombredanne/itools
 def set_cookie(self, name, value, **kw):
     self.cookies[name] = value
     # libsoup
     cookie = Cookie(value, **kw)
     cookie = SetCookieDataType.encode({name: cookie})
     self.soup_message.append_header('Set-Cookie', cookie)