<s> import sys <EOL> import os <EOL> import shutil <EOL> import tempfile <EOL> import StringIO <EOL> import unittest <EOL> import tarfile <EOL> from test import test_support <EOL> try : <EOL> import gzip <EOL> gzip . GzipFile <EOL> except ( ImportError , AttributeError ) : <EOL> gzip = None <EOL> try : <EOL> import bz2 <EOL> except ImportError : <EOL> bz2 = None <EOL> def path ( path ) : <EOL> return test_support . findfile ( path ) <EOL> testtar = path ( "<STR_LIT>" ) <EOL> tempdir = os . path . join ( tempfile . gettempdir ( ) , "<STR_LIT>" + os . extsep + "<STR_LIT>" ) <EOL> tempname = test_support . TESTFN <EOL> membercount = <NUM_LIT:12> <EOL> def tarname ( comp = "<STR_LIT>" ) : <EOL> if not comp : <EOL> return testtar <EOL> return os . path . join ( dirname ( ) , "<STR_LIT>" % ( testtar , os . extsep , comp ) ) <EOL> def dirname ( ) : <EOL> if not os . path . exists ( tempdir ) : <EOL> os . mkdir ( tempdir ) <EOL> return tempdir <EOL> def tmpname ( ) : <EOL> return tempname <EOL> class BaseTest ( unittest . TestCase ) : <EOL> comp = '<STR_LIT>' <EOL> mode = '<STR_LIT:r>' <EOL> sep = '<STR_LIT::>' <EOL> def setUp ( self ) : <EOL> mode = self . mode + self . sep + self . comp <EOL> self . tar = tarfile . open ( tarname ( self . comp ) , mode ) <EOL> def tearDown ( self ) : <EOL> self . tar . close ( ) <EOL> class ReadTest ( BaseTest ) : <EOL> def test ( self ) : <EOL> """<STR_LIT>""" <EOL> members = <NUM_LIT:0> <EOL> for tarinfo in self . tar : <EOL> members += <NUM_LIT:1> <EOL> if not tarinfo . isreg ( ) : <EOL> continue <EOL> f = self . tar . extractfile ( tarinfo ) <EOL> self . assert_ ( len ( f . read ( ) ) == tarinfo . size , <EOL> "<STR_LIT>" ) <EOL> f . close ( ) <EOL> self . assert_ ( members == membercount , <EOL> "<STR_LIT>" ) <EOL> def test_sparse ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . sep != "<STR_LIT:|>" : <EOL> f1 = self . tar . extractfile ( "<STR_LIT>" ) <EOL> f2 = self . tar . extractfile ( "<STR_LIT>" ) <EOL> self . assert_ ( f1 . read ( ) == f2 . read ( ) , <EOL> "<STR_LIT>" ) <EOL> def test_readlines ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . sep != "<STR_LIT:|>" : <EOL> filename = "<STR_LIT>" <EOL> self . tar . extract ( filename , dirname ( ) ) <EOL> f = open ( os . path . join ( dirname ( ) , filename ) , "<STR_LIT>" ) <EOL> lines1 = f . readlines ( ) <EOL> f . close ( ) <EOL> lines2 = self . tar . extractfile ( filename ) . readlines ( ) <EOL> self . assert_ ( lines1 == lines2 , <EOL> "<STR_LIT>" ) <EOL> def test_iter ( self ) : <EOL> if self . sep != "<STR_LIT:|>" : <EOL> filename = "<STR_LIT>" <EOL> self . tar . extract ( filename , dirname ( ) ) <EOL> f = open ( os . path . join ( dirname ( ) , filename ) , "<STR_LIT>" ) <EOL> lines1 = f . readlines ( ) <EOL> f . close ( ) <EOL> lines2 = [ line for line in self . tar . extractfile ( filename ) ] <EOL> self . assert_ ( lines1 == lines2 , <EOL> "<STR_LIT>" ) <EOL> def test_seek ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . sep != "<STR_LIT:|>" : <EOL> filename = "<STR_LIT>" <EOL> self . tar . extract ( filename , dirname ( ) ) <EOL> f = open ( os . path . join ( dirname ( ) , filename ) , "<STR_LIT:rb>" ) <EOL> data = f . read ( ) <EOL> f . close ( ) <EOL> tarinfo = self . tar . getmember ( filename ) <EOL> fobj = self . tar . extractfile ( tarinfo ) <EOL> text = fobj . read ( ) <EOL> fobj . seek ( <NUM_LIT:0> ) <EOL> self . assert_ ( <NUM_LIT:0> == fobj . tell ( ) , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( <NUM_LIT> , <NUM_LIT:0> ) <EOL> self . assert_ ( <NUM_LIT> == fobj . tell ( ) , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( - <NUM_LIT> , <NUM_LIT:1> ) <EOL> self . assert_ ( <NUM_LIT> == fobj . tell ( ) , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( <NUM_LIT> , <NUM_LIT:1> ) <EOL> self . assert_ ( <NUM_LIT> == fobj . tell ( ) , <EOL> "<STR_LIT>" ) <EOL> s = fobj . read ( <NUM_LIT:10> ) <EOL> self . assert_ ( s == data [ <NUM_LIT> : <NUM_LIT> ] , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> self . assert_ ( tarinfo . size == fobj . tell ( ) , <EOL> "<STR_LIT>" ) <EOL> self . assert_ ( fobj . read ( ) == "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( - tarinfo . size , <NUM_LIT:2> ) <EOL> self . assert_ ( <NUM_LIT:0> == fobj . tell ( ) , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( <NUM_LIT> ) <EOL> s1 = fobj . readlines ( ) <EOL> fobj . seek ( <NUM_LIT> ) <EOL> s2 = fobj . readlines ( ) <EOL> self . assert_ ( s1 == s2 , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( <NUM_LIT:0> ) <EOL> self . assert_ ( len ( fobj . readline ( ) ) == fobj . tell ( ) , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( <NUM_LIT> ) <EOL> self . assert_ ( len ( fobj . readline ( ) ) + <NUM_LIT> == fobj . tell ( ) , <EOL> "<STR_LIT>" ) <EOL> fobj . seek ( <NUM_LIT:0> ) <EOL> line = fobj . readline ( ) <EOL> self . assert_ ( fobj . read ( ) == data [ len ( line ) : ] , <EOL> "<STR_LIT>" ) <EOL> fobj . close ( ) <EOL> def test_old_dirtype ( self ) : <EOL> """<STR_LIT>""" <EOL> filename = tmpname ( ) <EOL> tarinfo = tarfile . TarInfo ( "<STR_LIT>" ) <EOL> tarinfo . type = tarfile . REGTYPE <EOL> fobj = open ( filename , "<STR_LIT:w>" ) <EOL> fobj . write ( tarinfo . tobuf ( ) ) <EOL> fobj . close ( ) <EOL> try : <EOL> tar = tarfile . open ( filename ) <EOL> tarinfo = tar . getmembers ( ) [ <NUM_LIT:0> ] <EOL> tar . close ( ) <EOL> self . assert_ ( tarinfo . type == tarfile . DIRTYPE ) <EOL> self . assert_ ( tarinfo . name . endswith ( "<STR_LIT:/>" ) ) <EOL> finally : <EOL> try : <EOL> os . unlink ( filename ) <EOL> except : <EOL> pass <EOL> class ReadStreamTest ( ReadTest ) : <EOL> sep = "<STR_LIT:|>" <EOL> def test ( self ) : <EOL> """<STR_LIT>""" <EOL> ReadTest . test ( self ) <EOL> tarinfo = self . tar . getmembers ( ) [ <NUM_LIT:0> ] <EOL> f = self . tar . extractfile ( tarinfo ) <EOL> self . assertRaises ( tarfile . StreamError , f . read ) <EOL> def test_stream ( self ) : <EOL> """<STR_LIT>""" <EOL> stream = self . tar <EOL> tar = tarfile . open ( tarname ( ) , '<STR_LIT:r>' ) <EOL> while <NUM_LIT:1> : <EOL> t1 = tar . next ( ) <EOL> t2 = stream . next ( ) <EOL> if t1 is None : <EOL> break <EOL> self . assert_ ( t2 is not None , "<STR_LIT>" ) <EOL> if t2 . islnk ( ) or t2 . issym ( ) : <EOL> self . assertRaises ( tarfile . StreamError , stream . extractfile , t2 ) <EOL> continue <EOL> v1 = tar . extractfile ( t1 ) <EOL> v2 = stream . extractfile ( t2 ) <EOL> if v1 is None : <EOL> continue <EOL> self . assert_ ( v2 is not None , "<STR_LIT>" ) <EOL> self . assert_ ( v1 . read ( ) == v2 . read ( ) , "<STR_LIT>" ) <EOL> tar . close ( ) <EOL> stream . close ( ) <EOL> class ReadDetectTest ( ReadTest ) : <EOL> def setUp ( self ) : <EOL> self . tar = tarfile . open ( tarname ( self . comp ) , self . mode ) <EOL> class ReadDetectFileobjTest ( ReadTest ) : <EOL> def setUp ( self ) : <EOL> name = tarname ( self . comp ) <EOL> self . fileobj = open ( name , "<STR_LIT:rb>" ) <EOL> self . tar = tarfile . open ( name , mode = self . mode , <EOL> fileobj = self . fileobj ) <EOL> def tearDown ( self ) : <EOL> self . tar . close ( ) <EOL> self . fileobj . close ( ) <EOL> class ReadAsteriskTest ( ReadTest ) : <EOL> def setUp ( self ) : <EOL> mode = self . mode + self . sep + "<STR_LIT:*>" <EOL> self . tar = tarfile . open ( tarname ( self . comp ) , mode ) <EOL> class ReadStreamAsteriskTest ( ReadStreamTest ) : <EOL> def setUp ( self ) : <EOL> mode = self . mode + self . sep + "<STR_LIT:*>" <EOL> self . tar = tarfile . open ( tarname ( self . comp ) , mode ) <EOL> class WriteTest ( BaseTest ) : <EOL> mode = '<STR_LIT:w>' <EOL> def setUp ( self ) : <EOL> mode = self . mode + self . sep + self . comp <EOL> self . src = tarfile . open ( tarname ( self . comp ) , '<STR_LIT:r>' ) <EOL> self . dstname = tmpname ( ) <EOL> self . dst = tarfile . open ( self . dstname , mode ) <EOL> def tearDown ( self ) : <EOL> self . src . close ( ) <EOL> self . dst . close ( ) <EOL> def test_posix ( self ) : <EOL> self . dst . posix = <NUM_LIT:1> <EOL> self . _test ( ) <EOL> def test_nonposix ( self ) : <EOL> self . dst . posix = <NUM_LIT:0> <EOL> self . _test ( ) <EOL> def test_small ( self ) : <EOL> self . dst . add ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> self . dst . close ( ) <EOL> self . assertNotEqual ( os . stat ( self . dstname ) . st_size , <NUM_LIT:0> ) <EOL> def _test ( self ) : <EOL> for tarinfo in self . src : <EOL> if not tarinfo . isreg ( ) : <EOL> continue <EOL> f = self . src . extractfile ( tarinfo ) <EOL> if self . dst . posix and len ( tarinfo . name ) > tarfile . LENGTH_NAME and "<STR_LIT:/>" not in tarinfo . name : <EOL> self . assertRaises ( ValueError , self . dst . addfile , <EOL> tarinfo , f ) <EOL> else : <EOL> self . dst . addfile ( tarinfo , f ) <EOL> def test_add_self ( self ) : <EOL> dstname = os . path . abspath ( self . dstname ) <EOL> self . assertEqual ( self . dst . name , dstname , "<STR_LIT>" ) <EOL> self . dst . add ( dstname ) <EOL> self . assertEqual ( self . dst . getnames ( ) , [ ] , "<STR_LIT>" ) <EOL> cwd = os . getcwd ( ) <EOL> os . chdir ( dirname ( ) ) <EOL> self . dst . add ( dstname ) <EOL> os . chdir ( cwd ) <EOL> self . assertEqual ( self . dst . getnames ( ) , [ ] , "<STR_LIT>" ) <EOL> class Write100Test ( BaseTest ) : <EOL> def setUp ( self ) : <EOL> self . name = "<STR_LIT>" <EOL> self . name += "<STR_LIT>" <EOL> self . tar = tarfile . open ( tmpname ( ) , "<STR_LIT:w>" ) <EOL> t = tarfile . TarInfo ( self . name ) <EOL> self . tar . addfile ( t ) <EOL> self . tar . close ( ) <EOL> self . tar = tarfile . open ( tmpname ( ) ) <EOL> def tearDown ( self ) : <EOL> self . tar . close ( ) <EOL> def test ( self ) : <EOL> self . assertEqual ( self . tar . getnames ( ) [ <NUM_LIT:0> ] , self . name , <EOL> "<STR_LIT>" ) <EOL> class WriteSize0Test ( BaseTest ) : <EOL> mode = '<STR_LIT:w>' <EOL> def setUp ( self ) : <EOL> self . tmpdir = dirname ( ) <EOL> self . dstname = tmpname ( ) <EOL> self . dst = tarfile . open ( self . dstname , "<STR_LIT:w>" ) <EOL> def tearDown ( self ) : <EOL> self . dst . close ( ) <EOL> def test_file ( self ) : <EOL> path = os . path . join ( self . tmpdir , "<STR_LIT:file>" ) <EOL> f = open ( path , "<STR_LIT:w>" ) <EOL> f . close ( ) <EOL> tarinfo = self . dst . gettarinfo ( path ) <EOL> self . assertEqual ( tarinfo . size , <NUM_LIT:0> ) <EOL> f = open ( path , "<STR_LIT:w>" ) <EOL> f . write ( "<STR_LIT>" ) <EOL> f . close ( ) <EOL> tarinfo = self . dst . gettarinfo ( path ) <EOL> self . assertEqual ( tarinfo . size , <NUM_LIT:3> ) <EOL> def test_directory ( self ) : <EOL> path = os . path . join ( self . tmpdir , "<STR_LIT>" ) <EOL> if os . path . exists ( path ) : <EOL> shutil . rmtree ( path ) <EOL> os . mkdir ( path ) <EOL> tarinfo = self . dst . gettarinfo ( path ) <EOL> self . assertEqual ( tarinfo . size , <NUM_LIT:0> ) <EOL> def test_symlink ( self ) : <EOL> if hasattr ( os , "<STR_LIT>" ) : <EOL> path = os . path . join ( self . tmpdir , "<STR_LIT>" ) <EOL> os . symlink ( "<STR_LIT>" , path ) <EOL> tarinfo = self . dst . gettarinfo ( path ) <EOL> self . assertEqual ( tarinfo . size , <NUM_LIT:0> ) <EOL> class WriteStreamTest ( WriteTest ) : <EOL> sep = '<STR_LIT:|>' <EOL> def test_padding ( self ) : <EOL> self . dst . close ( ) <EOL> if self . comp == "<STR_LIT>" : <EOL> f = gzip . GzipFile ( self . dstname ) <EOL> s = f . read ( ) <EOL> f . close ( ) <EOL> elif self . comp == "<STR_LIT>" : <EOL> f = bz2 . BZ2Decompressor ( ) <EOL> s = file ( self . dstname ) . read ( ) <EOL> s = f . decompress ( s ) <EOL> self . assertEqual ( len ( f . unused_data ) , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> else : <EOL> f = file ( self . dstname ) <EOL> s = f . read ( ) <EOL> f . close ( ) <EOL> self . assertEqual ( s . count ( "<STR_LIT>" ) , tarfile . RECORDSIZE , <EOL> "<STR_LIT>" ) <EOL> class WriteGNULongTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def _length ( self , s ) : <EOL> blocks , remainder = divmod ( len ( s ) + <NUM_LIT:1> , <NUM_LIT> ) <EOL> if remainder : <EOL> blocks += <NUM_LIT:1> <EOL> return blocks * <NUM_LIT> <EOL> def _calc_size ( self , name , link = None ) : <EOL> count = <NUM_LIT> <EOL> if len ( name ) > tarfile . LENGTH_NAME : <EOL> count += <NUM_LIT> <EOL> count += self . _length ( name ) <EOL> if link is not None and len ( link ) > tarfile . LENGTH_LINK : <EOL> count += <NUM_LIT> <EOL> count += self . _length ( link ) <EOL> return count <EOL> def _test ( self , name , link = None ) : <EOL> tarinfo = tarfile . TarInfo ( name ) <EOL> if link : <EOL> tarinfo . linkname = link <EOL> tarinfo . type = tarfile . LNKTYPE <EOL> tar = tarfile . open ( tmpname ( ) , "<STR_LIT:w>" ) <EOL> tar . posix = False <EOL> tar . addfile ( tarinfo ) <EOL> v1 = self . _calc_size ( name , link ) <EOL> v2 = tar . offset <EOL> self . assertEqual ( v1 , v2 , "<STR_LIT>" ) <EOL> tar . close ( ) <EOL> tar = tarfile . open ( tmpname ( ) ) <EOL> member = tar . next ( ) <EOL> self . failIf ( member is None , "<STR_LIT>" ) <EOL> self . assert_ ( tarinfo . name == member . name and tarinfo . linkname == member . linkname , "<STR_LIT>" ) <EOL> tar . close ( ) <EOL> def test_longname_1023 ( self ) : <EOL> self . _test ( ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> def test_longname_1024 ( self ) : <EOL> self . _test ( ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> def test_longname_1025 ( self ) : <EOL> self . _test ( ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> def test_longlink_1023 ( self ) : <EOL> self . _test ( "<STR_LIT:name>" , ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> def test_longlink_1024 ( self ) : <EOL> self . _test ( "<STR_LIT:name>" , ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> def test_longlink_1025 ( self ) : <EOL> self . _test ( "<STR_LIT:name>" , ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> def test_longnamelink_1023 ( self ) : <EOL> self . _test ( ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" , <EOL> ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> def test_longnamelink_1024 ( self ) : <EOL> self . _test ( ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" , <EOL> ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> def test_longnamelink_1025 ( self ) : <EOL> self . _test ( ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" , <EOL> ( "<STR_LIT>" * <NUM_LIT> ) + "<STR_LIT>" ) <EOL> class ReadGNULongTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . tar = tarfile . open ( tarname ( ) ) <EOL> def tearDown ( self ) : <EOL> self . tar . close ( ) <EOL> def test_1471427 ( self ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" * <NUM_LIT:20> + "<STR_LIT>" <EOL> try : <EOL> tarinfo = self . tar . getmember ( name ) <EOL> except KeyError : <EOL> tarinfo = None <EOL> self . assert_ ( tarinfo is not None , "<STR_LIT>" ) <EOL> self . assert_ ( tarinfo . type != tarfile . DIRTYPE , "<STR_LIT>" ) <EOL> def test_read_name ( self ) : <EOL> name = ( "<STR_LIT>" * <NUM_LIT:10> ) [ : <NUM_LIT> ] <EOL> try : <EOL> tarinfo = self . tar . getmember ( name ) <EOL> except KeyError : <EOL> tarinfo = None <EOL> self . assert_ ( tarinfo is not None , "<STR_LIT>" ) <EOL> def test_read_link ( self ) : <EOL> link = ( "<STR_LIT>" * <NUM_LIT:10> ) [ : <NUM_LIT> ] <EOL> name = ( "<STR_LIT>" * <NUM_LIT:10> ) [ : <NUM_LIT> ] <EOL> try : <EOL> tarinfo = self . tar . getmember ( link ) <EOL> except KeyError : <EOL> tarinfo = None <EOL> self . assert_ ( tarinfo is not None , "<STR_LIT>" ) <EOL> self . assert_ ( tarinfo . linkname == name , "<STR_LIT>" ) <EOL> def test_truncated_longname ( self ) : <EOL> f = open ( tarname ( ) ) <EOL> fobj = StringIO . StringIO ( f . read ( <NUM_LIT> ) ) <EOL> f . close ( ) <EOL> tar = tarfile . open ( name = "<STR_LIT>" , fileobj = fobj ) <EOL> self . assert_ ( len ( tar . getmembers ( ) ) == <NUM_LIT:0> , "<STR_LIT>" ) <EOL> tar . close ( ) <EOL> class ExtractHardlinkTest ( BaseTest ) : <EOL> def test_hardlink ( self ) : <EOL> """<STR_LIT>""" <EOL> self . tar . errorlevel = <NUM_LIT:1> <EOL> self . tar . extract ( "<STR_LIT>" , dirname ( ) ) <EOL> try : <EOL> self . tar . extract ( "<STR_LIT>" , dirname ( ) ) <EOL> except EnvironmentError , e : <EOL> import errno <EOL> if e . errno == errno . ENOENT : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class CreateHardlinkTest ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . tar = tarfile . open ( tmpname ( ) , "<STR_LIT:w>" ) <EOL> self . foo = os . path . join ( dirname ( ) , "<STR_LIT:foo>" ) <EOL> self . bar = os . path . join ( dirname ( ) , "<STR_LIT:bar>" ) <EOL> if os . path . exists ( self . foo ) : <EOL> os . remove ( self . foo ) <EOL> if os . path . exists ( self . bar ) : <EOL> os . remove ( self . bar ) <EOL> f = open ( self . foo , "<STR_LIT:w>" ) <EOL> f . write ( "<STR_LIT:foo>" ) <EOL> f . close ( ) <EOL> self . tar . add ( self . foo ) <EOL> def test_add_twice ( self ) : <EOL> tarinfo = self . tar . gettarinfo ( self . foo ) <EOL> self . assertEqual ( tarinfo . type , tarfile . REGTYPE , <EOL> "<STR_LIT>" ) <EOL> def test_add_hardlink ( self ) : <EOL> os . link ( self . foo , self . bar ) <EOL> tarinfo = self . tar . gettarinfo ( self . foo ) <EOL> self . assertEqual ( tarinfo . type , tarfile . LNKTYPE , <EOL> "<STR_LIT>" ) <EOL> tarinfo = self . tar . gettarinfo ( self . bar ) <EOL> self . assertEqual ( tarinfo . type , tarfile . LNKTYPE , <EOL> "<STR_LIT>" ) <EOL> def test_dereference_hardlink ( self ) : <EOL> self . tar . dereference = True <EOL> os . link ( self . foo , self . bar ) <EOL> tarinfo = self . tar . gettarinfo ( self . bar ) <EOL> self . assertEqual ( tarinfo . type , tarfile . REGTYPE , <EOL> "<STR_LIT>" ) <EOL> class ReadTestGzip ( ReadTest ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadStreamTestGzip ( ReadStreamTest ) : <EOL> comp = "<STR_LIT>" <EOL> class WriteTestGzip ( WriteTest ) : <EOL> comp = "<STR_LIT>" <EOL> class WriteStreamTestGzip ( WriteStreamTest ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadDetectTestGzip ( ReadDetectTest ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadDetectFileobjTestGzip ( ReadDetectFileobjTest ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadAsteriskTestGzip ( ReadAsteriskTest ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadStreamAsteriskTestGzip ( ReadStreamAsteriskTest ) : <EOL> comp = "<STR_LIT>" <EOL> class FileModeTest ( unittest . TestCase ) : <EOL> def test_modes ( self ) : <EOL> self . assertEqual ( tarfile . filemode ( <NUM_LIT:0> <NUM_LIT> ) , '<STR_LIT>' ) <EOL> self . assertEqual ( tarfile . filemode ( <NUM_LIT:0> <NUM_LIT> ) , '<STR_LIT>' ) <EOL> class OpenFileobjTest ( BaseTest ) : <EOL> def test_opener ( self ) : <EOL> fobj = StringIO . StringIO ( "<STR_LIT>" ) <EOL> try : <EOL> tarfile . open ( "<STR_LIT>" , "<STR_LIT:r>" , fileobj = fobj ) <EOL> except tarfile . ReadError : <EOL> self . assertEqual ( fobj . tell ( ) , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> if bz2 : <EOL> class ReadTestBzip2 ( ReadTestGzip ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadStreamTestBzip2 ( ReadStreamTestGzip ) : <EOL> comp = "<STR_LIT>" <EOL> class WriteTestBzip2 ( WriteTest ) : <EOL> comp = "<STR_LIT>" <EOL> class WriteStreamTestBzip2 ( WriteStreamTestGzip ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadDetectTestBzip2 ( ReadDetectTest ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadDetectFileobjTestBzip2 ( ReadDetectFileobjTest ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadAsteriskTestBzip2 ( ReadAsteriskTest ) : <EOL> comp = "<STR_LIT>" <EOL> class ReadStreamAsteriskTestBzip2 ( ReadStreamAsteriskTest ) : <EOL> comp = "<STR_LIT>" <EOL> if not gzip : <EOL> del ReadTestGzip <EOL> del ReadStreamTestGzip <EOL> del WriteTestGzip <EOL> del WriteStreamTestGzip <EOL> def test_main ( ) : <EOL> f = open ( tarname ( ) , "<STR_LIT:rb>" ) <EOL> fguts = f . read ( ) <EOL> f . close ( ) <EOL> if gzip : <EOL> tar = gzip . open ( tarname ( "<STR_LIT>" ) , "<STR_LIT:wb>" ) <EOL> tar . write ( fguts ) <EOL> tar . close ( ) <EOL> if bz2 : <EOL> tar = bz2 . BZ2File ( tarname ( "<STR_LIT>" ) , "<STR_LIT:wb>" ) <EOL> tar . write ( fguts ) <EOL> tar . close ( ) <EOL> tests = [ <EOL> FileModeTest , <EOL> OpenFileobjTest , <EOL> ReadTest , <EOL> ReadStreamTest , <EOL> ReadDetectTest , <EOL> ReadDetectFileobjTest , <EOL> ReadAsteriskTest , <EOL> ReadStreamAsteriskTest , <EOL> WriteTest , <EOL> Write100Test , <EOL> WriteSize0Test , <EOL> WriteStreamTest , <EOL> WriteGNULongTest , <EOL> ReadGNULongTest , <EOL> ] <EOL> if hasattr ( os , "<STR_LIT>" ) : <EOL> tests . append ( ExtractHardlinkTest ) <EOL> tests . append ( CreateHardlinkTest ) <EOL> if gzip : <EOL> tests . extend ( [ <EOL> ReadTestGzip , ReadStreamTestGzip , <EOL> WriteTestGzip , WriteStreamTestGzip , <EOL> ReadDetectTestGzip , ReadDetectFileobjTestGzip , <EOL> ReadAsteriskTestGzip , ReadStreamAsteriskTestGzip <EOL> ] ) <EOL> if bz2 : <EOL> tests . extend ( [ <EOL> ReadTestBzip2 , ReadStreamTestBzip2 , <EOL> WriteTestBzip2 , WriteStreamTestBzip2 , <EOL> ReadDetectTestBzip2 , ReadDetectFileobjTestBzip2 , <EOL> ReadAsteriskTestBzip2 , ReadStreamAsteriskTestBzip2 <EOL> ] ) <EOL> try : <EOL> test_support . run_unittest ( * tests ) <EOL> finally : <EOL> if gzip : <EOL> os . remove ( tarname ( "<STR_LIT>" ) ) <EOL> if bz2 : <EOL> os . remove ( tarname ( "<STR_LIT>" ) ) <EOL> if os . path . exists ( dirname ( ) ) : <EOL> shutil . rmtree ( dirname ( ) ) <EOL> if os . path . exists ( tmpname ( ) ) : <EOL> os . remove ( tmpname ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
