@@ -1344,6 +1344,103 @@ def check(result):
13441344 check (func (burl ))
13451345 check (func (burl , missing_as_none = True ))
13461346
1347+ def test_result_compat_unpickling (self ):
1348+ def check (result , pickles ):
1349+ for pickled in pickles :
1350+ result2 = pickle .loads (pickled )
1351+ self .assertEqual (result2 , result )
1352+ self .assertEqual (result2 .geturl (), result .geturl ())
1353+
1354+ url = 'http://example.com/?#'
1355+ burl = url .encode ()
1356+ # Pre-3.15 data.
1357+ check (urldefrag (url ), (
1358+ b'ccopy_reg\n _reconstructor\n (curlparse\n DefragResult\n c__builtin__\n tuple\n (Vhttp://example.com/?\n V\n ttR.' ,
1359+ b'ccopy_reg\n _reconstructor\n (curlparse\n DefragResult\n c__builtin__\n tuple\n (X\x14 \x00 \x00 \x00 http://example.com/?X\x00 \x00 \x00 \x00 ttR.' ,
1360+ b'\x80 \x02 curlparse\n DefragResult\n X\x14 \x00 \x00 \x00 http://example.com/?X\x00 \x00 \x00 \x00 \x86 \x81 .' ,
1361+ b'\x80 \x03 curllib.parse\n DefragResult\n X\x14 \x00 \x00 \x00 http://example.com/?X\x00 \x00 \x00 \x00 \x86 \x81 .' ,
1362+ b'\x80 \x04 \x95 8\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x0c DefragResult\x93 \x8c \x14 http://example.com/?\x8c \x00 \x86 \x81 .' ,
1363+ ))
1364+ check (urldefrag (burl ), (
1365+ b'ccopy_reg\n _reconstructor\n (curlparse\n DefragResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n (Vhttp://example.com/?\n Vlatin1\n tRc__builtin__\n bytes\n (tRttR.' ,
1366+ b'ccopy_reg\n _reconstructor\n (curlparse\n DefragResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n (X\x14 \x00 \x00 \x00 http://example.com/?X\x06 \x00 \x00 \x00 latin1tRc__builtin__\n bytes\n )RttR.' ,
1367+ b'\x80 \x02 curlparse\n DefragResultBytes\n c_codecs\n encode\n X\x14 \x00 \x00 \x00 http://example.com/?X\x06 \x00 \x00 \x00 latin1\x86 Rc__builtin__\n bytes\n )R\x86 \x81 .' ,
1368+ b'\x80 \x03 curllib.parse\n DefragResultBytes\n C\x14 http://example.com/?C\x00 \x86 \x81 .' ,
1369+ b'\x80 \x04 \x95 =\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x11 DefragResultBytes\x93 C\x14 http://example.com/?C\x00 \x86 \x81 .' ,
1370+ ))
1371+ check (urlsplit (url ), (
1372+ b'ccopy_reg\n _reconstructor\n (curlparse\n SplitResult\n c__builtin__\n tuple\n (Vhttp\n Vexample.com\n V/\n V\n p0\n g0\n ttR.' ,
1373+ b'ccopy_reg\n _reconstructor\n (curlparse\n SplitResult\n c__builtin__\n tuple\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 ttR.' ,
1374+ b'\x80 \x02 curlparse\n SplitResult\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 t\x81 .' ,
1375+ b'\x80 \x03 curllib.parse\n SplitResult\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 t\x81 .' ,
1376+ b'\x80 \x04 \x95 ;\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x0b SplitResult\x93 (\x8c \x04 http\x8c \x0b example.com\x8c \x01 /\x8c \x00 \x94 h\x00 t\x81 .' ,
1377+ ))
1378+ check (urlsplit (burl ), (
1379+ b'ccopy_reg\n _reconstructor\n (curlparse\n SplitResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n p0\n (Vhttp\n Vlatin1\n p1\n tRg0\n (Vexample.com\n g1\n tRg0\n (V/\n g1\n tRc__builtin__\n bytes\n (tRp2\n g2\n ttR.' ,
1380+ b'ccopy_reg\n _reconstructor\n (curlparse\n SplitResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n q\x00 (X\x04 \x00 \x00 \x00 httpX\x06 \x00 \x00 \x00 latin1q\x01 tRh\x00 (X\x0b \x00 \x00 \x00 example.comh\x01 tRh\x00 (X\x01 \x00 \x00 \x00 /h\x01 tRc__builtin__\n bytes\n )Rq\x02 h\x02 ttR.' ,
1381+ b'\x80 \x02 curlparse\n SplitResultBytes\n (c_codecs\n encode\n q\x00 X\x04 \x00 \x00 \x00 httpX\x06 \x00 \x00 \x00 latin1q\x01 \x86 Rh\x00 X\x0b \x00 \x00 \x00 example.comh\x01 \x86 Rh\x00 X\x01 \x00 \x00 \x00 /h\x01 \x86 Rc__builtin__\n bytes\n )Rq\x02 h\x02 t\x81 .' ,
1382+ b'\x80 \x03 curllib.parse\n SplitResultBytes\n (C\x04 httpC\x0b example.comC\x01 /C\x00 q\x00 h\x00 t\x81 .' ,
1383+ b'\x80 \x04 \x95 @\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x10 SplitResultBytes\x93 (C\x04 httpC\x0b example.comC\x01 /C\x00 \x94 h\x00 t\x81 .' ,
1384+ ))
1385+ check (urlparse (url ), (
1386+ b'ccopy_reg\n _reconstructor\n (curlparse\n ParseResult\n c__builtin__\n tuple\n (Vhttp\n Vexample.com\n V/\n V\n p0\n g0\n g0\n ttR.' ,
1387+ b'ccopy_reg\n _reconstructor\n (curlparse\n ParseResult\n c__builtin__\n tuple\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 h\x00 ttR.' ,
1388+ b'\x80 \x02 curlparse\n ParseResult\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 h\x00 t\x81 .' ,
1389+ b'\x80 \x03 curllib.parse\n ParseResult\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 h\x00 t\x81 .' ,
1390+ b'\x80 \x04 \x95 =\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x0b ParseResult\x93 (\x8c \x04 http\x8c \x0b example.com\x8c \x01 /\x8c \x00 \x94 h\x00 h\x00 t\x81 .' ,
1391+ ))
1392+ check (urlparse (burl ), (
1393+ b'ccopy_reg\n _reconstructor\n (curlparse\n ParseResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n p0\n (Vhttp\n Vlatin1\n p1\n tRg0\n (Vexample.com\n g1\n tRg0\n (V/\n g1\n tRc__builtin__\n bytes\n (tRp2\n g2\n g2\n ttR.' ,
1394+ b'ccopy_reg\n _reconstructor\n (curlparse\n ParseResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n q\x00 (X\x04 \x00 \x00 \x00 httpX\x06 \x00 \x00 \x00 latin1q\x01 tRh\x00 (X\x0b \x00 \x00 \x00 example.comh\x01 tRh\x00 (X\x01 \x00 \x00 \x00 /h\x01 tRc__builtin__\n bytes\n )Rq\x02 h\x02 h\x02 ttR.' ,
1395+ b'\x80 \x02 curlparse\n ParseResultBytes\n (c_codecs\n encode\n q\x00 X\x04 \x00 \x00 \x00 httpX\x06 \x00 \x00 \x00 latin1q\x01 \x86 Rh\x00 X\x0b \x00 \x00 \x00 example.comh\x01 \x86 Rh\x00 X\x01 \x00 \x00 \x00 /h\x01 \x86 Rc__builtin__\n bytes\n )Rq\x02 h\x02 h\x02 t\x81 .' ,
1396+ b'\x80 \x03 curllib.parse\n ParseResultBytes\n (C\x04 httpC\x0b example.comC\x01 /C\x00 q\x00 h\x00 h\x00 t\x81 .' ,
1397+ b'\x80 \x04 \x95 B\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x10 ParseResultBytes\x93 (C\x04 httpC\x0b example.comC\x01 /C\x00 \x94 h\x00 h\x00 t\x81 .' ,
1398+ ))
1399+
1400+ # 3.15 data with missing_as_none=True.
1401+ check (urldefrag (url , missing_as_none = True ), (
1402+ b'ccopy_reg\n _reconstructor\n (curlparse\n DefragResult\n c__builtin__\n tuple\n (Vhttp://example.com/?\n V\n ttR(N(dV_keep_empty\n I01\n stb.' ,
1403+ b'ccopy_reg\n _reconstructor\n (curlparse\n DefragResult\n c__builtin__\n tuple\n (X\x14 \x00 \x00 \x00 http://example.com/?X\x00 \x00 \x00 \x00 ttR(N}X\x0b \x00 \x00 \x00 _keep_emptyI01\n stb.' ,
1404+ b'\x80 \x02 curlparse\n DefragResult\n X\x14 \x00 \x00 \x00 http://example.com/?X\x00 \x00 \x00 \x00 \x86 \x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1405+ b'\x80 \x03 curllib.parse\n DefragResult\n X\x14 \x00 \x00 \x00 http://example.com/?X\x00 \x00 \x00 \x00 \x86 \x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1406+ b'\x80 \x04 \x95 K\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x0c DefragResult\x93 \x8c \x14 http://example.com/?\x8c \x00 \x86 \x81 N}\x8c \x0b _keep_empty\x88 s\x86 b.' ,
1407+ ))
1408+ check (urldefrag (burl , missing_as_none = True ), (
1409+ b'ccopy_reg\n _reconstructor\n (curlparse\n DefragResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n (Vhttp://example.com/?\n Vlatin1\n tRc__builtin__\n bytes\n (tRttR(N(dV_keep_empty\n I01\n stb.' ,
1410+ b'ccopy_reg\n _reconstructor\n (curlparse\n DefragResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n (X\x14 \x00 \x00 \x00 http://example.com/?X\x06 \x00 \x00 \x00 latin1tRc__builtin__\n bytes\n )RttR(N}X\x0b \x00 \x00 \x00 _keep_emptyI01\n stb.' ,
1411+ b'\x80 \x02 curlparse\n DefragResultBytes\n c_codecs\n encode\n X\x14 \x00 \x00 \x00 http://example.com/?X\x06 \x00 \x00 \x00 latin1\x86 Rc__builtin__\n bytes\n )R\x86 \x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1412+ b'\x80 \x03 curllib.parse\n DefragResultBytes\n C\x14 http://example.com/?C\x00 \x86 \x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1413+ b'\x80 \x04 \x95 P\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x11 DefragResultBytes\x93 C\x14 http://example.com/?C\x00 \x86 \x81 N}\x8c \x0b _keep_empty\x88 s\x86 b.' ,
1414+ ))
1415+ check (urlsplit (url , missing_as_none = True ), (
1416+ b'ccopy_reg\n _reconstructor\n (curlparse\n SplitResult\n c__builtin__\n tuple\n (Vhttp\n Vexample.com\n V/\n V\n p0\n g0\n ttR(N(dV_keep_empty\n I01\n stb.' ,
1417+ b'ccopy_reg\n _reconstructor\n (curlparse\n SplitResult\n c__builtin__\n tuple\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 ttR(N}X\x0b \x00 \x00 \x00 _keep_emptyI01\n stb.' ,
1418+ b'\x80 \x02 curlparse\n SplitResult\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 t\x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1419+ b'\x80 \x03 curllib.parse\n SplitResult\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /X\x00 \x00 \x00 \x00 q\x00 h\x00 t\x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1420+ b'\x80 \x04 \x95 N\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x0b SplitResult\x93 (\x8c \x04 http\x8c \x0b example.com\x8c \x01 /\x8c \x00 \x94 h\x00 t\x81 N}\x8c \x0b _keep_empty\x88 s\x86 b.' ,
1421+ ))
1422+ check (urlsplit (burl , missing_as_none = True ), (
1423+ b'ccopy_reg\n _reconstructor\n (curlparse\n SplitResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n p0\n (Vhttp\n Vlatin1\n p1\n tRg0\n (Vexample.com\n g1\n tRg0\n (V/\n g1\n tRc__builtin__\n bytes\n (tRp2\n g2\n ttR(N(dV_keep_empty\n I01\n stb.' ,
1424+ b'ccopy_reg\n _reconstructor\n (curlparse\n SplitResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n q\x00 (X\x04 \x00 \x00 \x00 httpX\x06 \x00 \x00 \x00 latin1q\x01 tRh\x00 (X\x0b \x00 \x00 \x00 example.comh\x01 tRh\x00 (X\x01 \x00 \x00 \x00 /h\x01 tRc__builtin__\n bytes\n )Rq\x02 h\x02 ttR(N}X\x0b \x00 \x00 \x00 _keep_emptyI01\n stb.' ,
1425+ b'\x80 \x02 curlparse\n SplitResultBytes\n (c_codecs\n encode\n q\x00 X\x04 \x00 \x00 \x00 httpX\x06 \x00 \x00 \x00 latin1q\x01 \x86 Rh\x00 X\x0b \x00 \x00 \x00 example.comh\x01 \x86 Rh\x00 X\x01 \x00 \x00 \x00 /h\x01 \x86 Rc__builtin__\n bytes\n )Rq\x02 h\x02 t\x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1426+ b'\x80 \x03 curllib.parse\n SplitResultBytes\n (C\x04 httpC\x0b example.comC\x01 /C\x00 q\x00 h\x00 t\x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1427+ b'\x80 \x04 \x95 S\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x10 SplitResultBytes\x93 (C\x04 httpC\x0b example.comC\x01 /C\x00 \x94 h\x00 t\x81 N}\x8c \x0b _keep_empty\x88 s\x86 b.' ,
1428+ ))
1429+ check (urlparse (url , missing_as_none = True ), (
1430+ b'ccopy_reg\n _reconstructor\n (curlparse\n ParseResult\n c__builtin__\n tuple\n (Vhttp\n Vexample.com\n V/\n NV\n p0\n g0\n ttR(N(dV_keep_empty\n I01\n stb.' ,
1431+ b'ccopy_reg\n _reconstructor\n (curlparse\n ParseResult\n c__builtin__\n tuple\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /NX\x00 \x00 \x00 \x00 q\x00 h\x00 ttR(N}X\x0b \x00 \x00 \x00 _keep_emptyI01\n stb.' ,
1432+ b'\x80 \x02 curlparse\n ParseResult\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /NX\x00 \x00 \x00 \x00 q\x00 h\x00 t\x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1433+ b'\x80 \x03 curllib.parse\n ParseResult\n (X\x04 \x00 \x00 \x00 httpX\x0b \x00 \x00 \x00 example.comX\x01 \x00 \x00 \x00 /NX\x00 \x00 \x00 \x00 q\x00 h\x00 t\x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1434+ b'\x80 \x04 \x95 O\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x0b ParseResult\x93 (\x8c \x04 http\x8c \x0b example.com\x8c \x01 /N\x8c \x00 \x94 h\x00 t\x81 N}\x8c \x0b _keep_empty\x88 s\x86 b.' ,
1435+ ))
1436+ check (urlparse (burl , missing_as_none = True ), (
1437+ b'ccopy_reg\n _reconstructor\n (curlparse\n ParseResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n p0\n (Vhttp\n Vlatin1\n p1\n tRg0\n (Vexample.com\n g1\n tRg0\n (V/\n g1\n tRNc__builtin__\n bytes\n (tRp2\n g2\n ttR(N(dV_keep_empty\n I01\n stb.' ,
1438+ b'ccopy_reg\n _reconstructor\n (curlparse\n ParseResultBytes\n c__builtin__\n tuple\n (c_codecs\n encode\n q\x00 (X\x04 \x00 \x00 \x00 httpX\x06 \x00 \x00 \x00 latin1q\x01 tRh\x00 (X\x0b \x00 \x00 \x00 example.comh\x01 tRh\x00 (X\x01 \x00 \x00 \x00 /h\x01 tRNc__builtin__\n bytes\n )Rq\x02 h\x02 ttR(N}X\x0b \x00 \x00 \x00 _keep_emptyI01\n stb.' ,
1439+ b'\x80 \x02 curlparse\n ParseResultBytes\n (c_codecs\n encode\n q\x00 X\x04 \x00 \x00 \x00 httpX\x06 \x00 \x00 \x00 latin1q\x01 \x86 Rh\x00 X\x0b \x00 \x00 \x00 example.comh\x01 \x86 Rh\x00 X\x01 \x00 \x00 \x00 /h\x01 \x86 RNc__builtin__\n bytes\n )Rq\x02 h\x02 t\x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1440+ b'\x80 \x03 curllib.parse\n ParseResultBytes\n (C\x04 httpC\x0b example.comC\x01 /NC\x00 q\x00 h\x00 t\x81 N}X\x0b \x00 \x00 \x00 _keep_empty\x88 s\x86 b.' ,
1441+ b'\x80 \x04 \x95 T\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \x0c urllib.parse\x8c \x10 ParseResultBytes\x93 (C\x04 httpC\x0b example.comC\x01 /NC\x00 \x94 h\x00 t\x81 N}\x8c \x0b _keep_empty\x88 s\x86 b.' ,
1442+ ))
1443+
13471444 def test_parse_qs_encoding (self ):
13481445 result = urllib .parse .parse_qs ("key=\u0141 %E9" , encoding = "latin-1" )
13491446 self .assertEqual (result , {'key' : ['\u0141 \xE9 ' ]})
0 commit comments