@@ -1589,8 +1589,6 @@ def test_quote_errors(self):
15891589 self .assertRaises (TypeError , urllib .parse .quote , b'foo' ,
15901590 encoding = 'utf-8' )
15911591 self .assertRaises (TypeError , urllib .parse .quote , b'foo' , errors = 'strict' )
1592- self .assertRaises (TypeError , urllib .parse .quote , 'abc' , errors = 123 )
1593- self .assertRaises (TypeError , urllib .parse .quote_plus , 'abc' , errors = 123 )
15941592
15951593 def test_quote_ascii_fastpath (self ):
15961594 all_ascii = '' .join (chr (i ) for i in range (128 ))
@@ -1654,55 +1652,17 @@ def test_quote_ascii_fastpath(self):
16541652 self .assertEqual (urllib .parse .quote_plus ('a b/c' , safe = b'/' ), 'a+b/c' )
16551653
16561654 def test_quote_str_subclass (self ):
1657- class PlainSubStr (str ):
1655+ class SubStr (str ):
16581656 pass
16591657
1660- # Empty str subclass is returned as-is; non-empty returns plain str.
1661- empty = PlainSubStr ('' )
1658+ empty = SubStr ('' )
16621659 self .assertIs (urllib .parse .quote (empty ), empty )
16631660 self .assertIs (urllib .parse .quote_plus (empty ), empty )
16641661
1665- for s in (PlainSubStr ('abc' ), PlainSubStr ('a b/c' )):
1666- res_q = urllib .parse .quote (s )
1667- self .assertIs (type (res_q ), str )
1668- self .assertEqual (res_q , urllib .parse .quote (str (s )))
1669- res_qp = urllib .parse .quote_plus (s )
1670- self .assertIs (type (res_qp ), str )
1671- self .assertEqual (res_qp , urllib .parse .quote_plus (str (s )))
1672-
1673- # str subclass overriding encode/rstrip/translate/isascii must bypass
1674- # the fast path and use encode() as before.
1675- class CustomEncodeStr (str ):
1676- def encode (self , encoding = 'utf-8' , errors = 'strict' ):
1677- return b'custom'
1678- def rstrip (self , chars = None ):
1679- raise AssertionError ('rstrip should not be called on str subclass' )
1680- def translate (self , table ):
1681- raise AssertionError ('translate should not be called on str subclass' )
1682- def isascii (self ):
1683- raise AssertionError ('isascii should not be called on str subclass' )
1684-
1685- self .assertEqual (urllib .parse .quote (CustomEncodeStr ('a b' )), 'custom' )
1686- self .assertEqual (urllib .parse .quote_plus (CustomEncodeStr ('a b' )), 'custom' )
1687-
1688- class CustomSafeStr (str ):
1689- def encode (self , encoding = 'utf-8' , errors = 'strict' ):
1690- return b'+ '
1691- def __add__ (self , other ):
1692- return CustomSafeStr (super ().__add__ (other ))
1693-
1694- self .assertEqual (
1695- urllib .parse .quote ('a+b/c' , safe = CustomSafeStr ('/' )),
1696- 'a+b%2Fc' ,
1697- )
1698- self .assertEqual (
1699- urllib .parse .quote_plus ('a+b' , safe = CustomSafeStr ('' )),
1700- 'a+b' ,
1701- )
1702- self .assertEqual (
1703- urllib .parse .quote_plus ('a+b c' , safe = CustomSafeStr ('' )),
1704- 'a+b+c' ,
1705- )
1662+ for s in (SubStr ('abc' ), SubStr ('a b/c' )):
1663+ self .assertEqual (urllib .parse .quote (s ), urllib .parse .quote (str (s )))
1664+ self .assertEqual (urllib .parse .quote_plus (s ),
1665+ urllib .parse .quote_plus (str (s )))
17061666
17071667 def test_issue14072 (self ):
17081668 p1 = urllib .parse .urlsplit ('tel:+31-641044153' )
0 commit comments