ó
    ×›‘he
 ã                   óî  • S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r
  SSKJr  SSKJr  SSKJrJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJ r J!r!  SSK"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)   " S S\5      r* " S S\5      r+ " S S\5      r, " S S\5      r- " S S\5      r. " S S\5      r/ " S S\5      r0 " S S \5      r1 " S! S"\5      r2 " S# S$\5      r3 " S% S&\5      r4g)'z"
Tests for L{twisted.web.static}.
é    N)ÚBytesIO)ÚskipIf)ÚverifyObject)ÚabstractÚ
interfaces)ÚcompatÚlog)ÚnetworkString)ÚFilePath)Úplatform)ÚTestCase)ÚhttpÚresourceÚscriptÚstatic)ÚFOUND)ÚUnsupportedMethod©Ú_render)ÚDummyRequestc                   ó$   • \ rS rSrSrS rS rSrg)ÚStaticDataTestsé    z
Tests for L{Data}.
c                 ó¦   ^ ^• [         R                  " SS5      n[        S/5      mSTl        [	        UT5      nUU 4S jnUR                  U5        U$ )zF
L{Data.render} returns an empty response body for a I{HEAD} request.
ó   fooÚbarÚ ó   HEADc                 ó\   >• TR                  SR                  TR                  5      S5        g ©Nó    ©ÚassertEqualÚjoinÚwritten©ÚignoredÚrequestÚselfs    €€Ú`C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/web/test/test_static.pyÚ
cbRenderedÚ4StaticDataTests.test_headRequest.<locals>.cbRendered.   ó    ø€ Ø×Ñ˜SŸX™X g§o¡oÓ6¸Õ<r!   )r   ÚDatar   Úmethodr   ÚaddCallback)r)   ÚdataÚdr+   r(   s   `   @r*   Útest_headRequestÚ StaticDataTests.test_headRequest%   sL   ù€ ô �{Š{˜6 5Ó)ˆÜ ˜tÓ$ˆØ ˆŒÜ�D˜'Ó"ˆö	=ð 	
�‰�jÔ!Øˆr!   c                 óš   • [         R                  " SS5      n[        S/5      nSUl        U R	                  [
        UR                  U5        g)z^
L{Data.render} raises L{UnsupportedMethod} in response to a non-I{GET},
non-I{HEAD} request.
r   s   barr!   ó   POSTN)r   r.   r   r/   ÚassertRaisesr   Úrender)r)   r1   r(   s      r*   Útest_invalidMethodÚ"StaticDataTests.test_invalidMethod4   s>   € ô
 �{Š{˜6 6Ó*ˆÜ ˜uÓ%ˆØ ˆŒØ×ÑÔ+¨T¯[©[¸'ÕBr!   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r3   r9   Ú__static_attributes__r;   r!   r*   r   r       s   † ñòõCr!   r   c                   ó„  • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS r\" \R                   " 5       S5      S 5       rS rS rS rS rS r\" \R0                  " 5       R3                  5       S;  SR5                  \R0                  " 5       5      5      S 5       rS rS rS rS rS r S r!S r"S r#S r$S r%S  r&S!r'g")#ÚStaticFileTestsé?   z*
Tests for the basic behavior of L{File}.
c                 ó   • [        X5      $ ©Nr   )r)   r   r(   s      r*   r   ÚStaticFileTests._renderD   s   € Ü�xÓ)Ð)r!   c                 ó  • [         R                  " SS9 n[        R                  " U R	                  5       SS9nU R                  UR                  S/5        SSS5        U R                  [        W5      S5        g! , (       d  f       N*= f)z‰
Passing C{1} as the value to L{File}'s C{ignoredExts} argument
issues a warning and sets the ignored extensions to the
wildcard C{"*"}.
T©Úrecordé   ©ÚignoredExtsÚ*N©ÚwarningsÚcatch_warningsr   ÚFileÚmktempr#   rM   Úlen©r)   ÚcaughtWarningsÚfiles      r*   Útest_ignoredExtTrueÚ#StaticFileTests.test_ignoredExtTrueG   sg   € ô ×$Ò$¨DÒ1°^Ü—;’;˜tŸ{™{›}¸!Ñ<ˆDØ×Ñ˜T×-Ñ-°¨uÔ5÷ 2ð 	×Ñœ˜^Ó,¨aÕ0÷	 2Õ1úó   •AA:Á:
Bc                 ó  • [         R                  " SS9 n[        R                  " U R	                  5       SS9nU R                  UR                  / 5        SSS5        U R                  [        W5      S5        g! , (       d  f       N*= f)z„
Passing C{1} as the value to L{File}'s C{ignoredExts} argument
issues a warning and sets the ignored extensions to the empty
list.
TrI   r   rL   NrK   rO   rU   s      r*   Útest_ignoredExtFalseÚ$StaticFileTests.test_ignoredExtFalseS   se   € ô ×$Ò$¨DÒ1°^Ü—;’;˜tŸ{™{›}¸!Ñ<ˆDØ×Ñ˜T×-Ñ-¨rÔ2÷ 2ð 	×Ñœ˜^Ó,¨aÕ0÷	 2Õ1ús   •A A9Á9
Bc                 ó  • [         R                  " SS9 n[        R                  " U R	                  5       SS9nU R                  UR                  S/5        SSS5        U R                  [        W5      S5        g! , (       d  f       N*= f)z„
Passing C{1} as the value to L{File}'s C{allowExt} argument
issues a warning and sets the ignored extensions to the
wildcard C{*}.
TrI   rL   rN   NrK   rO   rU   s      r*   Útest_allowExtÚStaticFileTests.test_allowExt_   sg   € ô ×$Ò$¨DÒ1°^Ü—;’;˜tŸ{™{›}¸$Ñ?ˆDØ×Ñ˜T×-Ñ-°¨uÔ5÷ 2ð 	×Ñœ˜^Ó,¨aÕ0÷	 2Õ1úrZ   c                 ó   • [        S/5      nSUl        [        U R                  5       5      nUR	                  S5        [
        R                  " UR                  5      nU R                  [        UR                  U5        g)z^
L{File.render} raises L{UnsupportedMethod} in response to a non-I{GET},
non-I{HEAD} request.
r!   r6   r   N)r   r/   r   rS   Ú
setContentr   rR   Úpathr7   r   r8   )r)   r(   rc   rW   s       r*   r9   Ú"StaticFileTests.test_invalidMethodk   s\   € ô
  ˜uÓ%ˆØ ˆŒÜ˜Ÿ™›Ó&ˆØ�‰˜ÔÜ�{Š{˜4Ÿ9™9Ó%ˆØ×ÑÔ+¨T¯[©[¸'ÕBr!   c                 ó6  ^ ^• [        T R                  5       5      nUR                  5         [        R                  " UR
                  5      n[        S/5      m[        R                  " UT5      nT R                  UT5      nUU 4S jnUR                  U5        U$ )z¶
If a request is made which encounters a L{File} before a final segment
which does not correspond to any file in the path the L{File} was
created with, a not found response is sent.
ó   foobarc                 ó>   >• TR                  TR                  S5        g ©Né”  ©r#   ÚresponseCoder&   s    €€r*   r+   Ú1StaticFileTests.test_notFound.<locals>.cbRendered†   ó   ø€ Ø×Ñ˜W×1Ñ1°3Õ7r!   ©r   rS   Úmakedirsr   rR   rc   r   r   ÚgetChildForRequestr   r0   ©r)   ÚbaserW   Úchildr2   r+   r(   s   `     @r*   Útest_notFoundÚStaticFileTests.test_notFoundw   sv   ù€ ô ˜Ÿ™›Ó&ˆØ�‰ŒÜ�{Š{˜4Ÿ9™9Ó%ˆä 	˜{Ó+ˆÜ×+Ò+¨D°'Ó:ˆà�L‰L˜ Ó(ˆö	8ð 	
�‰�jÔ!Øˆr!   c                 óf  • [        U R                  5       5      nUR                  5         [        R                  " UR
                  5      n[        S/5      n[        R                  " X#5      nU R                  U[        R                  5        U R                  UR
                  UR
                  5        g)zj
The C{''} child of a L{File} which corresponds to a directory in the
filesystem is a L{DirectoryLister}.
r!   N)r   rS   ro   r   rR   rc   r   r   rp   ÚassertIsInstanceÚDirectoryListerr#   ©r)   rr   rW   r(   rs   s        r*   Útest_emptyChildÚStaticFileTests.test_emptyChildŒ   sy   € ô
 ˜Ÿ™›Ó&ˆØ�‰ŒÜ�{Š{˜4Ÿ9™9Ó%ˆä ˜uÓ%ˆÜ×+Ò+¨DÓ:ˆØ×Ñ˜e¤V×%;Ñ%;Ô<Ø×Ñ˜Ÿ™ T§Y¡YÕ/r!   c                 óX  • [        U R                  5       5      R                  5       nUR                  5         UR	                  S5      R                  S5      R                  5         [        R                  " UR                  5      n[        S/5      n[        R                  " X#5      nU R                  U[        R                  5        [        R                   " UR                  5      nU R#                  UR                  U5        UR%                  U5      nU R                  U[&        5        g)zÂ
The C{u''} child of a L{File} which corresponds to a directory
whose path is text is a L{DirectoryLister} that renders to a
binary listing.

@see: U{https://twistedmatrix.com/trac/ticket/9438}
z	text-fileÚwr!   N)r   rS   Ú
asTextModero   rs   ÚopenÚcloser   rR   rc   r   r   rp   rw   rx   r   ÚnativeStringr#   r8   Úbytes)r)   ÚtextBaseÚtextFiler(   rs   Ú
nativePathÚresponses          r*   Útest_emptyChildUnicodeParentÚ,StaticFileTests.test_emptyChildUnicodeParentš   sÓ   € ô ˜DŸK™K›MÓ*×5Ñ5Ó7ˆØ×ÑÔØ�‰�{Ó#×(Ñ(¨Ó-×3Ñ3Ô5Ü—;’;˜xŸ}™}Ó-ˆä ˜uÓ%ˆÜ×+Ò+¨HÓ>ˆØ×Ñ˜e¤V×%;Ñ%;Ô<ä×(Ò(¨¯©Ó7ˆ
Ø×Ñ˜Ÿ™ ZÔ0à—<‘< Ó(ˆØ×Ñ˜h¬Õ.r!   c                 ó6  ^ ^• [        T R                  5       5      nUR                  5         [        R                  " UR
                  5      n[        S/5      m[        R                  " UT5      nT R                  UT5      nUU 4S jnUR                  U5        U$ )z²
If a request is made which encounters a L{File} before a final segment
which cannot be looked up in the filesystem due to security
considerations, a not found response is sent.
s   ..c                 ó>   >• TR                  TR                  S5        g rh   rj   r&   s    €€r*   r+   ÚBStaticFileTests.test_securityViolationNotFound.<locals>.cbRenderedÀ   rm   r!   rn   rq   s   `     @r*   Útest_securityViolationNotFoundÚ.StaticFileTests.test_securityViolationNotFound±   sv   ù€ ô ˜Ÿ™›Ó&ˆØ�‰ŒÜ�{Š{˜4Ÿ9™9Ó%ˆä ˜wÓ'ˆÜ×+Ò+¨D°'Ó:ˆà�L‰L˜ Ó(ˆö	8ð 	
�‰�jÔ!Øˆr!   z(Cannot remove read permission on Windowsc                 ód  ^ ^• [        T R                  5       5      nUR                  S5        T R                  UR                  S5        UR	                  S5        [
        R                  " UR                  5      n[        S/5      mT R                  UT5      nUU 4S jnUR                  U5        U$ )z‰
If the file in the filesystem which would satisfy a request cannot be
read, L{File.render} sets the HTTP response code to I{FORBIDDEN}.
r!   iÀ  r   c                 ó>   >• TR                  TR                  S5        g )Ni“  rj   r&   s    €€r*   r+   Ú:StaticFileTests.test_forbiddenResource.<locals>.cbRenderedØ   rm   r!   )r   rS   rb   Ú
addCleanupÚchmodr   rR   rc   r   r   r0   )r)   rr   rW   r2   r+   r(   s   `    @r*   Útest_forbiddenResourceÚ&StaticFileTests.test_forbiddenResourceÆ   s†   ù€ ô ˜Ÿ™›Ó&ˆØ�‰˜Ôà�‰˜Ÿ
™
 EÔ*ð 	�
‰
�1Œä�{Š{˜4Ÿ9™9Ó%ˆÜ ˜uÓ%ˆØ�L‰L˜˜wÓ'ˆö	8ð 	
�‰�jÔ!Øˆr!   c                 ó†  ^ ^• T R                  5       n[        U[        5      (       a  UR                  S5      n[	        U5      nUR                  5         [        R                  " UR                  5      n[        S/5      m[        R                  " UT5      nT R                  UT5      nUU 4S jnUR                  U5        U$ )zk
A request whose path cannot be decoded as UTF-8 receives a not
found response, and the failure is logged.
Úasciió   ÿc                 óš   >• TR                  TR                  S5        TR                  [        TR                  [        5      5      S5        g )Nri   rK   )r#   rk   rT   ÚflushLoggedErrorsÚUnicodeDecodeErrorr&   s    €€r*   r+   Ú8StaticFileTests.test_undecodablePath.<locals>.cbRenderedï   s:   ø€ Ø×Ñ˜W×1Ñ1°3Ô7Ø×ÑœS ×!7Ñ!7Ô8JÓ!KÓLÈaÕPr!   )rS   Ú
isinstancer‚   Údecoder   ro   r   rR   rc   r   r   rp   r   r0   )r)   rc   rr   rW   rs   r2   r+   r(   s   `      @r*   Útest_undecodablePathÚ$StaticFileTests.test_undecodablePathÞ   s–   ù€ ð
 �{‰{‹}ˆÜ�dœE×"Ñ"Ø—;‘;˜wÓ'ˆDÜ˜‹~ˆØ�‰Œä�{Š{˜4Ÿ9™9Ó%ˆÜ ˜yÓ)ˆÜ×+Ò+¨D°'Ó:ˆà�L‰L˜ Ó(ˆö	Qð 	
�‰�jÔ!Øˆr!   c                 ó€   • U R                  [        R                  " S5      R                  [        R
                  5        g)z>
L{File.forbidden} defaults to L{resource.ForbiddenResource}.
ó   .N)rw   r   rR   Ú	forbiddenr   ÚForbiddenResource©r)   s    r*   Útest_forbiddenResource_defaultÚ.StaticFileTests.test_forbiddenResource_defaultö   s)   € ð 	×ÑœfŸkšk¨$Ó/×9Ñ9¼8×;UÑ;UÕVr!   c                 ód  ^^• [        U R                  5       5      nUR                  S5        SmS n " U4S jS[        R                  5      m " U4S jS[
        R                  5      nU" UR                  5      nX$l        [        S/5      nUR                  U5      nU R                  TU5        g)	zj
The resource rendered for forbidden requests is stored as a class
member so that users can customize it.
r!   s   custom-forbidden-responsec                  ó6   • [        [        R                  S5      e)Nr   )ÚOSErrorÚerrnoÚEACCESr;   r!   r*   ÚfailingOpenForReadingÚOStaticFileTests.test_forbiddenResource_customize.<locals>.failingOpenForReading  s   € Üœ%Ÿ,™,¨Ó+Ð+r!   c                   ó"   >• \ rS rSrU 4S jrSrg)ÚQStaticFileTests.test_forbiddenResource_customize.<locals>.CustomForbiddenResourcei  c                 ó   >• T$ rF   r;   ©r)   r(   ÚmarkerResponses     €r*   r8   ÚXStaticFileTests.test_forbiddenResource_customize.<locals>.CustomForbiddenResource.render	  ó	   ø€ Ø%Ð%r!   r;   N©r<   r=   r>   r?   r8   rA   ©r²   s   €r*   ÚCustomForbiddenResourcer¯     ó   ø† ÷&ð &r!   r·   c                   ó&   >• \ rS rSr Y " 5       rSrg)ÚJStaticFileTests.test_forbiddenResource_customize.<locals>.CustomStaticFilei  r;   N)r<   r=   r>   r?   r¢   rA   )r·   s   €r*   ÚCustomStaticFilerº     s   ø† Ú/Ó1‹Ir!   r»   N)r   rS   rb   r   ÚResourcer   rR   rc   ÚopenForReadingr   r8   r#   )	r)   rr   r¬   r»   ÚfileResourcer(   Úresultr·   r²   s	          @@r*   Ú test_forbiddenResource_customizeÚ0StaticFileTests.test_forbiddenResource_customizeü   s�   ù€ ô
 ˜Ÿ™›Ó&ˆØ�‰˜ÔØ5ˆò	,÷	&¤h×&7Ñ&7ô 	&÷	2œvŸ{™{ô 	2ñ (¨¯	©	Ó2ˆØ&;Ô#Ü ˜uÓ%ˆà×$Ñ$ WÓ-ˆà×Ñ˜¨Õ0r!   c                 ó†  ^ ^• [        T R                  5       5      nUR                  5         UR                  S5      R	                  S5        [
        R                  " UR                  5      nS/Ul        [        S/5      m[        R                  " UT5      nT R                  UT5      nUU 4S jnUR                  U5        U$ )zã
If a request is made which encounters a L{File} before a final empty
segment, a file in the L{File} instance's C{indexNames} list which
exists in the path the L{File} was created with is served as the
response to the request.
úfoo.baró   bazr!   c                 ó¸   >• TR                  SR                  TR                  5      S5        TR                  TR                  R	                  S5      S   S5        g ©Nr!   rÄ   ó   content-lengthr   ó   3©r#   r$   r%   ÚresponseHeadersÚgetRawHeadersr&   s    €€r*   r+   Ú3StaticFileTests.test_indexNames.<locals>.cbRendered)  óJ   ø€ Ø×Ñ˜SŸX™X g§o¡oÓ6¸Ô?Ø×ÑØ×'Ñ'×5Ñ5Ð6GÓHÈÑKÈTõr!   )r   rS   ro   rs   rb   r   rR   rc   Ú
indexNamesr   r   rp   r   r0   rq   s   `     @r*   Útest_indexNamesÚStaticFileTests.test_indexNames  s–   ù€ ô ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�9Ó×(Ñ(¨Ô0Ü�{Š{˜4Ÿ9™9Ó%ˆØ$˜+ˆŒä ˜uÓ%ˆÜ×+Ò+¨D°'Ó:ˆà�L‰L˜ Ó(ˆö	ð 	
�‰�jÔ!Øˆr!   c                 óv  ^ ^• [        T R                  5       5      nUR                  5         UR                  S5      R	                  S5        [
        R                  " UR                  5      n[        S/5      m[        R                  " UT5      nT R                  UT5      nUU 4S jnUR                  U5        U$ )z¹
If a request is made which encounters a L{File} before a final segment
which names a file in the path the L{File} was created with, that file
is served as the response to the request.
rÃ   rÄ   ó   foo.barc                 ó¸   >• TR                  SR                  TR                  5      S5        TR                  TR                  R	                  S5      S   S5        g rÆ   rÉ   r&   s    €€r*   r+   Ú3StaticFileTests.test_staticFile.<locals>.cbRenderedB  rÍ   r!   ©r   rS   ro   rs   rb   r   rR   rc   r   r   rp   r   r0   rq   s   `     @r*   Útest_staticFileÚStaticFileTests.test_staticFile2  s�   ù€ ô ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�9Ó×(Ñ(¨Ô0Ü�{Š{˜4Ÿ9™9Ó%ˆä 
˜|Ó,ˆÜ×+Ò+¨D°'Ó:ˆà�L‰L˜ Ó(ˆö	ð 	
�‰�jÔ!Øˆr!   )úutf-8Úmcbsz>Cannot write unicode filenames with file system encoding of {}c                 ó   ^ ^^• SnSm[        T R                  5       5      nUR                  5         UR                  U5      R	                  T5        [
        R                  " UR                  5      n[        UR                  S5      /5      m[        R                  " UT5      nT R                  UT5      nUUU 4S jnUR                  U5        U$ )z`
A request for a existing unicode file path encoded as UTF-8
returns the contents of that file.
u   á¿†s   contentrØ   c           
      óî   >• TR                  SR                  TR                  5      T5        TR                  TR                  R	                  S5      S   [        [        [        T5      5      5      5        g )Nr!   rÇ   r   )r#   r$   r%   rÊ   rË   r
   ÚstrrT   )r'   Úcontentr(   r)   s    €€€r*   r+   ÚBStaticFileTests.test_staticFileUnicodeFileName.<locals>.cbRenderedb  sY   ø€ Ø×Ñ˜SŸX™X g§o¡oÓ6¸Ô@Ø×ÑØ×'Ñ'×5Ñ5Ð6GÓHÈÑKÜœc¤# g£,Ó/Ó0õr!   )r   rS   ro   rs   rb   r   rR   rc   r   Úencoder   rp   r   r0   )	r)   Únamerr   rW   rs   r2   r+   rÝ   r(   s	   `      @@r*   Útest_staticFileUnicodeFileNameÚ.StaticFileTests.test_staticFileUnicodeFileNameK  s¡   ú€ ð =ˆØˆä˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�4Ó×#Ñ# GÔ,Ü�{Š{˜4Ÿ9™9Ó%ˆä §¡¨GÓ 4Ð5Ó6ˆÜ×+Ò+¨D°'Ó:ˆà�L‰L˜ Ó(ˆ÷	ð 	
�‰�jÔ!Øˆr!   c                 ó¾   • [         R                  " U R                  5       5      n[        S/5      nUR	                  SU5      nU R                  X1R                  5        g)zy
A L{static.File} created for a directory which does not exist should
return childNotFound from L{static.File.getChild}.
rÒ   N)r   rR   rS   r   ÚgetChildr#   ÚchildNotFound)r)   Ú
staticFiler(   rs   s       r*   Útest_staticFileDeletedGetChildÚ.StaticFileTests.test_staticFileDeletedGetChildl  sJ   € ô
 —[’[ §¡£Ó/ˆ
Ü 
˜|Ó,ˆØ×#Ñ# J°Ó8ˆØ×Ñ˜× 8Ñ 8Õ9r!   c                 ó  ^ ^^^• [         R                  " T R                  5       5      n[        S/5      m[        S/5      mT R	                  UT5      mT R	                  UR
                  T5      nUUUU 4S jnUR                  U5        U$ )zc
A L{static.File} created for a file which does not exist should render
its C{childNotFound} page.
rÒ   c                 ó:   >• UUU4S jnTR                  U5        T$ )Nc                 óŽ   >• TR                  SR                  TR                  5      SR                  TR                  5      5        g r    r"   )r'   r(   Úrequest2r)   s    €€€r*   r+   ÚUStaticFileTests.test_staticFileDeletedRender.<locals>.cbRendered2.<locals>.cbRendered‚  s/   ø€ Ø× Ñ  §¡¨'¯/©/Ó!:¸C¿H¹HÀX×EUÑEUÓ<VÕWr!   )r0   )r'   r+   r2   r(   rì   r)   s     €€€€r*   ÚcbRendered2ÚAStaticFileTests.test_staticFileDeletedRender.<locals>.cbRendered2�  s   ø€ ÷Xð �M‰M˜*Ô%ØˆHr!   )r   rR   rS   r   r   rå   r0   )r)   ræ   Úd2rî   r2   r(   rì   s   `   @@@r*   Útest_staticFileDeletedRenderÚ,StaticFileTests.test_staticFileDeletedRenderv  st   û€ ô
 —[’[ §¡£Ó/ˆ
Ü 
˜|Ó,ˆÜ  Ó-ˆØ�L‰L˜ WÓ-ˆØ�\‰\˜*×2Ñ2°HÓ=ˆ÷	ð 	ð 	�‰�{Ô#Øˆ	r!   c                 óv  ^^• [        U R                  5       5      nUR                  S5        Sm " U4S jS[        R                  5      m " U4S jS[
        R                  5      nU" UR                  5      n[        S/5      nUR                  SU5      nUR                  U5      nU R                  TU5        g)	z[
The resource rendered for child not found requests can be customize
using a class member.
r!   s   custom-child-not-found-responsec                   ó"   >• \ rS rSrU 4S jrSrg)ÚYStaticFileTests.test_getChildChildNotFound_customize.<locals>.CustomChildNotFoundResourceri   c                 ó   >• T$ rF   r;   r±   s     €r*   r8   Ú`StaticFileTests.test_getChildChildNotFound_customize.<locals>.CustomChildNotFoundResource.render•  r´   r!   r;   Nrµ   r¶   s   €r*   ÚCustomChildNotFoundResourcerõ   ”  r¸   r!   rø   c                   ó&   >• \ rS rSr Y " 5       rSrg)ÚNStaticFileTests.test_getChildChildNotFound_customize.<locals>.CustomStaticFilei˜  r;   N)r<   r=   r>   r?   rå   rA   )rø   s   €r*   r»   rú   ˜  s   ø† Ú7Ó9‹Mr!   r»   s   no-child.txtN)r   rS   rb   r   r¼   r   rR   rc   r   rä   r8   r#   )	r)   rr   r»   r¾   r(   rs   r¿   rø   r²   s	          @@r*   Ú$test_getChildChildNotFound_customizeÚ4StaticFileTests.test_getChildChildNotFound_customize‹  s•   ù€ ô
 ˜Ÿ™›Ó&ˆØ�‰˜ÔØ;ˆ÷	&¬(×*;Ñ*;ô 	&÷	:œvŸ{™{ô 	:ñ (¨¯	©	Ó2ˆÜ Ð0Ó1ˆà×%Ñ% o°wÓ?ˆØ—‘˜gÓ&ˆà×Ñ˜¨Õ0r!   c                 ó  ^ ^• [        T R                  5       5      nUR                  S5        [        R                  " UR
                  5      n[        S/5      mSTl        [        UT5      nUU 4S jnUR                  U5        U$ )zL
L{static.File.render} returns an empty response body for I{HEAD}
requests.
r   r!   r   c                 ó\   >• TR                  SR                  TR                  5      S5        g r    r"   r&   s    €€r*   r+   Ú4StaticFileTests.test_headRequest.<locals>.cbRendered¯  r-   r!   )
r   rS   rb   r   rR   rc   r   r/   r   r0   )r)   rc   rW   r2   r+   r(   s   `    @r*   r3   Ú StaticFileTests.test_headRequest£  sj   ù€ ô
 ˜Ÿ™›Ó&ˆØ�‰˜ÔÜ�{Š{˜4Ÿ9™9Ó%ˆÜ ˜uÓ%ˆØ ˆŒÜ�D˜'Ó"ˆö	=ð 	
�‰�jÔ!Øˆr!   c                 ó¤  ^ ^• [        T R                  5       5      nUR                  5         UR                  S5      R	                  S5        [
        R                  " UR                  5      nS[        R                  0Ul
        [        S/5      m[        R                  " UT5      nT R                  UT5      nUU 4S jnUR                  U5        U$ )zù
If a request is made which encounters a L{File} before a final segment
which names a file with an extension which is in the L{File}'s
C{processors} mapping, the processor associated with that extension is
used to serve the response to the request.
rÃ   sT   from twisted.web.static import Data
resource = Data(b'dynamic world', 'text/plain')
ú.barrÒ   c                 ó¸   >• TR                  SR                  TR                  5      S5        TR                  TR                  R	                  S5      S   S5        g )Nr!   s   dynamic worldrÇ   r   s   13rÉ   r&   s    €€r*   r+   Ú3StaticFileTests.test_processors.<locals>.cbRenderedÊ  sK   ø€ Ø×Ñ˜SŸX™X g§o¡oÓ6Ð8HÔIØ×ÑØ×'Ñ'×5Ñ5Ð6GÓHÈÑKÈUõr!   )r   rS   ro   rs   rb   r   rR   rc   r   ÚResourceScriptÚ
processorsr   r   rp   r   r0   rq   s   `     @r*   Útest_processorsÚStaticFileTests.test_processorsµ  s§   ù€ ô ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�9Ó×(Ñ(ðAô	
ô
 �{Š{˜4Ÿ9™9Ó%ˆØ!¤6×#8Ñ#8Ð9ˆŒÜ 
˜|Ó,ˆÜ×+Ò+¨D°'Ó:ˆà�L‰L˜ Ó(ˆö	ð 	
�‰�jÔ!Øˆr!   c                 óN  • [         R                  " S5      nU R                  UR                  / 5        UR	                  S5        UR	                  S5        U R                  UR                  SS/5        [         R                  " SSS9nU R                  UR                  SS/5        g)zy
The list of ignored extensions can be set by passing a value to
L{File.__init__} or by calling L{File.ignoreExt} later.
r¡   z.foor  )r  ú.bazrL   r
  N)r   rR   r#   rM   Ú	ignoreExt)r)   rW   s     r*   Útest_ignoreExtÚStaticFileTests.test_ignoreExtÓ  s‡   € ô
 �{Š{˜4Ó ˆØ×Ñ˜×)Ñ)¨2Ô.Ø�‰�vÔØ�‰�vÔØ×Ñ˜×)Ñ)¨F°FÐ+;Ô<ä�{Š{˜4Ð-=Ñ>ˆØ×Ñ˜×)Ñ)¨F°FÐ+;Õ<r!   c                 ó´  ^ ^• [        T R                  5       5      nUR                  5         UR                  S5      R	                  S5        UR                  S5      R	                  S5        [
        R                  " UR                  SS9n[        S/5      m[        R                  " UT5      nT R                  UT5      nUU 4S jnUR                  U5        U$ )	zò
A request for the I{base} child of a L{File} succeeds with a resource
for the I{base<extension>} file in the path the L{File} was created
with if such a file exists and the L{File} has been configured to
ignore the I{<extension>} extension.
rÃ   rÄ   zfoo.quuxrf   )r  rL   r   c                 ó\   >• TR                  SR                  TR                  5      S5        g )Nr!   rÄ   r"   r&   s    €€r*   r+   ÚAStaticFileTests.test_ignoredExtensionsIgnored.<locals>.cbRenderedó  s    ø€ Ø×Ñ˜SŸX™X g§o¡oÓ6¸Õ?r!   rÕ   rq   s   `     @r*   Útest_ignoredExtensionsIgnoredÚ-StaticFileTests.test_ignoredExtensionsIgnoredá  s§   ù€ ô ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�9Ó×(Ñ(¨Ô0Ø�
‰
�:Ó×)Ñ)¨)Ô4Ü�{Š{˜4Ÿ9™9°)Ñ<ˆä ˜xÓ(ˆÜ×+Ò+¨D°'Ó:ˆà�L‰L˜ Ó(ˆö	@ð 	
�‰�jÔ!Øˆr!   c                 óþ  • [        U R                  5       5      nUR                  5         UR                  S5      R                  5         [        R
                  " UR                  5      n[        S/5      nSUl        [        R                  " X#5      nU R                  U R                  XC5      5        U R                  UR                  [        5        U R                  UR                   R#                  S5      S/5        g)zŽ
A request for a path which is a directory but does not have a trailing
slash will be redirected to a URL which does have a slash by L{File}.
Úfolders   folders   http://dummy/folder#baz?foo=bars   locations    http://dummy/folder/#baz?foo=barN)r   rS   ro   rs   r   rR   rc   r   Úurir   rp   ÚsuccessResultOfr   r#   rk   r   rÊ   rË   ry   s        r*   Ú+test_directoryWithoutTrailingSlashRedirectsÚ;StaticFileTests.test_directoryWithoutTrailingSlashRedirectsù  s¼   € ô
 ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�8Ó×%Ñ%Ô'Ü�{Š{˜4Ÿ9™9Ó%ˆä 	˜{Ó+ˆØ8ˆŒÜ×+Ò+¨DÓ:ˆà×Ñ˜TŸ\™\¨%Ó9Ô:Ø×Ñ˜×-Ñ-¬uÔ5Ø×ÑØ×#Ñ#×1Ñ1°+Ó>Ø0Ð1õ	
r!   c                 óÈ   ^• [        5       m[        U R                  5       5      nUR                  5         [        R
                  " UR                  5      nU4S jUl        TU4$ )z�
Create a L{File} that when opened for reading, returns a L{StringIO}.

@return: 2-tuple of the opened "file" and the L{File}.
@rtype: L{tuple}
c                  ó   >• T $ rF   r;   )ÚfakeFiles   €r*   Ú<lambda>Ú;StaticFileTests._makeFilePathWithStringIO.<locals>.<lambda>  s   ø€ ™Hr!   )ÚStringIOr   rS   Útouchr   rR   rc   r   )r)   rc   rW   r  s      @r*   Ú_makeFilePathWithStringIOÚ)StaticFileTests._makeFilePathWithStringIO  sH   ø€ ô “:ˆÜ˜Ÿ™›Ó&ˆØ�
‰
ŒÜ�{Š{˜4Ÿ9™9Ó%ˆä$ˆŒ	Ø˜ˆ~Ðr!   c                 ó  • U R                  5       u  p[        S/5      nSUl        U R                  [	        X#5      5        U R                  SR                  UR                  5      S5        U R                  UR                  5        g)zU
A HEAD request opens the file, gets the size, and then closes it after
the request.
r   r   r!   N)
r   r   r/   r  r   r#   r$   r%   Ú
assertTrueÚclosed©r)   r  rW   r(   s       r*   Útest_HEADClosesFileÚ#StaticFileTests.test_HEADClosesFile  sg   € ð
 ×7Ñ7Ó9‰ˆÜ ˜tÓ$ˆØ ˆŒØ×ÑœW TÓ3Ô4Ø×Ñ˜Ÿ™ '§/¡/Ó2°CÔ8Ø�‰˜Ÿ™Õ(r!   c                 ó  • U R                  5       u  p[        S/5      nSUl        S Ul        U R	                  [        X#5      5        U R                  SR                  UR                  5      S5        U R                  UR                  5        g)zA
A GET request that is cached closes the file after the request.
r   s   GETc                 ó"   • [         R                  $ rF   )r   ÚCACHED)Ú_s    r*   r  Ú>StaticFileTests.test_cachedRequestClosesFile.<locals>.<lambda>1  s   € ¬D¯KªKr!   r!   N)r   r   r/   ÚsetLastModifiedr  r   r#   r$   r%   r#  r$  r%  s       r*   Útest_cachedRequestClosesFileÚ,StaticFileTests.test_cachedRequestClosesFile)  so   € ð ×7Ñ7Ó9‰ˆÜ ˜tÓ$ˆØˆŒá"7ˆÔØ×ÑœW TÓ3Ô4Ø×Ñ˜Ÿ™ '§/¡/Ó2°CÔ8Ø�‰˜Ÿ™Õ(r!   r;   N)(r<   r=   r>   r?   r@   r   rX   r\   r_   r9   rt   rz   r‡   rŒ   r   r   Ú	isWindowsr“   rž   r¥   rÀ   rÏ   rÖ   ÚsysÚgetfilesystemencodingÚlowerÚformatrá   rç   rñ   rû   r3   r  r  r  r  r   r&  r.  rA   r;   r!   r*   rC   rC   ?   sø   † ñò*ò
1ò
1ò
1ò
Còò*0ò/ò.ñ* ˆH×ÒÓ Ð"LÓMñó Nðò.ò0Wò1ò6ò6ñ2 Ø×!Ò!Ó#×)Ñ)Ó+Ð3DÑDð	ß‰f�S×.Ò.Ó0Ó1óñ
óð
ò8:òò*1ò0ò$ò<=òò0
ò*ò
)õ)r!   rC   c                   óŽ   • \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS rS rSrg)ÚStaticMakeProducerTestsi7  z!
Tests for L{File.makeProducer}.
Nc                 óº   • [        U R                  5       5      nUR                  U5        [        R                  " UR                  5       5      nX5l        X%l        U$ )zÍ
Make a L{static.File} resource that has C{content} for its content.

@param content: The L{bytes} to use as the contents of the resource.
@param type: Optional value for the content type of the resource.
)r   rS   rb   r   rR   Ú_asBytesPathÚencodingÚtype)r)   rÝ   r:  r9  ÚfileNamer   s         r*   ÚmakeResourceWithContentÚ/StaticMakeProducerTests.makeResourceWithContent<  sI   € ô ˜DŸK™K›MÓ*ˆØ×Ñ˜GÔ$Ü—;’;˜x×4Ñ4Ó6Ó7ˆØ$ÔØŒØˆr!   c                 óÆ   • 0 nUR                   R                  5        H@  u  p4UR                  5       R                  S5      (       d  M+  US   X#R                  5       '   MB     U$ )z¢
Extract the content-* headers from the L{DummyRequest} C{request}.

This returns the subset of C{request.outgoingHeaders} of headers that
start with 'content-'.
s   content-r   )rÊ   ÚgetAllRawHeadersr3  Ú
startswith)r)   r(   ÚcontentHeadersÚkÚvs        r*   rA  Ú&StaticMakeProducerTests.contentHeadersJ  sU   € ð ˆØ×+Ñ+×<Ñ<Ö>‰DˆAØ�w‰w‹y×#Ñ# K×0Ó0Ø,-¨a©D�Ÿw™w›yÓ)ñ ?ð Ðr!   c                 óö   • U R                  S5      n[        / 5      nUR                  " 5        nUR                  " X#5      nU R	                  U[
        R                  5        SSS5        g! , (       d  f       g= f)zX
makeProducer when no Range header is set returns an instance of
NoRangeStaticProducer.
r!   N)r<  r   r½   ÚmakeProducerrw   r   ÚNoRangeStaticProducer)r)   r   r(   rW   Úproducers        r*   Ú,test_noRangeHeaderGivesNoRangeStaticProducerÚDStaticMakeProducerTests.test_noRangeHeaderGivesNoRangeStaticProducerW  s^   € ð
 ×/Ñ/°Ó4ˆÜ˜rÓ"ˆØ×$Ò$Ô&¨$Ø×,Ò,¨WÓ;ˆHØ×!Ñ! (¬F×,HÑ,HÔI÷ '×&Ö&ús   ®3A*Á*
A8c                 ó
  • U R                  S5      n[        / 5      nUR                  " 5        nUR                  " X#5        U R	                  [
        R                  UR                  5        SSS5        g! , (       d  f       g= f)zX
makeProducer when no Range header is set sets the responseCode on the
request to 'OK'.
r!   N)r<  r   r½   rF  r#   r   ÚOKrk   )r)   r   r(   rW   s       r*   Útest_noRangeHeaderSets200OKÚ3StaticMakeProducerTests.test_noRangeHeaderSets200OKb  s`   € ð
 ×/Ñ/°Ó4ˆÜ˜rÓ"ˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×ÑœTŸW™W g×&:Ñ&:Ô;÷ '×&Ö&ús   ®=A4Á4
Bc                 ó<  • SnSnSnU R                  SU-  X#S9n[        / 5      nUR                  " 5        nUR                  " XV5        U R	                  [        U5      SU4-  [        U5      S.U R                  U5      5        SSS5        g! , (       d  f       g= f)	zW
makeProducer when no Range header is set sets the Content-* headers
for the response.
é{   ú
text/plainÚgzipó   a©r:  r9  ó   %d)ó   content-typerÇ   ó   content-encodingN)r<  r   r½   rF  r#   r
   rA  )r)   ÚlengthÚcontentTypeÚcontentEncodingr   r(   rW   s          r*   Ú$test_noRangeHeaderSetsContentHeadersÚ<StaticMakeProducerTests.test_noRangeHeaderSetsContentHeadersm  s¢   € ð
 ˆØ"ˆØ ˆØ×/Ñ/Ø�6‰M ð 0ð 
ˆô ˜rÓ"ˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×Ñä%2°;Ó%?Ø',°¨yÑ'8Ü)6°Ó)Gñð
 ×#Ñ# GÓ,ô÷ '×&Ö&ús   ¶ABÂ
Bc                 ó.  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5      nU R                  U[        R                  5        SSS5        g! , (       d  f       g= f)zs
makeProducer when the Range header requests a single byte range
returns an instance of SingleRangeStaticProducer.
ó   rangeó	   bytes=1-3ó   abcdefN©	r   ÚrequestHeadersÚaddRawHeaderr<  r½   rF  rw   r   ÚSingleRangeStaticProducer©r)   r(   r   rW   rH  s        r*   Ú.test_singleRangeGivesSingleRangeStaticProducerÚFStaticMakeProducerTests.test_singleRangeGivesSingleRangeStaticProducer„  st   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨H°lÔCØ×/Ñ/°	Ó:ˆØ×$Ò$Ô&¨$Ø×,Ò,¨WÓ;ˆHØ×!Ñ! (¬F×,LÑ,LÔM÷ '×&Ö&úó   Á
3BÂ
Bc                 óB  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5        U R                  [        R                  UR                  5        SSS5        g! , (       d  f       g= f)zŠ
makeProducer when the Range header requests a single, satisfiable byte
range sets the response code on the request to 'Partial Content'.
r^  r_  r`  N©
r   rb  rc  r<  r½   rF  r#   r   ÚPARTIAL_CONTENTrk   ©r)   r(   r   rW   s       r*   Ú%test_singleRangeSets206PartialContentÚ=StaticMakeProducerTests.test_singleRangeSets206PartialContent�  sx   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨H°lÔCØ×/Ñ/°	Ó:ˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×ÑœT×1Ñ1°7×3GÑ3GÔH÷ '×&Ö&úó   Á
=BÂ
Bc                 ód  • [        / 5      nUR                  R                  SS5        SnSnU R                  SX#S9nUR                  " 5        nUR
                  " X5        U R                  [        U5      [        U5      SSS	.U R                  U5      5        S
S
S
5        g
! , (       d  f       g
= f)úx
makeProducer when the Range header requests a single, satisfiable byte
range sets the Content-* headers appropriately.
r^  r_  rQ  rR  r`  rT  s   bytes 1-3/6rÈ   )rV  rW  ó   content-rangerÇ   N)	r   rb  rc  r<  r½   rF  r#   r
   rA  )r)   r(   rY  rZ  r   rW   s         r*   Ú"test_singleRangeSetsContentHeadersÚ:StaticMakeProducerTests.test_singleRangeSetsContentHeadersœ  s«   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨H°lÔCØ"ˆØ ˆØ×/Ñ/Ø˜Kð 0ð 
ˆð ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×Ñä%2°;Ó%?Ü)6°Ó)GØ&4Ø'+ñ	ð ×#Ñ# GÓ,ô÷ '×&Ö&ús   ÁAB!Â!
B/c                 ó.  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5      nU R                  U[        R                  5        SSS5        g! , (       d  f       g= f)zŠ
makeProducer still returns an instance of L{SingleRangeStaticProducer}
when the Range header requests a single unsatisfiable byte range.
r^  ó
   bytes=4-10ó   abcNra  re  s        r*   Ú=test_singleUnsatisfiableRangeReturnsSingleRangeStaticProducerÚUStaticMakeProducerTests.test_singleUnsatisfiableRangeReturnsSingleRangeStaticProducer´  st   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨H°mÔDØ×/Ñ/°Ó7ˆØ×$Ò$Ô&¨$Ø×,Ò,¨WÓ;ˆHØ×!Ñ! (¬F×,LÑ,LÔM÷ '×&Ö&úrh  c                 óB  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5        U R                  [        R                  UR                  5        SSS5        g! , (       d  f       g= f)zž
makeProducer sets the response code of the request to of 'Requested
Range Not Satisfiable' when the Range header requests a single
unsatisfiable byte range.
r^  rv  rw  N©
r   rb  rc  r<  r½   rF  r#   r   ÚREQUESTED_RANGE_NOT_SATISFIABLErk   rl  s       r*   Ú?test_singleUnsatisfiableRangeSets416ReqestedRangeNotSatisfiableÚWStaticMakeProducerTests.test_singleUnsatisfiableRangeSets416ReqestedRangeNotSatisfiableÀ  sx   € ô ˜rÓ"ˆØ×Ñ×+Ñ+¨H°mÔDØ×/Ñ/°Ó7ˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×ÑœT×AÑAÀ7×CWÑCWÔX÷ '×&Ö&úro  c                 ó:  • [        / 5      nUR                  R                  SS5        SnU R                  SUS9nUR                  " 5        nUR
                  " X5        U R                  SSSS	.U R                  U5      5        S
S
S
5        g
! , (       d  f       g
= f)zz
makeProducer when the Range header requests a single, unsatisfiable
byte range sets the Content-* headers appropriately.
r^  rv  rQ  rw  ©r:  ó
   text/plainó   0ó	   bytes */3©rV  rÇ   rr  N©r   rb  rc  r<  r½   rF  r#   rA  ©r)   r(   rY  r   rW   s        r*   Ú/test_singleUnsatisfiableRangeSetsContentHeadersÚGStaticMakeProducerTests.test_singleUnsatisfiableRangeSetsContentHeadersÍ  s’   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨H°mÔDØ"ˆØ×/Ñ/°¸[Ð/ÐIˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×Ñà%2Ø'+Ø&2ñð
 ×#Ñ# GÓ,ô÷ '×&Ö&úó   Á8BÂ
Bc                 ó:  • [        / 5      nUR                  R                  SS5        SnU R                  SUS9nUR                  " 5        nUR
                  " X5        U R                  SSSS	.U R                  U5      5        S
S
S
5        g
! , (       d  f       g
= f)z�
makeProducer when the Range header requests a single byte range that
partly overlaps the resource sets the Content-* headers appropriately.
r^  s
   bytes=2-10rQ  rw  r€  r�  ó   1s   bytes 2-2/3r„  Nr…  r†  s        r*   Ú6test_singlePartiallyOverlappingRangeSetsContentHeadersÚNStaticMakeProducerTests.test_singlePartiallyOverlappingRangeSetsContentHeadersá  s’   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨H°mÔDØ"ˆØ×/Ñ/°¸[Ð/ÐIˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×Ñà%2Ø'+Ø&4ñð
 ×#Ñ# GÓ,ô÷ '×&Ö&úr‰  c                 ó.  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5      nU R                  U[        R                  5        SSS5        g! , (       d  f       g= f)zu
makeProducer when the Range header requests a single byte range
returns an instance of MultipleRangeStaticProducer.
r^  ó   bytes=1-3,5-6r`  N©	r   rb  rc  r<  r½   rF  rw   r   ÚMultipleRangeStaticProducerre  s        r*   Ú2test_multipleRangeGivesMultipleRangeStaticProducerÚJStaticMakeProducerTests.test_multipleRangeGivesMultipleRangeStaticProducerõ  su   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨HÐ6FÔGØ×/Ñ/°	Ó:ˆØ×$Ò$Ô&¨$Ø×,Ò,¨WÓ;ˆHØ×!Ñ! (¬F×,NÑ,NÔO÷ '×&Ö&úrh  c                 óB  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5        U R                  [        R                  UR                  5        SSS5        g! , (       d  f       g= f)zŒ
makeProducer when the Range header requests a multiple satisfiable
byte ranges sets the response code on the request to 'Partial
Content'.
r^  r�  r`  Nrj  rl  s       r*   Ú'test_multipleRangeSets206PartialContentÚ?StaticMakeProducerTests.test_multipleRangeSets206PartialContent  sy   € ô ˜rÓ"ˆØ×Ñ×+Ñ+¨HÐ6FÔGØ×/Ñ/°	Ó:ˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×ÑœT×1Ñ1°7×3GÑ3GÔH÷ '×&Ö&úro  c                 ó‚  • [        / 5      nUR                  R                  SS5        U R                  SSS9nUR                  " 5        nUR
                  " X5      nU R                  U5      nU R                  SS1[        UR                  5       5      5        SnUR                   H  u  pxn	U[        U5      -  nM     U R                  S	U4-  US   5        U R                  SU5        US   n
U R                  S
[        R                  " SU
5      5        U R!                  SU5        S
S
S
5        g
! , (       d  f       g
= f)rq  r^  r�  s   abcdefghijklrR  )r9  rÇ   rV  é   rU  Ns(   multipart/byteranges; boundary="[^"]*"\ZrW  )r   rb  rc  r<  r½   rF  rA  r#   ÚsetÚkeysÚ	rangeInforT   ÚassertInÚassertNotIdenticalÚreÚmatchÚassertNotIn)r)   r(   r   rW   rH  rA  ÚexpectedLengthÚboundaryÚoffsetÚsizerY  s              r*   Ú#test_mutipleRangeSetsContentHeadersÚ;StaticMakeProducerTests.test_mutipleRangeSetsContentHeaders  s2  € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨HÐ6FÔGØ×/Ñ/°È&Ð/ÐQˆØ×$Ò$Ô&¨$Ø×,Ò,¨WÓ;ˆHØ!×0Ñ0°Ó9ˆNà×ÑØ" OÐ4´c¸.×:MÑ:MÓ:OÓ6Pôð ˆNØ*2×*<Ô*<Ñ&� $Ø¤# h£-Ñ/’ñ +=à×ÑØ˜Ð)Ñ)¨>Ð:KÑ+Lôð
 �M‰M˜/¨>Ô:Ø(¨Ñ9ˆKØ×#Ñ#ØÜ—’ÐEÀ{ÓSôð ×ÑÐ0°.ÔA÷3 '×&Ö&ús   Á	CD0Ä0
D>c                 ó.  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5      nU R                  U[        R                  5        SSS5        g! , (       d  f       g= f)z—
makeProducer still returns an instance of L{SingleRangeStaticProducer}
when the Range header requests multiple ranges, none of which are
satisfiable.
r^  ó   bytes=10-12,15-20rw  Nr�  re  s        r*   ÚBtest_multipleUnsatisfiableRangesReturnsMultipleRangeStaticProducerÚZStaticMakeProducerTests.test_multipleUnsatisfiableRangesReturnsMultipleRangeStaticProducer1  su   € ô ˜rÓ"ˆØ×Ñ×+Ñ+¨HÐ6JÔKØ×/Ñ/°Ó7ˆØ×$Ò$Ô&¨$Ø×,Ò,¨WÓ;ˆHØ×!Ñ! (¬F×,NÑ,NÔO÷ '×&Ö&úrh  c                 óB  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5        U R                  [        R                  UR                  5        SSS5        g! , (       d  f       g= f)z«
makeProducer sets the response code of the request to of 'Requested
Range Not Satisfiable' when the Range header requests multiple ranges,
none of which are satisfiable.
r^  r¨  rw  Nr{  rl  s       r*   ÚBtest_multipleUnsatisfiableRangesSets416ReqestedRangeNotSatisfiableÚZStaticMakeProducerTests.test_multipleUnsatisfiableRangesSets416ReqestedRangeNotSatisfiable>  sy   € ô ˜rÓ"ˆØ×Ñ×+Ñ+¨HÐ6JÔKØ×/Ñ/°Ó7ˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×ÑœT×AÑAÀ7×CWÑCWÔX÷ '×&Ö&úro  c                 ór  • [        / 5      nUR                  R                  SS5        SnUR                  R                  SS5        U R                  SUS9nUR                  " 5        nUR
                  " X5        U R                  SSS	S
.U R                  U5      5        SSS5        g! , (       d  f       g= f)z‡
makeProducer when the Range header requests multiple ranges, none of
which are satisfiable, sets the Content-* headers appropriately.
r^  rv  rQ  r¨  rw  r€  r‚  rƒ  r�  )rÇ   rr  rV  Nr…  r†  s        r*   Ú1test_multipleUnsatisfiableRangeSetsContentHeadersÚIStaticMakeProducerTests.test_multipleUnsatisfiableRangeSetsContentHeadersK  s©   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨H°mÔDØ"ˆØ×Ñ×+Ñ+¨HÐ6JÔKØ×/Ñ/°¸[Ð/ÐIˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×Ñà'+Ø&2Ø%2ñð
 ×#Ñ# GÓ,ô÷ '×&Ö&ús   Á'8B(Â(
B6c                 óB  • [        / 5      nUR                  R                  SS5        U R                  S5      nUR                  " 5        nUR
                  " X5        U R                  [        R                  UR                  5        SSS5        g! , (       d  f       g= f)zŠ
makeProducer when the Range header requests multiple ranges, at least
one of which matches, sets the response code to 'Partial Content'.
r^  s   bytes=1-3,100-200r`  Nrj  rl  s       r*   Ú test_oneSatisfiableRangeIsEnoughÚ8StaticMakeProducerTests.test_oneSatisfiableRangeIsEnough`  sy   € ô
 ˜rÓ"ˆØ×Ñ×+Ñ+¨HÐ6JÔKØ×/Ñ/°	Ó:ˆØ×$Ò$Ô&¨$Ø×!Ò! 'Ô0Ø×ÑœT×1Ñ1°7×3GÑ3GÔH÷ '×&Ö&úro  r;   )NN)r<   r=   r>   r?   r@   r<  rA  rI  rM  r[  rf  rm  rs  rx  r}  r‡  rŒ  r’  r•  r¥  r©  r¬  r¯  r²  rA   r;   r!   r*   r6  r6  7  sr   † ñôòò	Jò	<òò.
Nò
Iòò0
NòYòò(ò(
PòIò!BòFPòYòõ*
Ir!   r6  c                   ó$   • \ rS rSrSrS rS rSrg)ÚStaticProducerTestsim  z+
Tests for the abstract L{StaticProducer}.
c                 óœ   • [        5       n[        R                  " SU5      nUR                  5         U R	                  UR
                  5        g)z]
L{StaticProducer.stopProducing} closes the file object the producer is
producing data from.
N)r  r   ÚStaticProducerÚstopProducingr#  r$  ©r)   Ú
fileObjectrH  s      r*   Útest_stopProducingClosesFileÚ0StaticProducerTests.test_stopProducingClosesFiler  s;   € ô
 “Zˆ
Ü×(Ò(¨¨zÓ:ˆØ×ÑÔ Ø�‰˜
×)Ñ)Õ*r!   c                 ó°   • [        5       n[        R                  " [        / 5      U5      nUR	                  5         U R                  SUR                  5        g)zª
L{StaticProducer.stopProducing} sets the request instance variable to
None, which indicates to subclasses' resumeProducing methods that no
more data should be produced.
N)r  r   r·  r   r¸  ÚassertIdenticalr(   r¹  s      r*   Ú#test_stopProducingSetsRequestToNoneÚ7StaticProducerTests.test_stopProducingSetsRequestToNone|  sD   € ô “Zˆ
Ü×(Ò(¬°bÓ)9¸:ÓFˆØ×ÑÔ Ø×Ñ˜T 8×#3Ñ#3Õ4r!   r;   N)r<   r=   r>   r?   r@   r»  r¿  rA   r;   r!   r*   rµ  rµ  m  s   † ñò+õ	5r!   rµ  c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚNoRangeStaticProducerTestsiˆ  z%
Tests for L{NoRangeStaticProducer}.
c                 ób   • [        [        R                  [        R                  " SS5      5        g)z7
L{NoRangeStaticProducer} implements L{IPullProducer}.
N)r   r   ÚIPullProducerr   rG  r¤   s    r*   Útest_implementsIPullProducerÚ7NoRangeStaticProducerTests.test_implementsIPullProducer�  s"   € ô 	”Z×-Ñ-¬v×/KÒ/KÈDÐRVÓ/WÕXr!   c                 óÔ   • [        / 5      nSn[        R                  " U[        U5      5      nUR	                  5         U R                  USR                  UR                  5      5        g)z[
L{NoRangeStaticProducer.resumeProducing} writes content from the
resource to the request.
r`  r!   N)r   r   rG  r  Ústartr#   r$   r%   ©r)   r(   rÝ   rH  s       r*   Ú#test_resumeProducingProducesContentÚ>NoRangeStaticProducerTests.test_resumeProducingProducesContent“  sS   € ô
 ˜rÓ"ˆØˆÜ×/Ò/°¼À'Ó9JÓKˆð 	�‰ÔØ×Ñ˜ #§(¡(¨7¯?©?Ó";Õ<r!   c                 ó   • [        / 5      n[        R                  R                  nSSU-  S-   -  n[        R
                  " U[        U5      5      nUR                  5         USU X2SU-   USU-  S /nU R                  XQR                  5        g)z�
L{NoRangeStaticProducer.start} writes at most
C{abstract.FileDescriptor.bufferSize} bytes of content from the
resource to the request at once.
rS  é   rK   r   N)
r   r   ÚFileDescriptorÚ
bufferSizer   rG  r  rÈ  r#   r%   ©r)   r(   rÏ  rÝ   rH  Úexpecteds         r*   Ú!test_resumeProducingBuffersOutputÚ<NoRangeStaticProducerTests.test_resumeProducingBuffersOutput   s•   € ô ˜rÓ"ˆÜ×,Ñ,×7Ñ7ˆ
Ø˜!˜j™.¨1Ñ,Ñ-ˆÜ×/Ò/°¼À'Ó9JÓKˆð 	�‰Ôà�A�jÐ!Ø  Z¡Ð0Ø�A˜
‘NÐ$Ð%ð
ˆð
 	×Ñ˜§?¡?Õ3r!   c                 óú   • [        / 5      nUR                  5       n/ nUR                  UR                  5        [        R
                  " U[        S5      5      nUR                  5         U R                  S/U5        g)zl
L{NoRangeStaticProducer.resumeProducing} calls finish() on the request
after it is done producing content.
r`  N)	r   ÚnotifyFinishr0   Úappendr   rG  r  rÈ  r#   ©r)   r(   ÚfinishDeferredÚcallbackListrH  s        r*   Útest_finishCalledWhenDoneÚ4NoRangeStaticProducerTests.test_finishCalledWhenDone´  sj   € ô
 ˜rÓ"ˆØ ×-Ñ-Ó/ˆØˆØ×"Ñ" <×#6Ñ#6Ô7Ü×/Ò/°¼À)Ó9LÓMˆð 	�‰ÔØ×Ñ˜$˜ Õ.r!   r;   N©
r<   r=   r>   r?   r@   rÅ  rÊ  rÒ  rÚ  rA   r;   r!   r*   rÂ  rÂ  ˆ  s   † ñòYò=ò4õ(/r!   rÂ  c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚSingleRangeStaticProducerTestsiÄ  z)
Tests for L{SingleRangeStaticProducer}.
c           	      óf   • [        [        R                  [        R                  " SSSS5      5        g)z;
L{SingleRangeStaticProducer} implements L{IPullProducer}.
N)r   r   rÄ  r   rd  r¤   s    r*   rÅ  Ú;SingleRangeStaticProducerTests.test_implementsIPullProducerÉ  s)   € ô 	Ü×$Ñ$Ü×,Ò,¨T°4¸¸tÓDõ	
r!   c                 óÞ   • [        / 5      nSn[        R                  " U[        U5      SS5      nUR	                  5         U R                  USS SR                  UR                  5      5        g)z’
L{SingleRangeStaticProducer.resumeProducing} writes the given amount
of content, starting at the given offset, from the resource to the
request.
r`  rK   é   é   r!   N)r   r   rd  r  rÈ  r#   r$   r%   rÉ  s       r*   rÊ  ÚBSingleRangeStaticProducerTests.test_resumeProducingProducesContentÒ  s_   € ô ˜rÓ"ˆØˆÜ×3Ò3°G¼XÀgÓ=NÐPQÐSTÓUˆð 	�‰ÔØ×Ñ˜  1˜ s§x¡x°·±Ó'@ÕAr!   c                 ó  • [        / 5      n[        R                  R                  nSU-  n[        R
                  " U[        U5      SUS-   5      nUR                  5         USUS-    X2S-   US-    /nU R                  XQR                  5        g)z”
L{SingleRangeStaticProducer.start} writes at most
C{abstract.FileDescriptor.bufferSize} bytes of content from the
resource to the request at once.
rw  rK   é
   é   N)
r   r   rÎ  rÏ  r   rd  r  rÈ  r#   r%   rÐ  s         r*   rÒ  Ú@SingleRangeStaticProducerTests.test_resumeProducingBuffersOutputà  s�   € ô ˜rÓ"ˆÜ×,Ñ,×7Ñ7ˆ
Ø˜:Ñ%ˆÜ×3Ò3Ø”X˜gÓ&¨¨:¸©?ó
ˆð
 	�‰Ôà�A˜
 Q™Ð'Ø ‘N Z°"¡_Ð5ð
ˆð 	×Ñ˜§?¡?Õ3r!   c                 óþ   • [        / 5      nUR                  5       n/ nUR                  UR                  5        [        R
                  " U[        S5      SS5      nUR                  5         U R                  S/U5        g)zp
L{SingleRangeStaticProducer.resumeProducing} calls finish() on the
request after it is done producing content.
r`  rK   N)	r   rÕ  r0   rÖ  r   rd  r  rÈ  r#   r×  s        r*   rÚ  Ú8SingleRangeStaticProducerTests.test_finishCalledWhenDoneõ  sp   € ô
 ˜rÓ"ˆØ ×-Ñ-Ó/ˆØˆØ×"Ñ" <×#6Ñ#6Ô7Ü×3Ò3°G¼XÀiÓ=PÐRSÐUVÓWˆð 	�‰ÔØ×Ñ˜$˜ Õ.r!   r;   NrÜ  r;   r!   r*   rÞ  rÞ  Ä  s   † ñò
òBò4õ*/r!   rÞ  c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	Ú MultipleRangeStaticProducerTestsi  z+
Tests for L{MultipleRangeStaticProducer}.
c                 ód   • [        [        R                  [        R                  " SSS5      5        g)z=
L{MultipleRangeStaticProducer} implements L{IPullProducer}.
N)r   r   rÄ  r   r‘  r¤   s    r*   rÅ  Ú=MultipleRangeStaticProducerTests.test_implementsIPullProducer
  s'   € ô 	Ü×$Ñ$Ü×.Ò.¨t°T¸4Ó@õ	
r!   c                 óÚ   • [        / 5      nSn[        R                  " U[        U5      SS/5      nUR	                  5         U R                  SSR                  UR                  5      5        g)z­
L{MultipleRangeStaticProducer.resumeProducing} writes the requested
chunks of content from the resource to the request, with the supplied
boundaries in between each chunk.
r`  )r‹  rK   râ  )ó   2r˜  rK   s   1bcd2fr!   N)r   r   r‘  r  rÈ  r#   r$   r%   rÉ  s       r*   rÊ  ÚDMultipleRangeStaticProducerTests.test_resumeProducingProducesContent  s]   € ô ˜rÓ"ˆØˆÜ×5Ò5Ø”X˜gÓ&¨°|Ð(Dó
ˆð
 	�‰ÔØ×Ñ˜ C§H¡H¨W¯_©_Ó$=Õ>r!   c                 óú   • [        / 5      nSn[        R                  " U[        U5      / SQ5      nSUl        UR                  5         SUSS -   S-   USS	 -   US	S
 S-   /nU R                  XAR                  5        g)aB  
L{MultipleRangeStaticProducer.start} writes about
C{abstract.FileDescriptor.bufferSize} bytes of content from the
resource to the request at once.

To be specific about the 'about' above: it can write slightly more,
for example in the case where the first boundary plus the first chunk
is less than C{bufferSize} but first boundary plus the first chunk
plus the second boundary is more, but this is unimportant as in
practice the boundaries are fairly small.  On the other side, it is
important for performance to bundle up several small chunks into one
call to request.write.
s   01234567890123456789))rS  r   rÍ  )ó   br˜  ræ  )ó   cr   r   ræ  rS  r   rÍ  ró  r˜  rç  é   rô  N)r   r   r‘  r  rÏ  rÈ  r#   r%   )r)   r(   rÝ   rH  rÑ  s        r*   rÒ  ÚBMultipleRangeStaticProducerTests.test_resumeProducingBuffersOutput#  s�   € ô ˜rÓ"ˆØ#ˆÜ×5Ò5Ø”X˜gÓ&Ò(Só
ˆð !ˆÔð 	�‰Ôà�7˜1˜Q�<Ñ $Ñ&¨°°2¨Ñ6Ø�B�rˆN˜TÑ!ð
ˆð 	×Ñ˜§?¡?Õ3r!   c                 óþ   • [        / 5      nUR                  5       n/ nUR                  UR                  5        [        R
                  " U[        S5      S/5      nUR                  5         U R                  S/U5        g)zr
L{MultipleRangeStaticProducer.resumeProducing} calls finish() on the
request after it is done producing content.
r`  )r!   rK   rÍ  N)	r   rÕ  r0   rÖ  r   r‘  r  rÈ  r#   r×  s        r*   rÚ  Ú:MultipleRangeStaticProducerTests.test_finishCalledWhenDone@  sq   € ô
 ˜rÓ"ˆØ ×-Ñ-Ó/ˆØˆØ×"Ñ" <×#6Ñ#6Ô7Ü×5Ò5Ø”X˜iÓ(¨;¨-ó
ˆð
 	�‰ÔØ×Ñ˜$˜ Õ.r!   r;   NrÜ  r;   r!   r*   rì  rì    s   † ñò
ò?ò 4õ:/r!   rì  c                   ó–   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rSrg)Ú
RangeTestsiR  a¤  
Tests for I{Range-Header} support in L{twisted.web.static.File}.

@type file: L{file}
@ivar file: Temporary (binary) file containing the content to be served.

@type resource: L{static.File}
@ivar resource: A leaf web resource using C{file} as content.

@type request: L{DummyRequest}
@ivar request: A fake request, requesting C{resource}.

@type catcher: L{list}
@ivar catcher: List which gathers all log information.
c                 óò  • [        U R                  5       5      nSU l        UR                  U R                  5        UR	                  5       U l        [        R                  " U R
                  R                  5      U l	        SU R                  l
        [        S/5      U l        U R
                  R                  U R                  l        / U l        [        R                   " U R                  R"                  5        g)zï
Create a temporary file with a fixed payload of 64 bytes.  Create a
resource for that file and create a request which will be for that
resource.  Each test can set a different range header to test different
aspects of the implementation.
s@   øuóEŒ7Î ž¶a0y0Sðï¬·¾µM6k{¾	Ð¼kYõI¸ˆoZ…bÍkò&ý%Ý‚q/AY‹rK   r!   N)r   rS   Úpayloadrb   r   rW   r   rR   rà   r   ÚisLeafr   r(   r  Úcatcherr	   ÚaddObserverrÖ  )r)   rc   s     r*   ÚsetUpÚRangeTests.setUpc  s¢   € ô ˜Ÿ™›Ó&ˆð*ð 	Œð 	�‰˜Ÿ™Ô%Ø—I‘I“KˆŒ	ÜŸš D§I¡I§N¡NÓ3ˆŒØ ˆ�‰ÔÜ# S EÓ*ˆŒØŸ9™9Ÿ>™>ˆ�‰ÔØˆŒÜ�Š˜Ÿ™×+Ñ+Õ,r!   c                 óŒ   • U R                   R                  5         [        R                  " U R                  R
                  5        g)z2
Clean up the resource file and the log observer.
N)rW   r€   r	   ÚremoveObserverrþ  rÖ  r¤   s    r*   ÚtearDownÚRangeTests.tearDown  s*   € ð 	�	‰	�‰ÔÜ×Ò˜4Ÿ<™<×.Ñ.Õ/r!   c                 óª   • U R                   R                  5       nU R                  US   S   U5        U R                  U R                   / SU< 35        g)zE
Asserts that a given log message occurred with an expected message.
Úmessager   zAn additional log occurred: N)rþ  Úpopr#   )r)   rÑ  ÚlogItems      r*   Ú_assertLoggedÚRangeTests._assertLogged†  sN   € ð —,‘,×"Ñ"Ó$ˆØ×Ñ˜ Ñ+¨AÑ.°Ô9Ø×Ñ˜Ÿ™ rÐ-IÈ'ÉÐ+UÕVr!   c                 ór  • U R                   R                  nU R                  [        US5        U R                  [        US5        U R                  [        US5        U R                  [        US5        U R                  [        US5        U R                  [        US5        U R                  [        US5        g)	z_
L{File._parseRangeHeader} raises L{ValueError} when passed
syntactically invalid byte ranges.
s   bytess   unknown=1-2s   bytes=3s   bytes=-s
   bytes=foo-s
   bytes=-foos	   bytes=5-4N)r   Ú_parseRangeHeaderr7   Ú
ValueError)r)   Úfs     r*   Útest_invalidRangesÚRangeTests.test_invalidRangesŽ  sŸ   € ð
 �M‰M×+Ñ+ˆð 	×Ñœ* a¨Ô2ð 	×Ñœ* a¨Ô8ð 	×Ñœ* a¨Ô4ð 	×Ñœ* a¨Ô4ð 	×Ñœ* a¨Ô7ð 	×Ñœ* a¨Ô7ð 	×Ñœ* a¨Õ6r!   c                 ó\   • U R                  U R                  R                  S5      S/5        g)zz
A single bytes range without an explicit stop position is parsed into a
two-tuple giving the start position and L{None}.
s   bytes=0-)r   NN©r#   r   r  r¤   s    r*   Útest_rangeMissingStopÚ RangeTests.test_rangeMissingStopª  ó%   € ð
 	×Ñ˜Ÿ™×8Ñ8¸ÓEÈ	À{ÕSr!   c                 ó\   • U R                  U R                  R                  S5      S/5        g)zu
A single bytes range without an explicit start position is parsed into
a two-tuple of L{None} and the end position.
s   bytes=-3)Nrâ  Nr  r¤   s    r*   Útest_rangeMissingStartÚ!RangeTests.test_rangeMissingStart±  r  r!   c                 ó\   • U R                  U R                  R                  S5      S/5        g)zl
A single bytes range with explicit start and stop positions is parsed
into a two-tuple of those positions.
s	   bytes=2-5)rÍ  r˜  Nr  r¤   s    r*   Ú
test_rangeÚRangeTests.test_range¸  s%   € ð
 	×Ñ˜Ÿ™×8Ñ8¸ÓFÈÈÕQr!   c                 ó  • U R                  U R                  R                  S5      S/5        U R                  U R                  R                  S5      S/5        U R                  U R                  R                  S5      S/5        U R                  U R                  R                  S5      S/5        U R                  U R                  R                  S5      S/5        U R                  U R                  R                  S5      S/5        g)	zy
A single bytes range with whitespace in allowed places is parsed in
the same way as it would be without the whitespace.
s    bytes=1-2 ©rK   rÍ  s   bytes =1-2 s
   bytes= 1-2s
   bytes=1 -2s
   bytes=1- 2s
   bytes=1-2 Nr  r¤   s    r*   Útest_rangeWithSpaceÚRangeTests.test_rangeWithSpace¿  sÊ   € ð
 	×Ñ˜Ÿ™×8Ñ8¸ÓHÈ6È(ÔSØ×Ñ˜Ÿ™×8Ñ8¸ÓHÈ6È(ÔSØ×Ñ˜Ÿ™×8Ñ8¸ÓGÈ&ÈÔRØ×Ñ˜Ÿ™×8Ñ8¸ÓGÈ&ÈÔRØ×Ñ˜Ÿ™×8Ñ8¸ÓGÈ&ÈÔRØ×Ñ˜Ÿ™×8Ñ8¸ÓGÈ&ÈÕRr!   c                 ó\   • U R                  U R                  R                  S5      S/5        g)z{
If there are multiple byte ranges but only one is non-null, the
non-null range is parsed and its start and stop returned.
s   bytes=1-2,
, ,	r  Nr  r¤   s    r*   Útest_nullRangeElementsÚ!RangeTests.test_nullRangeElementsË  s)   € ð
 	×ÑØ�M‰M×+Ñ+Ð,BÓCÀfÀXõ	
r!   c                 ó^   • U R                  U R                  R                  S5      SS/5        g)zL
If multiple byte ranges are specified their starts and stops are
returned.
s   bytes=1-2,3-4r  )râ  rã  Nr  r¤   s    r*   Útest_multipleRangesÚRangeTests.test_multipleRangesÔ  s,   € ð
 	×ÑØ�M‰M×+Ñ+Ð,<Ó=ÀÈÐ?Oõ	
r!   c                 ó  • U R                   R                  R                  SS5        U R                  R	                  U R                   5        U R                  [        SR                  U R                   R                  5      5      S5        g)zX
A correct response to a range request is as long as the length of the
requested range.
r^  s
   bytes=0-43r!   é,   N)	r(   rb  rc  r   r8   r#   rT   r$   r%   r¤   s    r*   Útest_bodyLengthÚRangeTests.test_bodyLengthÝ  s\   € ð
 	�‰×#Ñ#×0Ñ0°¸=ÔIØ�‰×Ñ˜TŸ\™\Ô*Ø×Ñœ˜SŸX™X d§l¡l×&:Ñ&:Ó;Ó<¸bÕAr!   c                 ól  • SnU R                   R                  R                  SU5        U R                  R	                  U R                   5        SUR                  5       < 3nU R                  U5        U R                  SR                  U R                   R                  5      U R                  5        U R                  U R                   R                  [        R                  5        U R                  U R                   R                  R                  S5      S   S[!        U R                  5      4-  5        g)	zþ
An incorrect range request (RFC 2616 defines a correct range request as
a Bytes-Unit followed by a '=' character followed by a specific range.
Only 'bytes' is defined) results in the range header value being logged
and a normal 200 response being sent.
s   foobar=0-43r^  z Ignoring malformed Range header r!   rÇ   r   rU  N)r(   rb  rc  r   r8   r�   r
  r#   r$   r%   rü  rk   r   rL  rÊ   rË   rT   )r)   ÚrangerÑ  s      r*   Útest_invalidRangeRequestÚ#RangeTests.test_invalidRangeRequestæ  sß   € ð ˆØ�‰×#Ñ#×0Ñ0°¸5ÔAØ�‰×Ñ˜TŸ\™\Ô*Ø5°e·l±l³nÑ5GÐHˆØ×Ñ˜8Ô$Ø×Ñ˜Ÿ™ $§,¡,×"6Ñ"6Ó7¸¿¹ÔFØ×Ñ˜Ÿ™×2Ñ2´D·G±GÔ<Ø×ÑØ�L‰L×(Ñ(×6Ñ6Ð7HÓIÈ!ÑLØ”S˜Ÿ™Ó&Ð(Ñ(õ	
r!   c                 óp  • SU-   nUR                  U5      nU R                  SUS   5        U R                  SUS   5        / nUSS  Hê  nUR                  SS5      u  pxpšnUS	-   U	-   nU R                  SU5        U R                  SU
5        [        R                  " S
U[        R                  [        R
                  -  5      R                  S5      n[        R                  " SU[        R                  [        R
                  -  5      R                  5       u  pïnUR                  UXïU4US.5        Mì     U$ )z�
Parse C{body} as a multipart MIME response separated by C{boundary}.

Note that this with fail the calling test on certain syntactic
problems.
s   
--r!   r   s   --
éÿÿÿÿrK   s   
rã  ó   
s   ^content-type: (.*)$s1   ^content-range: bytes ([0-9]+)-([0-9]+)/([0-9]+)$)ó   contentTypeó   contentRangeó   body)	Úsplitr#   rž  ÚsearchÚIÚMÚgroupÚgroupsrÖ  )r)   Úbodyr¢  ÚsepÚpartsÚparsed_partsÚpartÚbeforeÚheader1Úheader2ÚblankÚpartBodyÚheadersÚpartContentTypeValuerÈ  Úendr¤  s                    r*   ÚparseMultipartBodyÚRangeTests.parseMultipartBodyù  s*  € ð ˜(Ñ"ˆØ—
‘
˜3“ˆØ×Ñ˜˜e A™hÔ'Ø×Ñ˜ E¨"¡IÔ.ØˆØ˜!˜B“KˆDØ8<¿
¹
À7ÈAÓ8NÑ5ˆF˜W¨XØ ‘o¨Ñ/ˆGØ×Ñ˜S &Ô)Ø×Ñ˜S %Ô(Ü#%§9¢9Ø'¨´"·$±$¼¿¹±+ó$ç‰e�A‹hð !ô  "ŸyšyØDØÜ—‘”r—t‘t‘ó ÷ ‰f‹hñ	 ˆE˜ð
 ×Ñà$8Ø&+°$Ð%7Ø%ñöñ  ð( Ðr!   c                 óŠ  • / SQnSR                  U VVs/ s H  u  p#[        U SU 35      PM     snn5      nU R                  R                  R	                  SSU-   5        U R
                  R                  U R                  5        U R                  U R                  R                  [        R                  5        [        R                  " SU R                  R                  R                  S5      S   5      R                  S	5      nU R!                  S
R                  U R                  R"                  5      U5      nU R                  [%        U5      [%        U5      5        ['        Xa5       HÏ  u  nu  p#U R                  [        U R
                  R(                  5      US   5        US   u  p‰n
U R                  [+        U5      U5        U R                  [+        U	5      U5        U R                  [+        U
5      U R
                  R-                  5       5        U R                  U R.                  X#S	-    US   5        MÑ     gs  snnf )zW
The response to a request for multiple bytes ranges is a MIME-ish
multipart response.
)©r   rÍ  )é   é   )é(   é2   ó   ,Ú-r^  ó   bytes=ó'   ^multipart/byteranges; boundary="(.*)"$rV  r   rK   r!   r2  r3  r4  N)r$   r
   r(   rb  rc  r   r8   r#   rk   r   rk  rž  rŸ  rÊ   rË   r9  rH  r%   rT   Úzipr:  ÚintÚgetFileSizerü  ©r)   Ú	startEndsÚsÚeÚrangeHeaderValuer¢  r=  r?  rÈ  rG  r¤  s              r*   Útest_multipleRangeRequestÚ$RangeTests.test_multipleRangeRequest  sÆ  € ò
 1ˆ	ØŸ9™9Ù5>Ô?²Y©6¨AŒ]˜a˜S  ! ˜:Ö&±YÒ?ó
Ðð 	�‰×#Ñ#×0Ñ0°¸9ÐGWÑ;WÔXØ�‰×Ñ˜TŸ\™\Ô*Ø×Ñ˜Ÿ™×2Ñ2´D×4HÑ4HÔIÜ—8’8Ø6Ø�L‰L×(Ñ(×6Ñ6°ÓGÈÑJó
÷ ‰%�‹(ð 	ð ×'Ñ'¨¯©°·±×1EÑ1EÓ(FÈÓQˆØ×Ñœ˜Y›¬¨U«Ô4Ü Ö1‰LˆD‘&�1Ø×Ñœ]¨4¯=©=×+=Ñ+=Ó>ÀÀ^Ñ@TÔUØ# OÑ4ÑˆE˜Ø×ÑœS ›Z¨Ô+Ø×ÑœS ›X qÔ)Ø×ÑœS ›Y¨¯©×(AÑ(AÓ(CÔDØ×Ñ˜TŸ\™\¨!°!©eÐ4°d¸7±mÖDò 2ùó @s   •H?
c                 ó  • SS[        U R                  5      S-   4/nSR                  U VVs/ s H  u  p#[        U SU 35      PM     snn5      nU R                  R
                  R                  SSU-   5        U R                  R                  U R                  5        U R                  U R                  R                  [        R                  5        [        R                  " SU R                  R                  R!                  S	5      S
   5      R#                  S5      nU R%                  SR                  U R                  R&                  5      U5      nU R                  [        U5      [        U5      5        [)        Xa5       Hó  u  nu  p#U R                  [        U R                  R*                  5      US   5        US   u  p‰n
U R                  [-        U5      U5        U R                  [-        U	5      [/        X0R                  R1                  5       S-
  5      5        U R                  [-        U
5      U R                  R1                  5       5        U R                  U R                  X#S-    US   5        Mõ     gs  snnf )z–
The response to a request for multiple bytes ranges is a MIME-ish
multipart response, even when one of the ranged falls off the end of
the resource.
rK  rN  ræ  rP  rQ  r^  rR  rS  rV  r   rK   r!   r2  r3  r4  N)rT   rü  r$   r
   r(   rb  rc  r   r8   r#   rk   r   rk  rž  rŸ  rÊ   rË   r9  rH  r%   rT  r:  rU  ÚminrV  rW  s              r*   Ú0test_multipleRangeRequestWithRangeOverlappingEndÚ;RangeTests.test_multipleRangeRequestWithRangeOverlappingEnd5  sõ  € ð ˜b¤# d§l¡lÓ"3°bÑ"8Ð9Ð:ˆ	ØŸ9™9Ù5>Ô?²Y©6¨AŒ]˜a˜S  ! ˜:Ö&±YÒ?ó
Ðð 	�‰×#Ñ#×0Ñ0°¸9ÐGWÑ;WÔXØ�‰×Ñ˜TŸ\™\Ô*Ø×Ñ˜Ÿ™×2Ñ2´D×4HÑ4HÔIÜ—8’8Ø6Ø�L‰L×(Ñ(×6Ñ6°ÓGÈÑJó
÷ ‰%�‹(ð 	ð ×'Ñ'¨¯©°·±×1EÑ1EÓ(FÈÓQˆØ×Ñœ˜Y›¬¨U«Ô4Ü Ö1‰LˆD‘&�1Ø×Ñœ]¨4¯=©=×+=Ñ+=Ó>ÀÀ^Ñ@TÔUØ# OÑ4ÑˆE˜Ø×ÑœS ›Z¨Ô+Ø×ÑœS ›X¤s¨1¯m©m×.GÑ.GÓ.IÈAÑ.MÓ'NÔOØ×ÑœS ›Y¨¯©×(AÑ(AÓ(CÔDØ×Ñ˜TŸ\™\¨!°!©eÐ4°d¸7±mÖDò 2ùó @s   ­I;
c                 óâ  • U R                   R                  R                  SS5        U R                  R	                  U R                   5        U R                  SR                  U R                   R                  5      U R                  SS 5        U R                  [        SR                  U R                   R                  5      5      S5        U R                  U R                   R                  [        R                  5        U R                  U R                   R                  R                  S5      S   S	5        U R                  U R                   R                  R                  S
5      S   S5        g)z‚
If the end byte position is omitted, then it is treated as if the
length of the resource was specified by the end byte position.
r^  s	   bytes=23-r!   é   Né)   rr  r   s   bytes 23-63/64rÇ   s   41©r(   rb  rc  r   r8   r#   r$   r%   rü  rT   rk   r   rk  rÊ   rË   r¤   s    r*   Útest_implicitEndÚRangeTests.test_implicitEndP  s	  € ð
 	�‰×#Ñ#×0Ñ0°¸<ÔHØ�‰×Ñ˜TŸ\™\Ô*Ø×Ñ˜Ÿ™ $§,¡,×"6Ñ"6Ó7¸¿¹ÀbÀcÐ9JÔKØ×Ñœ˜SŸX™X d§l¡l×&:Ñ&:Ó;Ó<¸bÔAØ×Ñ˜Ÿ™×2Ñ2´D×4HÑ4HÔIØ×ÑØ�L‰L×(Ñ(×6Ñ6Ð7GÓHÈÑKØô	
ð 	×ÑØ�L‰L×(Ñ(×6Ñ6Ð7HÓIÈ!ÑLÈeõ	
r!   c                 óâ  • U R                   R                  R                  SS5        U R                  R	                  U R                   5        U R                  SR                  U R                   R                  5      U R                  SS 5        U R                  [        SR                  U R                   R                  5      5      S5        U R                  U R                   R                  [        R                  5        U R                  U R                   R                  R                  S5      S   S	5        U R                  U R                   R                  R                  S
5      S   S5        g)z»
If the start byte position is omitted but the end byte position is
supplied, then the range is treated as requesting the last -N bytes of
the resource, where N is the end byte position.
r^  s	   bytes=-17r!   iïÿÿÿNé   rr  r   s   bytes 47-63/64rÇ   s   17re  r¤   s    r*   Útest_implicitStartÚRangeTests.test_implicitStartb  s	  € ð 	�‰×#Ñ#×0Ñ0°¸<ÔHØ�‰×Ñ˜TŸ\™\Ô*Ø×Ñ˜Ÿ™ $§,¡,×"6Ñ"6Ó7¸¿¹ÀcÀdÐ9KÔLØ×Ñœ˜SŸX™X d§l¡l×&:Ñ&:Ó;Ó<¸bÔAØ×Ñ˜Ÿ™×2Ñ2´D×4HÑ4HÔIØ×ÑØ�L‰L×(Ñ(×6Ñ6Ð7GÓHÈÑKØô	
ð 	×ÑØ�L‰L×(Ñ(×6Ñ6Ð7HÓIÈ!ÑLÈeõ	
r!   c                 ó‚  • U R                   R                  R                  SS5        U R                  R	                  U R                   5        SR                  U R                   R                  5      nU R                  XR                  SS 5        U R                  U R                   R                  [        R                  5        U R                  U R                   R                  R                  S5      S   S5        U R                  S	[        U5      4-  U R                   R                  R                  S
5      S   5        g)z°
A correct response to a bytes range header request from A to B starts
with the A'th byte and ends with (including) the B'th byte. The first
byte of a page is numbered with 0.
r^  s
   bytes=3-43r!   râ  r(  rr  r   s   bytes 3-43/64rU  rÇ   N©r(   rb  rc  r   r8   r$   r%   r#   rü  rk   r   rk  rÊ   rË   rT   ©r)   r%   s     r*   Útest_explicitRangeÚRangeTests.test_explicitRangeu  sð   € ð 	�‰×#Ñ#×0Ñ0°¸=ÔIØ�‰×Ñ˜TŸ\™\Ô*Ø—(‘(˜4Ÿ<™<×/Ñ/Ó0ˆØ×Ñ˜§,¡,¨q°Ð"4Ô5Ø×Ñ˜Ÿ™×2Ñ2´D×4HÑ4HÔIØ×ÑØ�L‰L×(Ñ(×6Ñ6Ð7GÓHÈÑKØô	
ð 	×ÑØ”S˜“\�OÑ#Ø�L‰L×(Ñ(×6Ñ6Ð7HÓIÈ!ÑLõ	
r!   c                 ó‚  • U R                   R                  R                  SS5        U R                  R	                  U R                   5        SR                  U R                   R                  5      nU R                  XR                  SS 5        U R                  U R                   R                  [        R                  5        U R                  U R                   R                  R                  S5      S   S5        U R                  S	[        U5      4-  U R                   R                  R                  S
5      S   5        g)zÛ
A correct response to a bytes range header request from A to B when B
is past the end of the resource starts with the A'th byte and ends
with the last byte of the resource. The first byte of a page is
numbered with 0.
r^  s   bytes=40-100r!   rN  Nrr  r   s   bytes 40-63/64rU  rÇ   rm  rn  s     r*   Ú test_explicitRangeOverlappingEndÚ+RangeTests.test_explicitRangeOverlappingEnd‰  sð   € ð 	�‰×#Ñ#×0Ñ0°¸?ÔKØ�‰×Ñ˜TŸ\™\Ô*Ø—(‘(˜4Ÿ<™<×/Ñ/Ó0ˆØ×Ñ˜§,¡,¨r¨sÐ"3Ô4Ø×Ñ˜Ÿ™×2Ñ2´D×4HÑ4HÔIØ×ÑØ�L‰L×(Ñ(×6Ñ6Ð7GÓHÈÑKØô	
ð 	×ÑØ”S˜“\�OÑ#Ø�L‰L×(Ñ(×6Ñ6Ð7HÓIÈ!ÑLõ	
r!   c                 ó  • U R                   R                  R                  SS5        U R                  R	                  U R                   5        U R                  U R                   R                  [        R                  5        U R                  SR                  U R                   R                  5      U R                  5        U R                  U R                   R                  R                  S5      S   S[        U R                  5      4-  5        g)z§
If a range is syntactically invalid due to the start being greater than
the end, the range header is ignored (the request is responded to as if
it were not present).
r^  s   bytes=20-13r!   rÇ   r   rU  N)r(   rb  rc  r   r8   r#   rk   r   rL  r$   r%   rü  rÊ   rË   rT   r¤   s    r*   Ú+test_statusCodeRequestedRangeNotSatisfiableÚ6RangeTests.test_statusCodeRequestedRangeNotSatisfiablež  s¹   € ð 	�‰×#Ñ#×0Ñ0°¸>ÔJØ�‰×Ñ˜TŸ\™\Ô*Ø×Ñ˜Ÿ™×2Ñ2´D·G±GÔ<Ø×Ñ˜Ÿ™ $§,¡,×"6Ñ"6Ó7¸¿¹ÔFØ×ÑØ�L‰L×(Ñ(×6Ñ6Ð7HÓIÈ!ÑLØ”S˜Ÿ™Ó&Ð(Ñ(õ	
r!   c           	      óŒ  • U R                   R                  R                  SS5        U R                  R	                  U R                   5        U R                  U R                   R                  [        R                  5        U R                  SR                  U R                   R                  5      S5        U R                  U R                   R                  R                  S5      S   S5        U R                  U R                   R                  R                  S5      S   [        S[        U R                  5      4-  5      5        g	)
zÝ
If a range is unsatisfiable due to the start not being less than the
length of the resource, the response is 416 (Requested range not
satisfiable) and no data is written to the response body (RFC 2616,
section 14.35.1).
r^  s   bytes=67-108r!   rÇ   r   r‚  rr  z
bytes */%dN)r(   rb  rc  r   r8   r#   rk   r   r|  r$   r%   rÊ   rË   r
   rT   rü  r¤   s    r*   Útest_invalidStartBytePosÚ#RangeTests.test_invalidStartBytePos­  sñ   € ð 	�‰×#Ñ#×0Ñ0°¸?ÔKØ�‰×Ñ˜TŸ\™\Ô*Ø×ÑØ�L‰L×%Ñ%¤t×'KÑ'Kô	
ð 	×Ñ˜Ÿ™ $§,¡,×"6Ñ"6Ó7¸Ô=Ø×ÑØ�L‰L×(Ñ(×6Ñ6Ð7HÓIÈ!ÑLÈdô	
ð 	×ÑØ�L‰L×(Ñ(×6Ñ6Ð7GÓHÈÑKÜ˜,¬#¨d¯l©lÓ*;Ð)=Ñ=Ó>õ	
r!   )rþ  rW   rü  r(   r   N)r<   r=   r>   r?   r@   r   r  r
  r  r  r  r  r  r"  r%  r)  r-  rH  r\  r`  rf  rj  ro  rr  ru  rx  rA   r;   r!   r*   rú  rú  R  sy   † ñò -ò80òWò7ò8TòTòRò
Sò
ò
òBò
ò& òDEò4Eò6
ò$
ò&
ò(
ò*
õ
r!   rú  c                   ó¬   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS r\" \R"                  " 5       (       + S5      S 5       rS rS rS rSrg)ÚDirectoryListerTestsiÄ  z&
Tests for L{static.DirectoryLister}.
c                 ó*   • [        S/5      nXl        U$ r    )r   r  )r)   r  r(   s      r*   Ú_requestÚDirectoryListerTests._requestÉ  s   € Ü ˜uÓ%ˆØŒØˆr!   c                 ó  • [        U R                  5       5      nUR                  5         [        R                  " UR
                  5      nUR                  U R                  S5      5      nU R                  SU5        U R                  SU5        g)zU
L{static.DirectoryLister} prints the request uri as header of the
rendered content.
r   s"   <h1>Directory listing for foo</h1>s(   <title>Directory listing for foo</title>N©	r   rS   ro   r   rx   rc   r8   r}  rœ  ©r)   rc   Úlisterr1   s       r*   Útest_renderHeaderÚ&DirectoryListerTests.test_renderHeaderÎ  sf   € ô
 ˜Ÿ™›Ó&ˆØ�‰Œä×'Ò'¨¯	©	Ó2ˆØ�}‰}˜TŸ]™]¨6Ó2Ó3ˆØ�‰Ð;¸TÔBØ�‰ÐAÀ4ÕHr!   c                 ó  • [        U R                  5       5      nUR                  5         [        R                  " UR
                  5      nUR                  U R                  S5      5      nU R                  SU5        U R                  SU5        g)zG
L{static.DirectoryLister} unquote the request uri before printing it.
s	   foo%20bars&   <h1>Directory listing for foo bar</h1>s,   <title>Directory listing for foo bar</title>Nr€  r�  s       r*   Útest_renderUnquoteHeaderÚ-DirectoryListerTests.test_renderUnquoteHeaderÛ  sf   € ô ˜Ÿ™›Ó&ˆØ�‰Œä×'Ò'¨¯	©	Ó2ˆØ�}‰}˜TŸ]™]¨<Ó8Ó9ˆØ�‰Ð?ÀÔFØ�‰ÐEÀtÕLr!   c                 ó  • [        U R                  5       5      nUR                  5         [        R                  " UR
                  5      nUR                  U R                  S5      5      nU R                  SU5        U R                  SU5        g)zT
L{static.DirectoryLister} escape "&", "<" and ">" after unquoting the
request uri.
s	   foo%26bars*   <h1>Directory listing for foo&amp;bar</h1>s0   <title>Directory listing for foo&amp;bar</title>Nr€  r�  s       r*   Útest_escapeHeaderÚ&DirectoryListerTests.test_escapeHeaderç  sf   € ô
 ˜Ÿ™›Ó&ˆØ�‰Œä×'Ò'¨¯	©	Ó2ˆØ�}‰}˜TŸ]™]¨<Ó8Ó9ˆØ�‰ÐCÀTÔJØ�‰ÐIÈ4ÕPr!   c                 ó‚  • [        U R                  5       5      nUR                  5         UR                  S5      R	                  S5        UR                  S5      R	                  SS-  5        [
        R                  " UR                  5      nUR                  U R                  S5      5      nSnU R                  XC5        g)	zM
L{static.DirectoryLister} is able to list all the files inside a
directory.
Úfile1s   content1Úfile2s   content2iè  r   sê   <tr class="odd">
    <td><a href="file1">file1</a></td>
    <td>8B</td>
    <td>[text/html]</td>
    <td></td>
</tr>
<tr class="even">
    <td><a href="file2">file2</a></td>
    <td>7K</td>
    <td>[text/html]</td>
    <td></td>
</tr>N)r   rS   ro   rs   rb   r   rx   rc   r8   r}  rœ  ©r)   rc   r‚  r1   r;  s        r*   Útest_renderFilesÚ%DirectoryListerTests.test_renderFilesô  s�   € ô
 ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�7Ó×&Ñ& {Ô3Ø�
‰
�7Ó×&Ñ& {°TÑ'9Ô:ä×'Ò'¨¯	©	Ó2ˆØ�}‰}˜TŸ]™]¨6Ó2Ó3ˆð	ˆð 	�‰�dÕ!r!   c                 óx  • [        U R                  5       5      nUR                  5         UR                  S5      R                  5         UR                  S5      R                  5         [        R
                  " UR                  5      nUR                  U R                  S5      5      nSnU R                  XC5        g)zS
L{static.DirectoryLister} is able to list all the directories inside
a directory.
Údir1zdir2 & 3r   sø   <tr class="odd">
    <td><a href="dir1/">dir1/</a></td>
    <td></td>
    <td>[Directory]</td>
    <td></td>
</tr>
<tr class="even">
    <td><a href="dir2%20%26%203/">dir2 &amp; 3/</a></td>
    <td></td>
    <td>[Directory]</td>
    <td></td>
</tr>N©
r   rS   ro   rs   r   rx   rc   r8   r}  rœ  rŽ  s        r*   Útest_renderDirectoriesÚ+DirectoryListerTests.test_renderDirectories  s‡   € ô
 ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�6Ó×#Ñ#Ô%Ø�
‰
�:Ó×'Ñ'Ô)ä×'Ò'¨¯	©	Ó2ˆØ�}‰}˜TŸ]™]¨6Ó2Ó3ˆð	ˆð 	�‰�dÕ!r!   c                 ó¸  • [        U R                  5       5      nUR                  5         UR                  S5      R                  5         UR                  S5      R                  5         UR                  S5      R                  5         [        R
                  " UR                  SS/S9nUR                  U R                  S5      5      nSnU R                  XC5        g)zy
L{static.DirectoryLister} takes an optional C{dirs} argument that
filter out the list of directories and files printed.
r’  Údir2Údir3)Údirsr   sæ   <tr class="odd">
    <td><a href="dir1/">dir1/</a></td>
    <td></td>
    <td>[Directory]</td>
    <td></td>
</tr>
<tr class="even">
    <td><a href="dir3/">dir3/</a></td>
    <td></td>
    <td>[Directory]</td>
    <td></td>
</tr>Nr“  rŽ  s        r*   Útest_renderFilteredÚ(DirectoryListerTests.test_renderFiltered(  s£   € ô
 ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�6Ó×#Ñ#Ô%Ø�
‰
�6Ó×#Ñ#Ô%Ø�
‰
�6Ó×#Ñ#Ô%Ü×'Ò'¨¯	©	¸ÀÐ8HÑIˆØ�}‰}˜TŸ]™]¨6Ó2Ó3ˆð	ˆð 	�‰�dÕ!r!   c           	      ó2  • [         R                  " S5      n[        S5       Vs/ s H  nSSSSSS.PM     nnUR                  U5      nU R	                  [        U5      S5        U R                  US   R                  S5      5        U R                  US   R                  S5      5        U R                  US	   R                  S5      5        U R                  US
   R                  S5      5        U R                  US   R                  S5      5        gs  snf )z]
L{static.DirectoryLister} gives an alternate class for each odd and
even rows in the table.
Nr˜  r   )ÚhrefÚtextr¤  r:  r9  r   z<tr class="odd">rK   z<tr class="even">rÍ  râ  rã  )r   rx   r,  Ú_buildTableContentr#   rT   r#  r@  )r)   r‚  ÚiÚelementsrÝ   s        r*   Útest_oddAndEvenÚ$DirectoryListerTests.test_oddAndEvenB  sü   € ô
 ×'Ò'¨Ó-ˆô ˜1”Xó
â�ð  ¨R¸ÈÔLÙð 	ð 
ð ×+Ñ+¨HÓ5ˆà×Ñœ˜W› qÔ)Ø�‰˜ ™
×-Ñ-Ð.@ÓAÔBØ�‰˜ ™
×-Ñ-Ð.AÓBÔCØ�‰˜ ™
×-Ñ-Ð.@ÓAÔBØ�‰˜ ™
×-Ñ-Ð.AÓBÔCØ�‰˜ ™
×-Ñ-Ð.@ÓAÕBùò
s   ¤Dc                 ó6  • [        U R                  5       5      nUR                  5         [        R                  " UR
                  5      nU R                  S5      nUR                  U5        U R                  UR                  R                  S5      S   S5        g)zr
L{static.DirectoryLister} produces a MIME-type that indicates that it is
HTML, and includes its charset (UTF-8).
r!   rV  r   s   text/html; charset=utf-8N)r   rS   ro   r   rx   rc   r}  r8   r#   rÊ   rË   )r)   rc   r‚  Úreqs       r*   Útest_contentTypeÚ%DirectoryListerTests.test_contentTypeU  su   € ô
 ˜Ÿ™›Ó&ˆØ�‰ŒÜ×'Ò'¨¯	©	Ó2ˆØ�m‰m˜CÓ ˆØ�‰�cÔØ×ÑØ×Ñ×-Ñ-¨oÓ>¸qÑAØ'õ	
r!   c                 ó¨  • [        U R                  5       5      nUR                  5         UR                  S5      R	                  S5        UR                  S5      R	                  S5        UR                  S5      R	                  S5        UR                  S5      R	                  S5        [
        R                  " UR                  5      nUR                  5         S	S
SSS.n[        R                  " UR                  US9nUR                  U5      u  pVU R                  U/ 5        U R                  USSSSSS.SSSSSS.SSSSSS.SSSSSS./5        g)zT
L{static.DirectoryLister} is able to detect mimetype and encoding of
listed files.
z	file1.txtó   file1zfile2.pys   pythonzfile3.conf.gzs   conf compressedzfile4.diff.bz2s   diff compressedrQ  ztext/pythonztext/configurationz	text/diff)z.txtz.pyz.confz.diff)ÚcontentTypesr   Ú5Bz[text/plain])r9  r�  r¤  rž  r:  Ú6Bz[text/python]z[gzip]Ú15Bz[text/configuration]z[bzip2]z[text/diff]N)r   rS   ro   rs   rb   ÚosÚlistdirrc   Úsortr   rx   Ú_getFilesAndDirectoriesr#   )r)   rc   Ú	directoryrª  r‚  r™  Úfiless          r*   Útest_mimeTypeAndEncodingsÚ.DirectoryListerTests.test_mimeTypeAndEncodingsd  sU  € ô
 ˜Ÿ™›Ó&ˆØ�‰ŒØ�
‰
�;Ó×*Ñ*¨8Ô4Ø�
‰
�:Ó×)Ñ)¨)Ô4Ø�
‰
�?Ó#×.Ñ.Ð/AÔBØ�
‰
Ð#Ó$×/Ñ/Ð0BÔCÜ—J’J˜tŸy™yÓ)ˆ	Ø�‰Ôð !Ø Ø)Ø ñ	
ˆô ×'Ò'¨¯	©	ÀÑMˆØ×4Ñ4°YÓ?‰ˆØ×Ñ˜˜rÔ"Ø×ÑØð !#Ø'Ø Ø'Ø*ñð !#Ø&Ø Ø&Ø+ñð !)Ø+Ø!Ø+Ø2ñð !*Ø,Ø!Ø,Ø)ñð-õ 	
r!   zNo symlink supportc                 ó  • [        U R                  5       5      nUR                  5         UR                  S5      nUR	                  S5        UR                  UR                  S5      5        UR                  5         [        R                  " UR                  5      n[        R                  " UR                  5      nUR                  5         UR                  U5      u  pVU R                  U/ 5        U R                  U/ 5        g)z‹
If on the file in the listing points to a broken symlink, it should not
be returned by L{static.DirectoryLister._getFilesAndDirectories}.
rŒ  r©  r�  N)r   rS   ro   rs   rb   ÚlinkToÚremover   rx   rc   r®  r¯  r°  r±  r#   )r)   rc   rŒ  r‚  r²  r™  r³  s          r*   Útest_brokenSymlinkÚ'DirectoryListerTests.test_brokenSymlinkž  s¹   € ô ˜Ÿ™›Ó&ˆØ�‰ŒØ—
‘
˜7Ó#ˆØ×Ñ˜Ô"Ø�‰�T—Z‘Z Ó(Ô)Ø�‰Œä×'Ò'¨¯	©	Ó2ˆÜ—J’J˜tŸy™yÓ)ˆ	Ø�‰ÔØ×4Ñ4°YÓ?‰ˆØ×Ñ˜˜rÔ"Ø×Ñ˜ Õ#r!   c                 ó4  ^ ^• [        T R                  5       5      nUR                  5         [        R                  " UR
                  5      nT R                  S5      m[        R                  " UT5      n[        UT5      nUU 4S jnUR                  U5        U$ )z]
Any child resource of L{static.DirectoryLister} renders an HTTP
I{NOT FOUND} response code.
r!   c                 óZ   >• TR                  TR                  [        R                  5        g rF   )r#   rk   r   Ú	NOT_FOUNDr&   s    €€r*   r+   Ú>DirectoryListerTests.test_childrenNotFound.<locals>.cbRendered¾  s   ø€ Ø×Ñ˜W×1Ñ1´4·>±>ÕBr!   )r   rS   ro   r   rx   rc   r}  r   rp   r   r0   )r)   rc   r‚  rs   r¿   r+   r(   s   `     @r*   Útest_childrenNotFoundÚ*DirectoryListerTests.test_childrenNotFound²  sy   ù€ ô
 ˜Ÿ™›Ó&ˆØ�‰ŒÜ×'Ò'¨¯	©	Ó2ˆØ—-‘- Ó$ˆÜ×+Ò+¨F°GÓ<ˆÜ˜ Ó(ˆö	Cð 	×Ñ˜:Ô&Øˆr!   c                 ó  • [        U R                  5       5      n[        R                  " UR                  5      nU R                  [        U5      SUR                  < S35        U R                  [        U5      SUR                  < S35        g)zB
L{static.DirectoryLister.__repr__} gives the path of the lister.
z<DirectoryLister of Ú>N)r   rS   r   rx   rc   r#   ÚreprrÜ   )r)   rc   r‚  s      r*   Ú	test_reprÚDirectoryListerTests.test_reprÄ  sl   € ô ˜Ÿ™›Ó&ˆÜ×'Ò'¨¯	©	Ó2ˆØ×Ñœ˜f›Ð)=¸d¿i¹i¹]È!Ð'LÔMØ×Ñœ˜V›Ð(<¸T¿Y¹Y¹MÈÐ&KÕLr!   c                 óÌ  • U R                  [        R                  " S5      S5        U R                  [        R                  " S5      S5        U R                  [        R                  " S5      S5        U R                  [        R                  " S5      S5        U R                  [        R                  " S	5      S
5        U R                  [        R                  " S5      S5        g)zQ
L{static.formatFileSize} format an amount of bytes into a more readable
format.
r   Ú0BrP  Ú123Bi×  Ú4Ki Í‡ Ú8Mi€X�IÚ1Gl   Pöc}Ú1149GN)r#   r   ÚformatFileSizer¤   s    r*   Útest_formatFileSizeÚ(DirectoryListerTests.test_formatFileSizeÍ  s¦   € ð
 	×Ñœ×.Ò.¨qÓ1°4Ô8Ø×Ñœ×.Ò.¨sÓ3°VÔ<Ø×Ñœ×.Ò.¨tÓ4°dÔ;Ø×Ñœ×.Ò.¨wÓ7¸Ô>Ø×Ñœ×.Ò.¨zÓ:¸DÔAØ×Ñœ×.Ò.¨}Ó=¸wÕGr!   r;   N)r<   r=   r>   r?   r@   r}  rƒ  r†  r‰  r�  r”  rš  r¢  r¦  r´  r   r   Ú_supportsSymlinksr¹  r¿  rÄ  rÎ  rA   r;   r!   r*   r{  r{  Ä  sx   † ñòò
Iò
MòQò"ò4"ò4"ò4Cò&
ò8
ñt �×*Ò*Ó,Ô,Ð.BÓCñ$ó Dð$ò&ò$Mõ
Hr!   r{  c                   óD   • \ rS rSrSr\" 5       rS rS rS r	S r
S rSrg	)
ÚLoadMimeTypesTestsiÚ  zˆ
Tests for the MIME type loading routine.

@cvar UNSET: A sentinel to signify that C{self.paths} has not been set by
    the mock init.
c                 ó&   • U R                   U l        g rF   )ÚUNSETÚpathsr¤   s    r*   r   ÚLoadMimeTypesTests.setUpä  s   € Ø—Z‘Zˆ�
r!   c                 ó   • Xl         g)z‚
A mock L{mimetypes.init} that records the value of the passed C{paths}
argument.

@param paths: The paths that will be recorded.
N©rÕ  ©r)   rÕ  s     r*   Ú	_fakeInitÚLoadMimeTypesTests._fakeInitç  s	   € ð �
r!   c                 óx   • [         R                  " U R                  S9  U R                  U R                  S5        g)z5
By default, L{None} is passed to C{mimetypes.init}.
©ÚinitN©r   ÚloadMimeTypesrÚ  r¾  rÕ  r¤   s    r*   Útest_defaultArgumentIsNoneÚ-LoadMimeTypesTests.test_defaultArgumentIsNoneð  s*   € ô 	×Ò $§.¡.Ò1Ø×Ñ˜TŸZ™Z¨Õ.r!   c                 ó€   • / SQn[         R                  " XR                  S9  U R                  U R                  U5        g)z9
Passed MIME type files are passed to C{mimetypes.init}.
)ÚxÚyÚzrÝ  Nrß  rÙ  s     r*   Útest_extraLocationsWorkÚ*LoadMimeTypesTests.test_extraLocationsWork÷  s/   € ò  ˆÜ×Ò˜U¯©Ò8Ø×Ñ˜TŸZ™Z¨Õ/r!   c                 óž  • [        [        SS5      (       a\  [        R                  " [        R                  5      nU R                  UR                  S   R                  [        R                  5        g[        R                  " [        R                  5      u  n  p4XBR                  S5         nU R                  U[        R                  5        g)z*
By default, C{mimetypes.init} is called.
Ú	signatureNrÞ  )ÚgetattrÚinspectrê  r   rà  ÚassertIsÚ
parametersÚdefaultÚ	mimetypesrÞ  Ú
getargspecÚindex)r)   rê  Úargsr+  ÚdefaultsÚdefaultInits         r*   Útest_usesGlobalInitFunctionÚ.LoadMimeTypesTests.test_usesGlobalInitFunctionÿ  sŒ   € ô ”7˜K¨×.Ñ.Ü×)Ò)¬&×*>Ñ*>Ó?ˆIØ�M‰M˜)×.Ñ.¨vÑ6×>Ñ>Ä	ÇÁÕOä#*×#5Ò#5´f×6JÑ6JÓ#KÑ ˆD�!�QØ"§:¡:¨fÓ#5Ñ6ˆKØ�M‰M˜+¤y§~¡~Õ6r!   rØ  N)r<   r=   r>   r?   r@   ÚobjectrÔ  r   rÚ  rá  rç  rö  rA   r;   r!   r*   rÒ  rÒ  Ú  s)   † ññ ‹H€Eò òò/ò0õ7r!   rÒ  c                   ó   • \ rS rSrS rSrg)ÚStaticDeprecationTestsi  c                 óÒ   • SSK Jn  U" [        S/5      5        U R                  U R                  /5      nU R                  [        U5      S5        U R                  US   S   S5        g)z/
L{twisted.web.static.addSlash} is deprecated.
r   )ÚaddSlashr!   rK   r  z<twisted.web.static.addSlash was deprecated in Twisted 16.0.0N)Útwisted.web.staticrü  r   ÚflushWarningsÚtest_addSlashDeprecatedr#   rT   )r)   rü  rP   s      r*   rÿ  Ú.StaticDeprecationTests.test_addSlashDeprecated  s`   € õ 	0á”˜s˜eÓ$Ô%à×%Ñ% t×'CÑ'CÐ&DÓEˆØ×Ñœ˜X›¨Ô*Ø×ÑØ�Q‰K˜	Ñ"ØJõ	
r!   r;   N)r<   r=   r>   r?   rÿ  rA   r;   r!   r*   rú  rú    s   † õ
r!   rú  )5r@   rª   rì  rð  r®  rž  r1  rP   Úior   r  Úunittestr   Úzope.interface.verifyr   Útwisted.internetr   r   Útwisted.pythonr   r	   Útwisted.python.compatr
   Útwisted.python.filepathr   Útwisted.python.runtimer   Útwisted.trial.unittestr   Útwisted.webr   r   r   r   Útwisted.web._responsesr   Útwisted.web.serverr   Útwisted.web.test._utilr   Útwisted.web.test.requesthelperr   r   rC   r6  rµ  rÂ  rÞ  rì  rú  r{  rÒ  rú  r;   r!   r*   Ú<module>r     sê   ðñó Û Û Û 	Û 	Û 
Û Ý "Ý å .ç 1ß &Ý /Ý ,Ý +Ý +ß 6Ó 6Ý (Ý 0Ý *Ý 7ôC�hô Cô>u)�hô u)ôpsI˜hô sIôl	5˜(ô 5ô69/ ô 9/ôx>/ Xô >/ôBJ/ xô J/ôZo
�ô o
ôdSH˜8ô SHôl27˜ô 27ôj
˜Xõ 
r!   