@@ -174,27 +174,6 @@ def test_b64encode(self):
174174 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
175175 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==" )
176176
177- eq (base64 .b64encode (b"www.python.org" , wrapcol = 0 ), b'd3d3LnB5dGhvbi5vcmc=' )
178- eq (base64 .b64encode (b"www.python.org" , wrapcol = 8 ), b'd3d3LnB5\n dGhvbi5v\n cmc=' )
179- eq (base64 .b64encode (b"www.python.org" , wrapcol = 76 ), b'd3d3LnB5dGhvbi5vcmc=' )
180- eq (base64 .b64encode (b"www.python.org" , wrapcol = 1 ),
181- b'd\n 3\n d\n 3\n L\n n\n B\n 5\n d\n G\n h\n v\n b\n i\n 5\n v\n c\n m\n c\n =' )
182- eq (base64 .b64encode (b"www.python.org" , wrapcol = sys .maxsize ),
183- b'd3d3LnB5dGhvbi5vcmc=' )
184- if check_impl_detail ():
185- eq (base64 .b64encode (b"www.python.org" , wrapcol = sys .maxsize * 2 ),
186- b'd3d3LnB5dGhvbi5vcmc=' )
187- with self .assertRaises (OverflowError ):
188- base64 .b64encode (b"www.python.org" , wrapcol = 2 ** 1000 )
189- with self .assertRaises (ValueError ):
190- base64 .b64encode (b"www.python.org" , wrapcol = - 8 )
191- with self .assertRaises (TypeError ):
192- base64 .b64encode (b"www.python.org" , wrapcol = 8.0 )
193- with self .assertRaises (TypeError ):
194- base64 .b64encode (b"www.python.org" , wrapcol = '8' )
195- eq (base64 .b64encode (b"" , wrapcol = 0 ), b'' )
196- eq (base64 .b64encode (b"" , wrapcol = 8 ), b'' )
197-
198177 # Test with arbitrary alternative characters
199178 eq (base64 .b64encode (b'\xd3 V\xbe o\xf7 \x1d ' , altchars = b'*$' ), b'01a*b$cd' )
200179 eq (base64 .b64encode (b'\xd3 V\xbe o\xf7 \x1d ' , altchars = bytearray (b'*$' )),
@@ -230,6 +209,31 @@ def test_b64encode(self):
230209 b'\xd3 V\xbe o\xf7 \x1d ' , b'01a-b_cd' )
231210 self .check_encode_type_errors (base64 .urlsafe_b64encode )
232211
212+ def test_b64encode_wrapcol (self ):
213+ eq = self .assertEqual
214+ b = b'www.python.org'
215+ eq (base64 .b64encode (b , wrapcol = 0 ), b'd3d3LnB5dGhvbi5vcmc=' )
216+ eq (base64 .b64encode (b , wrapcol = 8 ), b'd3d3LnB5\n dGhvbi5v\n cmc=' )
217+ eq (base64 .b64encode (b , wrapcol = 76 ), b'd3d3LnB5dGhvbi5vcmc=' )
218+ eq (base64 .b64encode (b , wrapcol = 1 ),
219+ b'd\n 3\n d\n 3\n L\n n\n B\n 5\n d\n G\n h\n v\n b\n i\n 5\n v\n c\n m\n c\n =' )
220+ eq (base64 .b64encode (b , wrapcol = sys .maxsize ), b'd3d3LnB5dGhvbi5vcmc=' )
221+ if check_impl_detail ():
222+ eq (base64 .b64encode (b , wrapcol = sys .maxsize * 2 ),
223+ b'd3d3LnB5dGhvbi5vcmc=' )
224+ with self .assertRaises (OverflowError ):
225+ base64 .b64encode (b , wrapcol = 2 ** 1000 )
226+ with self .assertRaises (ValueError ):
227+ base64 .b64encode (b , wrapcol = - 8 )
228+ with self .assertRaises (TypeError ):
229+ base64 .b64encode (b , wrapcol = 8.0 )
230+ with self .assertRaises (TypeError ):
231+ base64 .b64encode (b , wrapcol = '8' )
232+ with self .assertRaises (TypeError ):
233+ base64 .b64encode (b , wrapcol = None )
234+ eq (base64 .b64encode (b'' , wrapcol = 0 ), b'' )
235+ eq (base64 .b64encode (b'' , wrapcol = 8 ), b'' )
236+
233237 def test_b64decode (self ):
234238 eq = self .assertEqual
235239
@@ -637,18 +641,46 @@ def test_a85encode(self):
637641
638642 self .assertRaises (TypeError , base64 .a85encode , "" )
639643
640- eq (base64 .a85encode (b"www.python.org" , wrapcol = 7 , adobe = False ),
641- b'GB\\ 6`E-\n ZP=Df.1\n GEb>' )
642- eq (base64 .a85encode (b"\0 \0 \0 \0 www.python.org" , wrapcol = 7 , adobe = False ),
643- b'zGB\\ 6`E\n -ZP=Df.\n 1GEb>' )
644- eq (base64 .a85encode (b"www.python.org" , wrapcol = 7 , adobe = True ),
645- b'<~GB\\ 6`\n E-ZP=Df\n .1GEb>\n ~>' )
646-
647644 eq (base64 .a85encode (b' ' * 8 , foldspaces = True , adobe = False ), b'yy' )
648645 eq (base64 .a85encode (b' ' * 7 , foldspaces = True , adobe = False ), b'y+<Vd' )
649646 eq (base64 .a85encode (b' ' * 6 , foldspaces = True , adobe = False ), b'y+<U' )
650647 eq (base64 .a85encode (b' ' * 5 , foldspaces = True , adobe = False ), b'y+9' )
651648
649+ def test_a85encode_wrapcol (self ):
650+ eq = self .assertEqual
651+ b = b'www.python.org'
652+ eq (base64 .a85encode (b , wrapcol = 0 ), b'GB\\ 6`E-ZP=Df.1GEb>' )
653+ eq (base64 .a85encode (b , wrapcol = 7 ), b'GB\\ 6`E-\n ZP=Df.1\n GEb>' )
654+ eq (base64 .a85encode (b"\0 \0 \0 \0 www.python.org" , wrapcol = 7 ),
655+ b'zGB\\ 6`E\n -ZP=Df.\n 1GEb>' )
656+ eq (base64 .a85encode (b , wrapcol = 75 ), b'GB\\ 6`E-ZP=Df.1GEb>' )
657+ eq (base64 .a85encode (b , wrapcol = 1 ),
658+ b'G\n B\n \\ \n 6\n `\n E\n -\n Z\n P\n =\n D\n f\n .\n 1\n G\n E\n b\n >' )
659+ eq (base64 .a85encode (b , wrapcol = 7 , adobe = True ),
660+ b'<~GB\\ 6`\n E-ZP=Df\n .1GEb>\n ~>' )
661+ eq (base64 .a85encode (b , wrapcol = 1 ),
662+ b'G\n B\n \\ \n 6\n `\n E\n -\n Z\n P\n =\n D\n f\n .\n 1\n G\n E\n b\n >' )
663+ eq (base64 .a85encode (b , wrapcol = 1 , adobe = True ),
664+ b'<~\n GB\n \\ 6\n `E\n -Z\n P=\n Df\n .1\n GE\n b>\n ~>' )
665+ eq (base64 .a85encode (b , wrapcol = sys .maxsize ), b'GB\\ 6`E-ZP=Df.1GEb>' )
666+ if check_impl_detail ():
667+ eq (base64 .a85encode (b , wrapcol = 2 ** 1000 ), b'GB\\ 6`E-ZP=Df.1GEb>' )
668+ eq (base64 .a85encode (b , wrapcol = - 7 ),
669+ b'G\n B\n \\ \n 6\n `\n E\n -\n Z\n P\n =\n D\n f\n .\n 1\n G\n E\n b\n >' )
670+ eq (base64 .a85encode (b , wrapcol = - 7 , adobe = True ),
671+ b'<~\n GB\n \\ 6\n `E\n -Z\n P=\n Df\n .1\n GE\n b>\n ~>' )
672+ with self .assertRaises (TypeError ):
673+ base64 .a85encode (b , wrapcol = 7.0 )
674+ with self .assertRaises (TypeError ):
675+ base64 .a85encode (b , wrapcol = '7' )
676+ if check_impl_detail ():
677+ eq (base64 .a85encode (b , wrapcol = None ), b'GB\\ 6`E-ZP=Df.1GEb>' )
678+ eq (base64 .a85encode (b'' , wrapcol = 0 ), b'' )
679+ eq (base64 .a85encode (b'' , wrapcol = 7 ), b'' )
680+ eq (base64 .a85encode (b'' , wrapcol = 1 , adobe = True ), b'<~\n ~>' )
681+ eq (base64 .a85encode (b'' , wrapcol = 3 , adobe = True ), b'<~\n ~>' )
682+ eq (base64 .a85encode (b'' , wrapcol = 4 , adobe = True ), b'<~~>' )
683+
652684 def test_b85encode (self ):
653685 eq = self .assertEqual
654686
0 commit comments