def test_ch_unquote(): eq_(cookies._unquote(b'"hello world'), b'"hello world') eq_(cookies._unquote(b'hello world'), b'hello world') eq_(cookies._unquote(b'"hello world"'), b'hello world') eq_(cookies._quote(b'hello world'), b'"hello world"') # quotation mark is escaped w/ backslash eq_(cookies._unquote(b'"\\""'), b'"') eq_(cookies._quote(b'"'), b'"\\""') # misc byte escaped as octal eq_(cookies._unquote(b'"\\377"'), b'\xff') eq_(cookies._quote(b'\xff'), b'"\\377"') # combination eq_(cookies._unquote(b'"a\\"\\377"'), b'a"\xff') eq_(cookies._quote(b'a"\xff'), b'"a\\"\\377"')
def test_ch_unquote(): eq_(cookies._unquote(u'"hello world'), u'"hello world') eq_(cookies._unquote(u'hello world'), u'hello world') for unq, q in [ ('hello world', '"hello world"'), # quotation mark is escaped w/ backslash ('"', r'"\""'), # misc byte escaped as octal ('\xff', r'"\377"'), # combination ('a"\xff', r'"a\"\377"'), ]: eq_(cookies._unquote(q), unq) eq_(cookies._quote(unq), q)