@@ -38,10 +38,6 @@ def get_files(test):
3838 yield f
3939 test .assertFalse (f .closed )
4040
41- def openU (zipfp , fn ):
42- with check_warnings (('' , DeprecationWarning )):
43- return zipfp .open (fn , 'rU' )
44-
4541class AbstractTestsWithSourceFile :
4642 @classmethod
4743 def setUpClass (cls ):
@@ -1035,32 +1031,6 @@ def test_open_via_zip_info(self):
10351031 data += zipfp .read (info )
10361032 self .assertIn (data , {b"foobar" , b"barfoo" })
10371033
1038- def test_universal_deprecation (self ):
1039- f = io .BytesIO ()
1040- with zipfile .ZipFile (f , "w" ) as zipfp :
1041- zipfp .writestr ('spam.txt' , b'ababagalamaga' )
1042-
1043- with zipfile .ZipFile (f , "r" ) as zipfp :
1044- for mode in 'U' , 'rU' :
1045- with self .assertWarns (DeprecationWarning ):
1046- zipopen = zipfp .open ('spam.txt' , mode )
1047- zipopen .close ()
1048-
1049- def test_universal_readaheads (self ):
1050- f = io .BytesIO ()
1051-
1052- data = b'a\r \n ' * 16 * 1024
1053- with zipfile .ZipFile (f , 'w' , zipfile .ZIP_STORED ) as zipfp :
1054- zipfp .writestr (TESTFN , data )
1055-
1056- data2 = b''
1057- with zipfile .ZipFile (f , 'r' ) as zipfp , \
1058- openU (zipfp , TESTFN ) as zipopen :
1059- for line in zipopen :
1060- data2 += line
1061-
1062- self .assertEqual (data , data2 .replace (b'\n ' , b'\r \n ' ))
1063-
10641034 def test_writestr_extended_local_header_issue1202 (self ):
10651035 with zipfile .ZipFile (TESTFN2 , 'w' ) as orig_zip :
10661036 for data in 'abcdefghijklmnop' :
@@ -1268,9 +1238,12 @@ def test_bad_open_mode(self):
12681238 zipf .writestr ("foo.txt" , "O, for a Muse of Fire!" )
12691239
12701240 with zipfile .ZipFile (TESTFN , mode = "r" ) as zipf :
1271- # read the data to make sure the file is there
1241+ # read the data to make sure the file is there
12721242 zipf .read ("foo.txt" )
12731243 self .assertRaises (RuntimeError , zipf .open , "foo.txt" , "q" )
1244+ # universal newlines support is removed
1245+ self .assertRaises (RuntimeError , zipf .open , "foo.txt" , "U" )
1246+ self .assertRaises (RuntimeError , zipf .open , "foo.txt" , "rU" )
12741247
12751248 def test_read0 (self ):
12761249 """Check that calling read(0) on a ZipExtFile object returns an empty
@@ -2011,138 +1984,6 @@ def tearDown(self):
20111984 unlink (TESTFN )
20121985
20131986
2014- class AbstractUniversalNewlineTests :
2015- @classmethod
2016- def setUpClass (cls ):
2017- cls .line_gen = [bytes ("Test of zipfile line %d." % i , "ascii" )
2018- for i in range (FIXEDTEST_SIZE )]
2019- cls .seps = (b'\r ' , b'\r \n ' , b'\n ' )
2020- cls .arcdata = {}
2021- for n , s in enumerate (cls .seps ):
2022- cls .arcdata [s ] = s .join (cls .line_gen ) + s
2023-
2024- def setUp (self ):
2025- self .arcfiles = {}
2026- for n , s in enumerate (self .seps ):
2027- self .arcfiles [s ] = '%s-%d' % (TESTFN , n )
2028- with open (self .arcfiles [s ], "wb" ) as f :
2029- f .write (self .arcdata [s ])
2030-
2031- def make_test_archive (self , f , compression ):
2032- # Create the ZIP archive
2033- with zipfile .ZipFile (f , "w" , compression ) as zipfp :
2034- for fn in self .arcfiles .values ():
2035- zipfp .write (fn , fn )
2036-
2037- def read_test (self , f , compression ):
2038- self .make_test_archive (f , compression )
2039-
2040- # Read the ZIP archive
2041- with zipfile .ZipFile (f , "r" ) as zipfp :
2042- for sep , fn in self .arcfiles .items ():
2043- with openU (zipfp , fn ) as fp :
2044- zipdata = fp .read ()
2045- self .assertEqual (self .arcdata [sep ], zipdata )
2046-
2047- def test_read (self ):
2048- for f in get_files (self ):
2049- self .read_test (f , self .compression )
2050-
2051- def readline_read_test (self , f , compression ):
2052- self .make_test_archive (f , compression )
2053-
2054- # Read the ZIP archive
2055- with zipfile .ZipFile (f , "r" ) as zipfp :
2056- for sep , fn in self .arcfiles .items ():
2057- with openU (zipfp , fn ) as zipopen :
2058- data = b''
2059- while True :
2060- read = zipopen .readline ()
2061- if not read :
2062- break
2063- data += read
2064-
2065- read = zipopen .read (5 )
2066- if not read :
2067- break
2068- data += read
2069-
2070- self .assertEqual (data , self .arcdata [b'\n ' ])
2071-
2072- def test_readline_read (self ):
2073- for f in get_files (self ):
2074- self .readline_read_test (f , self .compression )
2075-
2076- def readline_test (self , f , compression ):
2077- self .make_test_archive (f , compression )
2078-
2079- # Read the ZIP archive
2080- with zipfile .ZipFile (f , "r" ) as zipfp :
2081- for sep , fn in self .arcfiles .items ():
2082- with openU (zipfp , fn ) as zipopen :
2083- for line in self .line_gen :
2084- linedata = zipopen .readline ()
2085- self .assertEqual (linedata , line + b'\n ' )
2086-
2087- def test_readline (self ):
2088- for f in get_files (self ):
2089- self .readline_test (f , self .compression )
2090-
2091- def readlines_test (self , f , compression ):
2092- self .make_test_archive (f , compression )
2093-
2094- # Read the ZIP archive
2095- with zipfile .ZipFile (f , "r" ) as zipfp :
2096- for sep , fn in self .arcfiles .items ():
2097- with openU (zipfp , fn ) as fp :
2098- ziplines = fp .readlines ()
2099- for line , zipline in zip (self .line_gen , ziplines ):
2100- self .assertEqual (zipline , line + b'\n ' )
2101-
2102- def test_readlines (self ):
2103- for f in get_files (self ):
2104- self .readlines_test (f , self .compression )
2105-
2106- def iterlines_test (self , f , compression ):
2107- self .make_test_archive (f , compression )
2108-
2109- # Read the ZIP archive
2110- with zipfile .ZipFile (f , "r" ) as zipfp :
2111- for sep , fn in self .arcfiles .items ():
2112- with openU (zipfp , fn ) as fp :
2113- for line , zipline in zip (self .line_gen , fp ):
2114- self .assertEqual (zipline , line + b'\n ' )
2115-
2116- def test_iterlines (self ):
2117- for f in get_files (self ):
2118- self .iterlines_test (f , self .compression )
2119-
2120- def tearDown (self ):
2121- for sep , fn in self .arcfiles .items ():
2122- unlink (fn )
2123- unlink (TESTFN )
2124- unlink (TESTFN2 )
2125-
2126-
2127- class StoredUniversalNewlineTests (AbstractUniversalNewlineTests ,
2128- unittest .TestCase ):
2129- compression = zipfile .ZIP_STORED
2130-
2131- @requires_zlib
2132- class DeflateUniversalNewlineTests (AbstractUniversalNewlineTests ,
2133- unittest .TestCase ):
2134- compression = zipfile .ZIP_DEFLATED
2135-
2136- @requires_bz2
2137- class Bzip2UniversalNewlineTests (AbstractUniversalNewlineTests ,
2138- unittest .TestCase ):
2139- compression = zipfile .ZIP_BZIP2
2140-
2141- @requires_lzma
2142- class LzmaUniversalNewlineTests (AbstractUniversalNewlineTests ,
2143- unittest .TestCase ):
2144- compression = zipfile .ZIP_LZMA
2145-
21461987class ZipInfoTests (unittest .TestCase ):
21471988 def test_from_file (self ):
21481989 zi = zipfile .ZipInfo .from_file (__file__ )
0 commit comments