<s> import os , sys <EOL> import UnRAR2 <EOL> from UnRAR2 . rar_exceptions import * <EOL> def cleanup ( dir = '<STR_LIT:test>' ) : <EOL> for path , dirs , files in os . walk ( dir ) : <EOL> for fn in files : <EOL> os . remove ( os . path . join ( path , fn ) ) <EOL> for dir in dirs : <EOL> os . removedirs ( os . path . join ( path , dir ) ) <EOL> cleanup ( ) <EOL> rarc = UnRAR2 . RarFile ( '<STR_LIT>' ) <EOL> rarc . infolist ( ) <EOL> assert rarc . comment == "<STR_LIT>" <EOL> for info in rarc . infoiter ( ) : <EOL> saveinfo = info <EOL> assert ( str ( info ) == """<STR_LIT>""" ) <EOL> break <EOL> rarc . extract ( ) <EOL> assert os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> assert os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> del rarc <EOL> assert ( str ( saveinfo ) == """<STR_LIT>""" ) <EOL> cleanup ( ) <EOL> cleanup ( ) <EOL> UnRAR2 . RarFile ( '<STR_LIT>' ) . extract ( ) <EOL> assert os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> assert os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> cleanup ( ) <EOL> cleanup ( ) <EOL> UnRAR2 . RarFile ( '<STR_LIT>' ) . extract ( '<STR_LIT>' ) <EOL> assert os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> assert not os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> cleanup ( ) <EOL> cleanup ( ) <EOL> archive = UnRAR2 . RarFile ( '<STR_LIT>' ) <EOL> assert archive . comment == '<STR_LIT>' <EOL> archive . extract ( lambda rarinfo : rarinfo . size <= <NUM_LIT> ) <EOL> for rarinfo in archive . infoiter ( ) : <EOL> if rarinfo . size <= <NUM_LIT> and not rarinfo . isdir : <EOL> assert rarinfo . size == os . stat ( rarinfo . filename ) . st_size <EOL> assert file ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' , '<STR_LIT>' ) . read ( ) == '<STR_LIT>' <EOL> assert not os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> cleanup ( ) <EOL> cleanup ( '<STR_LIT>' ) <EOL> archive = UnRAR2 . RarFile ( '<STR_LIT>' ) <EOL> archive . extract ( '<STR_LIT>' , '<STR_LIT>' , False ) <EOL> assert os . path . exists ( '<STR_LIT>' + os . sep + '<STR_LIT>' ) <EOL> cleanup ( '<STR_LIT>' ) <EOL> cleanup ( ) <EOL> archive = UnRAR2 . RarFile ( '<STR_LIT>' ) <EOL> entries = UnRAR2 . RarFile ( '<STR_LIT>' ) . read_files ( '<STR_LIT>' ) <EOL> assert len ( entries ) == <NUM_LIT:1> <EOL> assert entries [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . filename . endswith ( '<STR_LIT>' ) <EOL> assert entries [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> cleanup ( ) <EOL> fo = open ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' , "<STR_LIT>" ) <EOL> fo . write ( "<STR_LIT>" ) <EOL> fo . close ( ) <EOL> UnRAR2 . RarFile ( '<STR_LIT>' ) . extract ( '<STR_LIT>' ) <EOL> assert open ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' , "<STR_LIT>" ) . read ( ) != "<STR_LIT>" <EOL> cleanup ( ) <EOL> cleanup ( ) <EOL> fo = open ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' , "<STR_LIT>" ) <EOL> fo . write ( "<STR_LIT>" ) <EOL> fo . close ( ) <EOL> UnRAR2 . RarFile ( '<STR_LIT>' ) . extract ( '<STR_LIT>' , overwrite = False ) <EOL> assert open ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' , "<STR_LIT>" ) . read ( ) == "<STR_LIT>" <EOL> cleanup ( ) <EOL> list ( UnRAR2 . RarFile ( '<STR_LIT>' ) . infoiter ( ) ) <EOL> cleanup ( ) <EOL> rarc = UnRAR2 . RarFile ( '<STR_LIT>' , password = "<STR_LIT>" ) <EOL> rarc . extract ( ) <EOL> assert os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> cleanup ( ) <EOL> errored = False <EOL> try : <EOL> UnRAR2 . RarFile ( '<STR_LIT>' , password = "<STR_LIT>" ) . extract ( ) <EOL> except IncorrectRARPassword : <EOL> errored = True <EOL> assert not os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> assert errored <EOL> cleanup ( ) <EOL> cleanup ( ) <EOL> UnRAR2 . RarFile ( '<STR_LIT>' , password = "<STR_LIT>" ) . extract ( ) <EOL> assert os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> cleanup ( ) <EOL> errored = False <EOL> try : <EOL> UnRAR2 . RarFile ( '<STR_LIT>' , password = "<STR_LIT>" ) . extract ( ) <EOL> except IncorrectRARPassword : <EOL> errored = True <EOL> assert not os . path . exists ( '<STR_LIT:test>' + os . sep + '<STR_LIT>' ) <EOL> assert errored <EOL> cleanup ( ) <EOL> import doctest <EOL> doctest . testmod ( UnRAR2 ) <EOL> import pydoc <EOL> pydoc . writedoc ( UnRAR2 ) <EOL> try : <EOL> os . remove ( '<STR_LIT>' ) <EOL> except : <EOL> pass </s>
