<s> """<STR_LIT>""" <EOL> import os , zipfile <EOL> from twisted . test . test_paths import AbstractFilePathTestCase <EOL> from twisted . python . zippath import ZipArchive <EOL> def zipit ( dirname , zfname ) : <EOL> """<STR_LIT>""" <EOL> zf = zipfile . ZipFile ( zfname , "<STR_LIT:w>" ) <EOL> for root , ignored , files , in os . walk ( dirname ) : <EOL> for fname in files : <EOL> fspath = os . path . join ( root , fname ) <EOL> arcpath = os . path . join ( root , fname ) [ len ( dirname ) + <NUM_LIT:1> : ] <EOL> zf . write ( fspath , arcpath ) <EOL> zf . close ( ) <EOL> class ZipFilePathTestCase ( AbstractFilePathTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> AbstractFilePathTestCase . setUp ( self ) <EOL> zipit ( self . cmn , self . cmn + '<STR_LIT>' ) <EOL> self . path = ZipArchive ( self . cmn + '<STR_LIT>' ) <EOL> self . root = self . path <EOL> self . all = [ x . replace ( self . cmn , self . cmn + '<STR_LIT>' ) for x in self . all ] <EOL> def test_zipPathRepr ( self ) : <EOL> """<STR_LIT>""" <EOL> child = self . path . child ( "<STR_LIT:foo>" ) <EOL> pathRepr = "<STR_LIT>" % ( <EOL> os . path . abspath ( self . cmn + "<STR_LIT>" + os . sep + '<STR_LIT:foo>' ) , ) <EOL> self . assertEqual ( repr ( child ) , pathRepr ) <EOL> relativeCommon = self . cmn . replace ( os . getcwd ( ) + os . sep , "<STR_LIT>" , <NUM_LIT:1> ) + "<STR_LIT>" <EOL> relpath = ZipArchive ( relativeCommon ) <EOL> child = relpath . child ( "<STR_LIT:foo>" ) <EOL> self . assertEqual ( repr ( child ) , pathRepr ) <EOL> def test_zipPathReprParentDirSegment ( self ) : <EOL> """<STR_LIT>""" <EOL> child = self . path . child ( "<STR_LIT:foo>" ) . child ( "<STR_LIT:..>" ) . child ( "<STR_LIT:bar>" ) <EOL> pathRepr = "<STR_LIT>" % ( <EOL> self . cmn + "<STR_LIT>" + os . sep . join ( [ "<STR_LIT>" , "<STR_LIT:foo>" , "<STR_LIT:..>" , "<STR_LIT:bar>" ] ) ) <EOL> self . assertEqual ( repr ( child ) , pathRepr ) <EOL> def test_zipPathReprEscaping ( self ) : <EOL> """<STR_LIT>""" <EOL> child = self . path . child ( "<STR_LIT:'>" ) <EOL> path = self . cmn + "<STR_LIT>" + os . sep . join ( [ "<STR_LIT>" , "<STR_LIT:'>" ] ) <EOL> pathRepr = "<STR_LIT>" % ( path . encode ( '<STR_LIT>' ) , ) <EOL> self . assertEqual ( repr ( child ) , pathRepr ) <EOL> def test_zipArchiveRepr ( self ) : <EOL> """<STR_LIT>""" <EOL> pathRepr = '<STR_LIT>' % ( os . path . abspath ( self . cmn + '<STR_LIT>' ) , ) <EOL> self . assertEqual ( repr ( self . path ) , pathRepr ) <EOL> relativeCommon = self . cmn . replace ( os . getcwd ( ) + os . sep , "<STR_LIT>" , <NUM_LIT:1> ) + "<STR_LIT>" <EOL> relpath = ZipArchive ( relativeCommon ) <EOL> self . assertEqual ( repr ( relpath ) , pathRepr ) </s>
