Пример #1
0
    def test_basic_encoding(self):
        should_encode = [chr(num) for num in range(32)] # For 0x00 - 0x1F
        should_encode.append('<>#%"{}|\^[]`')
        should_encode.append(chr(127)) # For 0x7F
        should_encode = ''.join(should_encode)

        for char in should_encode:
            result = yuri.encode(char, query=False)
            self.assertEqual(hexed(char), result)
            result = yuri.encode(char, query=True)
            self.assertEqual(hexed(char), result)

        del should_encode
        partial_encode = 'ab[]cd'
        expected = 'ab%5B%5Dcd'
        result = yuri.encode(partial_encode, query=True)
        self.assertEqual(expected, result)
        result = yuri.encode(partial_encode, query=False)
        self.assertEqual(expected, result)
        self.assertRaises(TypeError, yuri.encode, None)
Пример #2
0
 def test_path_encoding(self):
     self.assertEqual(yuri.encode('/', query=False), '/')
     self.assertEqual(yuri.encode(' ', query=False), '%20')
Пример #3
0
 def test_query_encoding(self):
     self.assertEqual(yuri.encode('/', query=True), '%2F')
     self.assertEqual(yuri.encode(' ', query=True), '+')
Пример #4
0
    def test_unreserved_characters(self):
        result = yuri.encode(yuri.unreserved_characters, query=False)
        self.assertEqual(result, yuri.unreserved_characters)

        result = yuri.encode(yuri.unreserved_characters, query=True)
        self.assertEqual(result, yuri.unreserved_characters)