def test_uriencode(self): cases = [ ('%', '%25'), ('あい', '%E3%81%82%E3%81%84'), ('あ い', '%E3%81%82%20%E3%81%84'), ] for input, output in cases: self.assertEqual(uriencode(input), output)
def encode_path(path): splited = urilib.urisplit(path) epath = urilib.uriencode(splited.path, safe='/$*?=&;@,#') if splited.query: query = urilib.uriencode_plus(splited.query, safe='/$*?=&;@,#') path = epath + '?' + query else: if path[-1] == '?': path = epath + '?' else: path = epath return path
def test_encode_bytes(self): cases = [ (b'\xf6lk\xfcrbis', b'%F6lk%FCrbis') ] for input, output in cases: self.assertEqual(uriencode(input), output)
def check(self, decoded, encoded, safe='', encoding='utf-8'): self.assertEqual(uriencode(decoded, safe, encoding), encoded) self.assertEqual(uridecode(encoded, encoding), decoded)