+
    Dfj//                         R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHtHt ^ RI	H
t
  ! R R4      t ! R R]]
P                  4      t ! R	 R
]]
P                  4      t ! R R]
P                  4      tR# )z'
Tests for L{twisted.python.zipstream}
N)md5)filepath	zipstream)unittestc                   `   a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tRtV tR# )FileEntryMixinz7
File entry classes should behave as file-like objects
c                "   V P                  4       p\        P                  ! VRV P                  4      ;_uu_ 4       pVP	                  RV4       RRR4       \
        P                  ! VR4      pVP                  R4      #   + '       g   i     L8; i)z&
Return an appropriate zip file entry
wcontentNr)mktempzipfileZipFilecompressionwritestrr   ChunkingZipFilereadfile)selfcontentsfilenamezs   &&  D/usr/lib/python3/dist-packages/twisted/python/test/test_zipstream.pygetFileEntryFileEntryMixin.getFileEntry   sg     ;;=__XsD,<,<==JJy(+ >%%h4zz)$$ >=s   A>>B	c                    V P                  R4      ;_uu_ 4       pV P                  VP                  4       4       RRR4       R#   + '       g   i     R# ; i)z;
zip files should not be ttys, so isatty() should be false
 N)r   assertFalseisattyr   	fileEntrys   & r   test_isattyFileEntryMixin.test_isatty    s=     r""iY--/0 #"""s    AA	c                    V P                  R4      ;_uu_ 4       pV P                  VP                  4       RRR4       V P                  XP                  4       R#   + '       g   i     L-; i)zL
The C{closed} attribute should reflect whether C{close()} has been
called.
r   N)r   r   closed
assertTruer   s   & r   test_closedFileEntryMixin.test_closed'   sK    
 r""iY--. #	(() #"s   AA+	c                2   V P                  R4      ;_uu_ 4       pV P                  VP                  4       R4       V P                  VP                  4       R4       V P                  VP                  4       R4       RRR4       R#   + '       g   i     R# ; i)zS
C{readline()} should mirror L{file.readline} and return up to a single
delimiter.
s   hoho
hos   hoho
   ho    N)r   assertEqualreadliner   s   & r   test_readlineFileEntryMixin.test_readline0   sq    
 {++yY//19=Y//159Y//137 ,+++   A!BB	c                2   V P                  R4      ;_uu_ 4       pV P                  VP                  4       R4       V P                  VP                  4       R4       V P                  \        VP                  4       RRR4       R#   + '       g   i     R# ; i)zF
Zip file entries should implement the iterator protocol as files do.
s   ho
hoho   ho
s   hohoN)r   r*   nextassertRaisesStopIterationr   s   & r   	test_nextFileEntryMixin.test_next:   sh     {++yY^^-w7Y^^-w7mY^^< ,+++r.   c                    V P                  R4      ;_uu_ 4       pV P                  VP                  4       . RO4       RRR4       R#   + '       g   i     R# ; i)z7
C{readlines()} should return a list of all the lines.
s   ho
ho
hoN)r0   r0   r(   )r   r*   	readlinesr   s   & r   test_readlinesFileEntryMixin.test_readlinesC   s@     }--Y0024MN .---s   #AA	c                    V P                  R4      ;_uu_ 4       pV P                  \        V4      V4       V P                  VP                  4       V4       RRR4       R#   + '       g   i     R# ; i)z:
C{__iter__()} and C{xreadlines()} should return C{self}.
r   N)r   assertIsiter
xreadlinesr   s   & r   test_iterationFileEntryMixin.test_iterationJ   sO     r""iMM$y/95MM)..0)< #"""s   <A  A1	c                    RpV P                  V4      ;_uu_ 4       pV P                  VP                  4       V4       RRR4       R#   + '       g   i     R# ; i)z)
C{.read()} should read the entire file.
s   Hello, world!N)r   r*   readr   r   entrys   &  r   test_readWholeFileEntryMixin.test_readWholeR   sA     $x((EUZZ\84 )(((s   !AA	c                    RpV P                  V4      ;_uu_ 4       pVP                  ^4      pVP                  ^4      pRRR4       V P                  XR4       V P                  XR4       R#   + '       g   i     L6; i)z4
C{.read(num)} should read num bytes from the file.

0123456789Ns   0123s   456789)r   rA   r*   )r   r   rC   onetwos   &    r   test_readPartialFileEntryMixin.test_readPartialZ   sf      x((E**Q-C**S/C ) 	g&i(	 )(s   #A--A=	c                :   RpV P                  V4      ;_uu_ 4       pVP                  ^4       V P                  VP                  4       ^4       VP                  ^4       V P                  VP                  4       ^4       RRR4       R#   + '       g   i     R# ; i)zJ
C{.tell()} should return the number of bytes that have been read so
far.
Ndxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r   rA   r*   tellrB   s   &  r   	test_tellFileEntryMixin.test_telle   sm    
 x((EJJqMUZZ\1-JJqMUZZ\1-	 )(((s   A#B		B	 N)__name__
__module____qualname____firstlineno____doc__r   r    r%   r,   r4   r8   r>   rD   rJ   rO   __static_attributes____classdictcell____classdict__s   @r   r   r      sB     %1*8=O=5	)
. 
.r)   r   c                   2    ] tR t^rtRt]P                  tRtR# )DeflatedZipFileEntryTestsz*
DeflatedZipFileEntry should be file-like
rQ   N)	rR   rS   rT   rU   rV   r   ZIP_DEFLATEDr   rW   rQ   r)   r   r\   r\   r   s     &&Kr)   r\   c                   2    ] tR t^ztRt]P                  tRtR# )ZipFileEntryTestsz"
ZipFileEntry should be file-like
rQ   N)	rR   rS   rT   rU   rV   r   
ZIP_STOREDr   rW   rQ   r)   r   r_   r_   z   s     $$Kr)   r_   c                   |   a  ] tR t^t o RtR tRR ltR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tRtV tR# )ZipstreamTestsz$
Tests for twisted.python.zipstream
c                    \         P                  ! V P                  4       4      V n        V P                  P	                  4        V P                  P                  R4      V n        V P                  P	                  4        R# )zb
Creates junk data that can be compressed and a test directory for any
files that will be created
unzippedN)r   FilePathr   testdirmakedirschildunzipdirr   s   &r   setUpZipstreamTests.setUp   sR    
  ((7**:6 r)   c                X   V P                   P                  R4      P                  p\        P                  ! VR4      ;_uu_ 4       p\        V4       F9  w  rV\        V4      pV'       d   VR,           V,           pVP                  Wv4       K;  	  RRR4       V#   + '       g   i     T# ; i)z
Makes a zip file archive containing len(contents) files.  Contents
should be a list of strings, each string being the content of one file.
zzipfile.zipr	   /N)rf   rh   pathr   r   	enumeratestrr   )r   r   	directory
zpfilenamezpfileir
   r   s   &&&     r   makeZipFileZipstreamTests.makeZipFile   s    
 \\''6;;
__Z--'1
q6(39H2	 2 .  .- s   A	BB)	c                    \         P                  ! V P                  4       R4      ;_uu_ 4       pV P                  \        VP
                  R4       RRR4       R#   + '       g   i     R# ; i)zh
A ChunkingZipFile opened in write-mode should not allow .readfile(),
and raise a RuntimeError instead.
r	   	somethingN)r   r   r   r2   RuntimeErrorr   r   czfs   & r   test_invalidModeZipstreamTests.test_invalidMode   sD    
 &&t{{}c::clCLL+F ;:::s   "AA+	c                    \         P                  ! V P                  R.4      R4      pVP                  4        V P	                  \
        VP                  R4       R# )zV
A closed ChunkingZipFile should raise a L{RuntimeError} when
.readfile() is invoked.
ry   r   N)r   r   rv   closer2   rz   r   r{   s   & r   test_closedArchive!ZipstreamTests.test_closedArchive   sB    
 ''(8(8+(GM		,kBr)   c           	        V P                  RR.4      p\        P                  ! VR4      ;_uu_ 4       pVP                  R4      P                  pRRR4       \        VR4      ;_uu_ 4       pVP                  X^ 4       VP                  R	4       RRR4       \        P                  ! V4      ;_uu_ 4       pV P                  \        P                  VP                  R4       VP                  R4      ;_uu_ 4       pV P                  VP                  4       R4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     L; i  + '       g   i     L@; i  + '       g   i     R# ; i)
z
A zipfile entry with the wrong magic number should raise BadZipFile for
readfile(), but that should not affect other files in the archive.
ztest contentszmore contentsr   0Nr+b1   more contentss   0000)rv   r   r   getinfoheader_offsetopenseekwriter   r   r2   
BadZipFiler   r*   rA   )r   fnzf
zeroOffsetscribbler|   zfes   &      r   test_invalidHeader!ZipstreamTests.test_invalidHeader   s    
 @A__R%%C66J & "e__MM*a(NN8$  &&r**cg00#,,Dc""c  -=> # +* &% _
 #" +**s<   D-+$E 5AE&:!E	E&-D=	 E	E#E&&E7	c           	        V P                  RR.4      p\        P                  ! VR4      ;_uu_ 4       pVP                  R4      pRVn        RRR4       \        VR4      ;_uu_ 4       pVP                  XP                  ^ 4       VP                  VP                  4       4       RRR4       \        P                  ! V4      ;_uu_ 4       pV P                  \        P                  VP                  R4       VP                  R4      ;_uu_ 4       pV P                  VP!                  4       R4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     L; i  + '       g   i     L@; i  + '       g   i     R# ; i)	zk
A zipfile entry with a different filename than is found in the central
directory should raise BadZipFile.
s   test contentsr   r   r   znot zeroNr   r   )rv   r   r   r   r   r   r   r   r   
FileHeaderr   r   r2   r   r   r*   rA   )r   r   r   infor   r|   r   s   &      r   test_filenameMismatch$ZipstreamTests.test_filenameMismatch   s   
 /1ABC__R%%::c?D&DM & "e__MM$,,a0NN4??,-  &&r**cg00#,,Dc""c  -=> # +* &% _ #" +**s<   E(<E
AE;!E(	0E;E	E%	(E83E;;F	c                   V P                  4       p\        P                  ! VR4      ;_uu_ 4       p\        P                  ! R4      pVP	                  VR4       RVn        RRR4       \        P                  ! V4      ;_uu_ 4       pV P                  \        P                  VP                  R4       RRR4       R#   + '       g   i     Ld; i  + '       g   i     R# ; i)zY
A zipfile which describes an unsupported compression mechanism should
raise BadZipFile.
r	   r   z	some datai  N)r   r   r   ZipInfor   compress_typer   r   r2   r   r   )r   r   r   zir|   s   &    r   test_unsupportedCompression*ZipstreamTests.test_unsupportedCompression   s    
 [[]__R%%%BKKK(  $B & &&r**cg00#,,D +* &% +**s   0B<,C<C	C 	c           	     h   V P                  4       p\        P                  ! VR4      ;_uu_ 4       p\        P                  ! R4      pRp\        P
                  ! R^*\        V4      4      V,           Vn        VP                  VR4       RRR4       \        P                  ! V4      ;_uu_ 4       qUP                  R4      ;_uu_ 4       pV P                  VP                  4       R4       RRR4       RRR4       R#   + '       g   i     Lz; i  + '       g   i     L-; i  + '       g   i     R# ; i)zG
readfile() should skip over 'extra' data present in the zip metadata.
r	   r   s   hello, extraz<hhs   the real dataN)r   r   r   r   structpacklenextrar   r   r   r   r*   rA   )r   r   r   r   
extra_datar|   r   s   &      r   test_extraDataZipstreamTests.test_extraData   s     [[]__R%%%B(J{{5"c*o>KBHKK,-	 &
 &&r**c<<3D3DSXXZ)9: 4E** &%
 4E3D***s0   AC:.D !D	(D :D
	DD  D1	c                   ^
p\        V4       Uu. uF  pRV,          NK  	  ppV Uu. uF  q"P                  R4      NK  	  ppV P                  V4      p\        \        P
                  ! W@P                  P                  4      4       V P                  \        V P                  P                  4       4      \        \        \        \        V4      4      4      4       V P                  P                  4        FB  p\        VP                  4       4      pV P                  VP!                  4       W6,          4       KD  	  R# u upi u upi )z
L{twisted.python.zipstream.unzipIterChunky} returns an iterator which
must be exhausted to completely unzip the input archive.
This is test file %d!asciiN)rangeencoderv   listr   unzipIterChunkyri   ro   r*   setlistdirmaprq   childrenintbasename
getContent)r   numfilesru   r   rs   rh   nums   &      r   test_unzipIterChunky#ZipstreamTests.test_unzipIterChunky   s    
 9>xIA+a//I/78x!HHW%x8%%h/
Y&&z==3E3EFGT]]2245s3sE(O;T7UV]]++-Eenn&'CU--/? . J8s
   D<Ec                   ^
p\        V4       Uu. uF  pRV,          NK  	  ppV Uu. uF  q"P                  R4      NK  	  ppV P                  VR4      p\        \        P
                  ! W@P                  P                  4      4       \        V4       Uu0 uF  p\        V4      P                  R4      kK  	  ppV P                  \        V P                  P                  R4      P                  4       4      V4       V P                  P                  R4      P                  4        FB  p\        VP                  4       4      pV P                  VP!                  4       W5,          4       KD  	  R# u upi u upi u upi )z
The path to which a file is extracted by L{zipstream.unzipIterChunky}
is determined by joining the C{directory} argument to C{unzip} with the
path within the archive of the file being extracted.
r   r   foos   fooN)r   r   rv   r   r   r   ri   ro   rq   r*   r   rh   r   r   r   r   r   )r   r   ru   r   rs   r   fileContentsrh   s   &       r   test_unzipIterChunkyDirectory,ZipstreamTests.test_unzipIterChunkyDirectory  s#    9>xIA+a//I/78x!HHW%x8%%h6
Y&&z==3E3EFG<A(OLOSC0OLT]]008@@BC\R]]((099;Eenn&'CU--/? < J8 Ms   E-E2#E7c                   Rp\        R4       FL  p\        \        P                  ! 4       ^4      p\        V4      P	                  R4      pVRV,           ,          pKN  	  \        V4      P                  4       p	\        P                  ! V P                  4       4      p
V
P                  4        V
P                  R4      P                  pV P                  WV4       \        P                  ! WP                  VR7      p\!        V4      pY=u;8  ;'       d    V8  Mu pV P#                  V4       V F  pK  	  V P%                  V^ 4       V
P                  R4      P'                  4       ;_uu_ 4       p\        VP)                  4       4      P                  4       pV P%                  VV	4       RRR4       R#   + '       g   i     R# ; i)	zG
unzipIterChunky should unzip the given number of bytes per iteration.
r)   i  r       zbigfile.zip)	chunksizezipstreamjunkN)r   roundrandomrq   r   r   	hexdigestr   re   r   rg   rh   ro   _makebigfiler   r   r1   r$   r*   r   rA   )r   r   r   lowerupperjunknr   
numEncodedjunkmd5tempdirzfpathuziterr   approxfnewmd5s   &&&&&            r   _unzipIterChunkyTest#ZipstreamTests._unzipIterChunkyTest  sO    tA,CS1JD:%%D 
 d)%%'##DKKM2}-22&t4**6<<9UL ""U"A A]]?+0022a],,.FVW- 3222s   -:F11G	c                J    V P                  \        P                  R^#^-4       R# )z[
unzipIterChunky should unzip the given number of bytes per iteration on
a stored archive.
i  N)r   r   r`   rj   s   &r   test_unzipIterChunkyStored)ZipstreamTests.test_unzipIterChunkyStored5  s    
 	!!'"4"4c2rBr)   c                J    V P                  \        P                  R^^4       R# )z]
unzipIterChunky should unzip the given number of bytes per iteration on
a deflated archive.
i  N)r   r   r]   rj   s   &r   test_chunkyDeflated"ZipstreamTests.test_chunkyDeflated<  s    
 	!!'"6"6RDr)   c                    \         P                  ! VRV4      ;_uu_ 4       p\        ^
4       F  pRV,          pVP                  VR4       K   	  VP                  RV4       RRR4       R#   + '       g   i     R# ; i)zD
Create a zip file with the given file name and compression scheme.
r	   zzipstream%dr   r   N)r   r   r   r   )r   r   r   r   r   ru   r   s   &&&&   r   r   ZipstreamTests._makebigfileC  s^     __XsK88B2Y"Q&B#  KK.	 9888s   A A++A<	)rf   ri   N)r   )rR   rS   rT   rU   rV   rk   rv   r}   r   r   r   r   r   r   r   r   r   r   r   rW   rX   rY   s   @r   rb   rb      s\     !GC?"?$E";@ @,.<CE/ /r)   rb   )rV   r   r   r   hashlibr   twisted.pythonr   r   twisted.trialr   r   TestCaser\   r_   rb   rQ   r)   r   <module>r      sg        . "^. ^.B'0A0A '%(9(9 %I/X&& I/r)   