Ë
    oj(G  ã                  ó¶   — d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
mZ d dlmZ  G d„ de«      Z G d„ d	e
j                  «      Z G d
„ de«      Zy)é    )ÚannotationsN)ÚskipIf)ÚlogfileÚruntime)ÚTestCasec                  óð   — e Zd ZdZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Z	dd„Z
dd	„Zdd
„Zdd„Zdd„Zdd„Zdd„Zdd„Z eej(                  j+                  «       d«      dd„«       Zdd„Zdd„Zdd„Zdd„Zy)ÚLogFileTestsz%
    Test the rotating log file.
    c                óì   — | j                  «       | _        t        j                  | j                  «       d| _        t        j
                  j                  | j                  | j                  «      | _        y )Nztest.log©ÚmktempÚdirÚosÚmakedirsÚnameÚpathÚjoin©Úselfs    ú;/usr/lib/python3/dist-packages/twisted/test/test_logfile.pyÚsetUpzLogFileTests.setUp   sD   € Ø—;‘;“=ˆŒÜ
�‰�D—H‘HÔØˆŒ	Ü—G‘G—L‘L §¡¨4¯9©9Ó5ˆ�	ó    c                óØ   — t        j                  | j                  d«       t         j                  j	                  | j                  «      r!t        j                  | j                  d«       yy)zž
        Restore back write rights on created paths: if tests modified the
        rights, that will allow the paths to be removed easily afterwards.
        éÿ  N)r   Úchmodr   r   Úexistsr   s    r   ÚtearDownzLogFileTests.tearDown   sA   € ô
 	�‰�—‘˜5Ô!Ü�7‰7�>‰>˜$Ÿ)™)Ô$Ü�H‰H�T—Y‘Y Õ&ð %r   c                óÎ   — t        j                  | j                  | j                  «      }| j	                  |j
                  «       | j                  t        |j                  «       y)zf
        L{BaseLogFile.shouldRotate} is abstract and must be implemented by
        subclass.
        N)	r   ÚBaseLogFiler   r   Ú
addCleanupÚcloseÚassertRaisesÚNotImplementedErrorÚshouldRotate©r   Úlogs     r   Útest_abstractShouldRotatez&LogFileTests.test_abstractShouldRotate$   sE   € ô
 ×!Ñ! $§)¡)¨T¯X©XÓ6ˆØ�‰˜Ÿ	™	Ô"Ø×ÑÔ-¨s×/?Ñ/?Õ@r   c                óÂ  — t        j                  t        j                  | j                  | j
                  «      «      5 }|j                  d«       |j                  d«       |j                  «        |j                  d«       ddd«       t        | j                  «      5 }| j                  |j                  «       d«       ddd«       y# 1 sw Y   ŒHxY w# 1 sw Y   yxY w)zn
        Log files can be written to, flushed and closed. Closing a log file
        also flushes it.
        Ú123Ú456Ú7890NÚ
1234567890)Ú
contextlibÚclosingr   ÚLogFiler   r   ÚwriteÚflushÚopenr   ÚassertEqualÚread©r   r%   Úfs      r   Útest_writingzLogFileTests.test_writing-   s¨   € ô
 ×Ñ¤§¡°·	±	¸4¿8¹8Ó DÓEð 	ÈØ�I‰I�eÔØ�I‰I�eÔØ�I‰IŒKØ�I‰I�fÔ÷		ô �$—)‘)‹_ð 	5 Ø×Ñ˜QŸV™V›X |Ô4÷	5ð 	5÷	ð 	ú÷	5ð 	5ús   ¾AC	Â!CÃ	CÃCc                ój  — t        j                  t        j                  | j                  | j
                  d¬«      «      5 }|j                  d«       |j                  d«       |j                  d«       | j                  t        j                  j                  | j                  › d�«      «       | j                  t        j                  j                  | j                  › d�«      «       |j                  d«       | j                  t        j                  j                  | j                  › d�«      «       | j                  t        j                  j                  | j                  › d�«      «       | j                  t        j                  j                  | j                  › d	�«      «       |j                  d
«       | j                  t        j                  j                  | j                  › d	�«      «       |j                  «        | j                  t        j                  j                  | j                  › d	�«      «       | j                  t        j                  j                  | j                  › d�«      «       ddd«       | j                  j                  «       g d¢«       y# 1 sw Y   Œ,xY w)zq
        Rotating log files autorotate after a period of time, and can also be
        manually rotated.
        é
   )ÚrotateLengthr(   Ú4567890Ú11111111111ú.1ú.2Ú ú.3Ú3ú.4N)é   é   é   )r,   r-   r   r.   r   r   r/   Ú
assertTruer   r   r   ÚassertFalseÚrotater2   ÚlistLogsr$   s     r   Útest_rotationzLogFileTests.test_rotation;   sÇ  € ô ×ÑÜ�O‰O˜DŸI™I t§x¡x¸bÔAó
ð 	?àà�I‰I�eÔØ�I‰I�iÔ Ø�I‰I�hÔØ�O‰OœBŸG™GŸN™N¨d¯i©i¨[¸Ð+;Ó<Ô=Ø×ÑœRŸW™WŸ^™^¨t¯y©y¨k¸Ð,<Ó=Ô>Ø�I‰I�bŒMØ�O‰OœBŸG™GŸN™N¨d¯i©i¨[¸Ð+;Ó<Ô=Ø�O‰OœBŸG™GŸN™N¨d¯i©i¨[¸Ð+;Ó<Ô=Ø×ÑœRŸW™WŸ^™^¨t¯y©y¨k¸Ð,<Ó=Ô>Ø�I‰I�cŒNØ×ÑœRŸW™WŸ^™^¨t¯y©y¨k¸Ð,<Ó=Ô>ð �J‰JŒLØ�O‰OœBŸG™GŸN™N¨d¯i©i¨[¸Ð+;Ó<Ô=Ø×ÑœRŸW™WŸ^™^¨t¯y©y¨k¸Ð,<Ó=Ô>÷'	?ð* 	×Ñ˜Ÿ™›ªÕ3÷+	?ð 	?ús   Á H>J)Ê)J2c                ó4  — t        j                  t        j                  | j                  | j
                  «      «      5 }|j                  d«       ddd«       t        j                  | j                  | j
                  «      }| j                  |j                  «       | j                  |j                  d«       | j                  |j                  j                  «       |j                  «       |j                  d«       | j                  |j                  d«       | j                  |j                  j                  «       |j                  «       |j                  }|j                  dd«       | j                  |j                  «       d«       y# 1 sw Y   �Œ?xY w)a  
        Log files can be written to, closed. Their size is the number of
        bytes written to them. Everything that was written to them can
        be read, even if the writing happened on separate occasions,
        and even if the log file was closed in between.
        Ú
0123456789Nr8   Úabcé   r   s   0123456789abc)r,   r-   r   r.   r   r   r/   r   r    r2   ÚsizeÚ_fileÚtellÚseekr3   r4   s      r   Útest_appendzLogFileTests.test_appendX   s  € ô ×Ñ¤§¡°·	±	¸4¿8¹8Ó DÓEð 	$ÈØ�I‰I�lÔ#÷	$ô �o‰o˜dŸi™i¨¯©Ó2ˆØ�‰˜Ÿ	™	Ô"Ø×Ñ˜Ÿ™ 2Ô&Ø×Ñ˜Ÿ™Ÿ™Ó)¨3¯8©8Ô4Ø�	‰	�%ÔØ×Ñ˜Ÿ™ 2Ô&Ø×Ñ˜Ÿ™Ÿ™Ó)¨3¯8©8Ô4Ø�I‰IˆØ	�‰ˆq�!ŒØ×Ñ˜Ÿ™›Ð#3Õ4÷	$ñ 	$ús   ¾FÆFc                ó   — t        j                  | j                  | j                  «      }| j	                  |j
                  «       |j                  d«       |j                  d«       |j                  «        |j                  d«       |j                  «        | j                  |j                  «       dg«       t        j                  |j                  «       «      5 }|j                  j                  d«       | j                  |j!                  «       dg«       | j                  |j!                  «       g «       ddd«       t        j                  |j#                  d«      «      5 }| j                  |j!                  «       ddg«       | j                  |j!                  «       g «       ddd«       | j%                  t&        |j"                  d«       | j%                  t(        |j"                  d«       |j                  «        | j                  |j                  «       ddg«       t        j                  |j#                  d«      «      5 }|j                  j                  d«       | j                  |j!                  «       dg«       | j                  |j!                  «       g «       ddd«       t        j                  |j#                  d«      «      5 }| j                  |j!                  «       ddg«       | j                  |j!                  «       g «       ddd«       y# 1 sw Y   �ŒæxY w# 1 sw Y   �Œ„xY w# 1 sw Y   Œ“xY w# 1 sw Y   yxY w)	a[  
        Various tests for log readers.

        First of all, log readers can get logs by number and read what
        was written to those log files. Getting nonexistent log files
        raises C{ValueError}. Using anything other than an integer
        index raises C{TypeError}. As logs get older, their log
        numbers increase.
        zabc
zdef
zghi
rB   r   NrC   Ú1)r   r.   r   r   r   r    r/   rG   r0   r2   rH   r,   r-   ÚgetCurrentLogrO   rQ   Ú	readLinesÚgetLogr!   Ú
ValueErrorÚ	TypeError)r   r%   Úreaders      r   Útest_logReaderzLogFileTests.test_logReaderm   s‡  € ô �o‰o˜dŸi™i¨¯©Ó2ˆØ�‰˜Ÿ	™	Ô"Ø�	‰	�'ÔØ�	‰	�'ÔØ�
‰
ŒØ�	‰	�'ÔØ�	‰	Œð 	×Ñ˜Ÿ™›¨!¨Ô-Ü×Ñ × 1Ñ 1Ó 3Ó4ð 	5¸Ø�L‰L×Ñ˜aÔ Ø×Ñ˜V×-Ñ-Ó/°'°Ô;Ø×Ñ˜V×-Ñ-Ó/°Ô4÷	5ô ×Ñ §
¡
¨1£Ó.ð 	5°&Ø×Ñ˜V×-Ñ-Ó/°'¸7Ð1CÔDØ×Ñ˜V×-Ñ-Ó/°Ô4÷	5ð
 	×Ñœ* c§j¡j°!Ô4Ø×Ñœ) S§Z¡Z°Ô5ð 	�
‰
ŒØ×Ñ˜Ÿ™›¨!¨Q¨Ô0Ü×Ñ §
¡
¨1£Ó.ð 	5°&Ø�L‰L×Ñ˜aÔ Ø×Ñ˜V×-Ñ-Ó/°'°Ô;Ø×Ñ˜V×-Ñ-Ó/°Ô4÷	5ô ×Ñ §
¡
¨1£Ó.ð 	5°&Ø×Ñ˜V×-Ñ-Ó/°'¸7Ð1CÔDØ×Ñ˜V×-Ñ-Ó/°Ô4÷	5ð 	5÷'	5ñ 	5ú÷	5ñ 	5ú÷	5ð 	5ú÷	5ð 	5ús4   ÃALÅ&AL+É	AL8ËAMÌL(Ì+L5Ì8MÍMc                ó  — t        | j                  d«      5  	 ddd«       t        j                  | j                  «      }| j	                  |j
                  «       | j                  g |j                  d«      «       y# 1 sw Y   ŒexY w)zB
        L{LogReader.readLines} supports reading no line.
        ÚwNr   )r1   r   r   Ú	LogReaderr   r    r2   rV   )r   rZ   s     r   Útest_LogReaderReadsZeroLinez(LogFileTests.test_LogReaderReadsZeroLine˜   sk   € ô
 �$—)‘)˜SÓ!ñ 	Ø÷	ô ×"Ñ" 4§9¡9Ó-ˆØ�‰˜Ÿ™Ô%Ø×Ñ˜˜V×-Ñ-¨aÓ0Õ1÷	ð 	ús   —A=Á=Bc                ó8  — t        | j                  d«      j                  «        t        j                  | j                  d«       t        j
                  | j                  «      t
        j                     }t        j                  | j                  | j                  «      }| j                  |j                  «       |j                  d«       |j                  «        | j                  |t        j
                  | j                  «      t
        j                     «       y)zH
        Check rotated files have same permissions as original.
        r]   éÇ  rL   N)r1   r   r    r   r   ÚstatÚST_MODEr   r.   r   r   r   r/   rG   r2   )r   Úmoder%   s      r   Útest_modePreservationz"LogFileTests.test_modePreservation¤   s«   € ô 	ˆT�Y‰Y˜Ó×"Ñ"Ô$Ü
�‰�—‘˜EÔ"Ü�w‰w�t—y‘yÓ!¤$§,¡,Ñ/ˆÜ�o‰o˜dŸi™i¨¯©Ó2ˆØ�‰˜Ÿ	™	Ô"Ø�	‰	�%ÔØ�
‰
ŒØ×Ñ˜œrŸw™w t§y¡yÓ1´$·,±,Ñ?Õ@r   c                ó¸  — t        j                  | j                  | j                  «      }| j	                  |j
                  «       |j                  d«       t        j                  | j                  d«       	 t        t        j                  j                  | j                  d«      d«      }|j                  «        y# t        $ r Y nw xY w|j                  «        |j                  d«       |j                  «        |j                  }| j!                  |j#                  «       d«       |j%                  dd«       | j!                  |j'                  «       d	«       y)
zH
        Check it keeps working when permission on dir changes.
        rL   ém  Úxxxr]   NÚdefé   r   s   abcdef)r   r.   r   r   r   r    r/   r   r   r1   r   r   ÚOSErrorrG   r0   rO   r2   rP   rQ   r3   r4   s      r   Útest_noPermissionzLogFileTests.test_noPermission±   sô   € ô �o‰o˜dŸi™i¨¯©Ó2ˆØ�‰˜Ÿ	™	Ô"Ø�	‰	�%Ôô 	�‰�—‘˜5Ô!ð	Ü”R—W‘W—\‘\ $§(¡(¨EÓ2°CÓ8ˆAð �G‰GŒIØøô	 ò 	Ùð	úð 	�
‰
Œà�	‰	�%ÔØ�	‰	Œà�I‰IˆØ×Ñ˜Ÿ™› 1Ô%Ø	�‰ˆq�!ŒØ×Ñ˜Ÿ™› 9Õ-s   Á84B= Â=	C	ÃC	c                óJ  — t        j                  | j                  | j                  dd¬«      }| j	                  |j
                  «       |j                  d«       |j                  d«       | j                  t        j                  j                  | j                  › d�«      «       |j                  d«       | j                  t        j                  j                  | j                  › d�«      «       |j                  d	«       | j                  t        j                  j                  | j                  › d
�«      «       t        | j                  › d
�«      5 }| j                  |j                  «       d«       ddd«       |j                  d«       t        | j                  › d
�«      5 }| j                  |j                  «       d«       ddd«       | j                  t        j                  j                  | j                  › d�«      «       y# 1 sw Y   Œ—xY w# 1 sw Y   ŒQxY w)zl
        Test it respect the limit on the number of files when maxRotatedFiles
        is not None.
        r8   rD   )r9   ÚmaxRotatedFilesr;   Ú22222222222r<   Ú33333333333r=   Ú44444444444r?   NÚ55555555555rA   )r   r.   r   r   r   r    r/   rE   r   r   r   r1   r2   r3   rF   ©r   r%   Úfps      r   Útest_maxNumberOfLogz LogFileTests.test_maxNumberOfLogÐ   s�  € ô
 �o‰o˜dŸi™i¨¯©ÀÐTUÔVˆØ�‰˜Ÿ	™	Ô"Ø�	‰	�(ÔØ�	‰	�(ÔØ�‰œŸ™Ÿ™¨$¯)©)¨°BÐ'7Ó8Ô9à�	‰	�(ÔØ�‰œŸ™Ÿ™¨$¯)©)¨°BÐ'7Ó8Ô9à�	‰	�(ÔØ�‰œŸ™Ÿ™¨$¯)©)¨°BÐ'7Ó8Ô9Ü�T—Y‘Y�K˜rÐ"Ó#ð 	2 rØ×Ñ˜RŸW™W›Y¨Ô1÷	2ð 	�	‰	�(ÔÜ�T—Y‘Y�K˜rÐ"Ó#ð 	2 rØ×Ñ˜RŸW™W›Y¨Ô1÷	2à×ÑœŸ™Ÿ™¨4¯9©9¨+°RÐ(8Ó9Õ:÷	2ð 	2ú÷	2ð 	2ús   Å!HÆ(!HÈHÈH"c                óŒ  — t        j                  | j                  | j                  dd¬«      }| j	                  |j
                  «       t         j                  j                  | j                  dd¬«      }| j	                  |j
                  «       | j                  |j                  |j                  «       | j                  t        j                  j                  |j                  «      |j                  «       | j                  |j                  |j                  «       | j                  |j                  |j                  «       y)z/
        Test the fromFullPath method.
        r8   r   ©ÚdefaultModeN)r   r.   r   r   r   r    ÚfromFullPathr   r2   r   Úabspathr9   rx   )r   Úlog1Úlog2s      r   Útest_fromFullPathzLogFileTests.test_fromFullPathè   sÔ   € ô �‰˜tŸy™y¨$¯(©(°BÀEÔJˆØ�‰˜Ÿ
™
Ô#Ü�‰×+Ñ+¨D¯I©I°rÀuÐ+ÓMˆØ�‰˜Ÿ
™
Ô#Ø×Ñ˜Ÿ™ D§I¡IÔ.Ø×ÑœŸ™Ÿ™¨¯©Ó3°T·Y±YÔ?Ø×Ñ˜×*Ñ*¨D×,=Ñ,=Ô>Ø×Ñ˜×)Ñ)¨4×+;Ñ+;Õ<r   c                óP  — t        | j                  d«      5  t        j                  | j                  d«       t	        j
                  t        j                  | j                  «      t        j                     «      }ddd«       t        j                  | j                  | j                  «      }| j                  t	        j
                  t        j                  | j                  «      t        j                     «      «       | j                  |j                  «       y# 1 sw Y   Œ¢xY w)zx
        Test the default permission of the log file: if the file exist, it
        should keep the permission.
        Úwbra   N)r1   r   r   r   rb   ÚS_IMODErc   r   r.   r   r   r2   r   r    )r   ÚcurrentModer{   s      r   Útest_defaultPermissionsz$LogFileTests.test_defaultPermissionsõ   sº   € ô
 �$—)‘)˜TÓ"ñ 	IÜ�H‰H�T—Y‘Y Ô&ÜŸ,™,¤r§w¡w¨t¯y©yÓ'9¼$¿,¹,Ñ'GÓHˆK÷	Iô �‰˜tŸy™y¨$¯(©(Ó3ˆØ×ÑœŸ™¤b§g¡g¨d¯i©iÓ&8¼¿¹Ñ&FÓGÈÔUØ�‰˜Ÿ
™
Õ#÷	Ið 	Iús   —A$DÄD%c                óž  — t        j                  | j                  | j                  d¬«      }| j	                  |j
                  «       t        j                  t        j                  | j                  «      t        j                     «      }t        j                  j                  «       r| j                  |d«       y| j                  |d«       y)zG
        Test specifying the permissions used on the log file.
        é6   rw   é$  N)r   r.   r   r   r   r    rb   r€   r   r   rc   r   ÚplatformÚ	isWindowsr2   )r   r{   rd   s      r   Útest_specifiedPermissionsz&LogFileTests.test_specifiedPermissions  s„   € ô �‰˜tŸy™y¨$¯(©(ÀÔFˆØ�‰˜Ÿ
™
Ô#Ü�|‰|œBŸG™G D§I¡IÓ.¬t¯|©|Ñ<Ó=ˆÜ×Ñ×%Ñ%Ô'à×Ñ˜T 5Õ)à×Ñ˜T 5Õ)r   zCan't test reopen on Windowsc                ó´  — t        j                  t        j                  | j                  | j
                  «      «      5 }|j                  d«       t        j                  j                  | j
                  d«      }t        j                  | j                  |«       |j                  «        |j                  d«       ddd«       t        | j                  «      5 }| j                  |j                  «       d«       ddd«       t        «      5 }| j                  |j                  «       d«       ddd«       y# 1 sw Y   Œ|xY w# 1 sw Y   ŒJxY w# 1 sw Y   yxY w)z‹
        L{logfile.LogFile.reopen} allows to rename the currently used file and
        make L{logfile.LogFile} create a new file.
        Úhello1zsave.logÚhello2N)r,   r-   r   r.   r   r   r/   r   r   r   ÚrenameÚreopenr1   r2   r3   )r   r{   ÚsavePathr5   s       r   Útest_reopenzLogFileTests.test_reopen  sú   € ô ×Ñ¤§¡°·	±	¸4¿8¹8Ó DÓEð 	!ÈØ�J‰J�xÔ Ü—w‘w—|‘| D§H¡H¨jÓ9ˆHÜ�I‰I�d—i‘i Ô*Ø�K‰KŒMØ�J‰J�xÔ ÷	!ô �$—)‘)‹_ð 	1 Ø×Ñ˜QŸV™V›X xÔ0÷	1ä�(‹^ð 	1˜qØ×Ñ˜QŸV™V›X xÔ0÷	1ð 	1÷	!ð 	!ú÷	1ð 	1ú÷	1ð 	1ús$   ¾A=D6Ã!EÄ!EÄ6D?ÅEÅEc                ó¸   — | j                  t        t        j                  | j                  d«      }| j                  |j                  t        j                  «       y)zR
        Specifying an invalid directory to L{LogFile} raises C{IOError}.
        Úthis_dir_does_not_existN)r!   ÚIOErrorr   r.   r   r2   ÚerrnoÚENOENT)r   Úes     r   Útest_nonExistentDirz LogFileTests.test_nonExistentDir   s@   € ð ×ÑÜ”W—_‘_ d§i¡iÐ1Jó
ˆð 	×Ñ˜Ÿ™¤%§,¡,Õ/r   c                ó4  — t         j                  j                  «       rd\  }}d}nd\  }}d}t        j                  ||d¬«      }| j                  |j                  «       | j                  |j                  |«       | j                  |j                  d«       y)z„
        Opening a L{LogFile} which can be read and write but whose mode can't
        be changed doesn't trigger an error.
        )ÚNULr>   r˜   )Únullz/devz	/dev/nullrg   rw   N)
r   r†   r‡   r   r.   r   r    r2   r   rx   )r   r   Ú	directoryÚexpectedPathr%   s        r   Útest_cantChangeFileModez$LogFileTests.test_cantChangeFileMode)  s|   € ô
 ×Ñ×%Ñ%Ô'Ø'‰OˆD�)Ø ‰Là,‰OˆD�)Ø&ˆLä�o‰o˜d I¸5ÔAˆØ�‰˜Ÿ	™	Ô"à×Ñ˜Ÿ™ <Ô0Ø×Ñ˜Ÿ™¨%Õ0r   c                óÌ  — t        j                  | j                  | j                  «      }| j	                  |j
                  «       t        |j                  › d�d«      5 }|j                  d«       ddd«       t        |j                  › d�d«      5 }|j                  d«       ddd«       | j                  dg|j                  «       «       y# 1 sw Y   Œ^xY w# 1 sw Y   Œ7xY w)zl
        L{LogFile.listLogs} doesn't choke if it encounters a file with an
        unexpected name.
        r<   r]   r(   Nz	.bad-filerB   )r   r.   r   r   r   r    r1   r   r/   r2   rH   rs   s      r   Ú test_listLogsWithBadlyNamedFilesz-LogFileTests.test_listLogsWithBadlyNamedFiles;  s³   € ô
 �o‰o˜dŸi™i¨¯©Ó2ˆØ�‰˜Ÿ	™	Ô"ä�S—X‘X�J˜b�/ 3Ó'ð 	¨2Ø�H‰H�UŒO÷	ä�S—X‘X�J˜iÐ(¨#Ó.ð 	°"Ø�H‰H�UŒO÷	ð 	×Ñ˜!˜˜cŸl™l›nÕ-÷	ð 	ú÷	ð 	ús   ÁCÂCÃCÃC#c                óv  — t        j                  | j                  | j                  «      }| j	                  |j
                  «       t        dd«      D ]7  }t        |j                  › d|› �d«      5 }|j                  d«       ddd«       Œ9 | j                  ddg|j                  «       «       y# 1 sw Y   ŒfxY w)	zR
        L{LogFile.listLogs} ignores log files which rotated suffix is 0.
        r   rD   ú.r]   r(   NrB   rC   )r   r.   r   r   r   r    Úranger1   r   r/   r2   rH   )r   r%   Úirt   s       r   Ú%test_listLogsIgnoresZeroSuffixedFilesz2LogFileTests.test_listLogsIgnoresZeroSuffixedFilesJ  s�   € ô �o‰o˜dŸi™i¨¯©Ó2ˆØ�‰˜Ÿ	™	Ô"ä�q˜!“ò 	 ˆAÜ˜Ÿ™˜
 ! A 3Ð'¨Ó-ð  °Ø—‘˜”÷ ð  ð	 ð 	×Ñ˜!˜Q˜ §¡£Õ0÷ ð  ús   Á0B/Â/B8	N©ÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r&   r6   rI   rR   r[   r_   re   rl   ru   r}   r‚   rˆ   r   r   r†   r‡   r�   r–   rœ   rž   r£   © r   r   r	   r	      s�   „ ñó6ó'óAó5ó4ó:5ó*)5óV
2óAó.ó>;ó0=ó
$ó*ñ ˆG×Ñ×&Ñ&Ó(Ð*HÓIò1ó Jð1ó"0ó1ó$.ô1r   r	   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚRiggedDailyLogFileç        c                ól   — t         j                  j                  | «       | j                  «       | _        y )N)r   ÚDailyLogFileÚ	_openFileÚtoDateÚlastDater   s    r   r±   zRiggedDailyLogFile._openFile[  s#   € Ü×Ñ×&Ñ& tÔ,àŸ™›ˆ�r   c                ót   — |rt        j                  |Ž d d S t        j                  | j                  «      d d S )NrD   )ÚtimeÚgmtimeÚ_clock)r   Úargss     r   r²   zRiggedDailyLogFile.toDate`  s5   € ÙÜ—;‘; Ð% b qÐ)Ð)Ü�{‰{˜4Ÿ;™;Ó'¨¨Ð+Ð+r   Nr¤   )r¸   Úfloatr¥   ztuple[int, int, int])r§   r¨   r©   r·   r±   r²   r«   r   r   r­   r­   X  s   „ Ø€Fó&ô
,r   r­   c                  ó¨   — e Zd ZdZdd„Zdd„Zdd„Zdd„Zdd„Z e	e
j                  j                  «       d«      dd„«       Zdd	„Zdd
„Zdd„Zdd„Zy)ÚDailyLogFileTestsz!
    Test rotating log file.
    c                óì   — | j                  «       | _        t        j                  | j                  «       d| _        t        j
                  j                  | j                  | j                  «      | _        y )Nztestdaily.logr   r   s    r   r   zDailyLogFileTests.setUpk  sD   € Ø—;‘;“=ˆŒÜ
�‰�D—H‘HÔØ#ˆŒ	Ü—G‘G—L‘L §¡¨4¯9©9Ó5ˆ�	r   c                ó®  — t        j                  t        | j                  | j                  «      «      5 }|j                  d«       |j                  d«       |j                  «        |j                  d«       ddd«       t        | j                  «      5 }| j                  |j                  «       d«       ddd«       y# 1 sw Y   ŒHxY w# 1 sw Y   yxY w)zO
        A daily log file can be written to like an ordinary log file.
        r(   r)   r*   Nr+   )r,   r-   r­   r   r   r/   r0   r1   r   r2   r3   r4   s      r   r6   zDailyLogFileTests.test_writingq  s¥   € ô ×ÑÔ 2°4·9±9¸d¿h¹hÓ GÓHð 	ÈCØ�I‰I�eÔØ�I‰I�eÔØ�I‰IŒKØ�I‰I�fÔ÷		ô �$—)‘)‹_ð 	5 Ø×Ñ˜QŸV™V›X |Ô4÷	5ð 	5÷	ð 	ú÷	5ð 	5ús   ´AB?Â!CÂ?CÃCc                ó4  — t        | j                  | j                  «      }| j                  |j                  «       t        d«      D �cg c]&  }| j                  dz   |j                  |dz  «      z   ‘Œ( }}d|_        |j                  d«       d|_        |j                  d«       d|_        |j                  d«       | j                  t        j                  j                  |d	   «      «       | j                  t        j                  j                  |d
   «      «       d|_        |j                  d«       | j                  t        j                  j                  |d	   «      «       | j                  t        j                  j                  |d
   «      «       | j                  t        j                  j                  |d   «      «       d|_        |j                  d«       | j                  t        j                  j                  |d   «      «       yc c}w )z/
        Daily log files rotate daily.
        rD   r    é€Q r®   r(   iÀ¨  r:   r;   r   rB   i £ r>   rC   iô r@   N)r­   r   r   r   r    r¡   r   Úsuffixr·   r/   rE   r   r   rF   )r   r%   ÚdayÚdayss       r   rI   zDailyLogFileTests.test_rotation~  sr  € ô ! §¡¨D¯H©HÓ5ˆØ�‰˜Ÿ	™	Ô"ÜGLÈQÃxÖPÀ�—‘˜S‘ 3§:¡:¨c°E©kÓ#:Ó:ÐPˆÐPð ˆŒ
Ø�	‰	�%ÔØˆŒ
Ø�	‰	�)ÔØˆŒ
Ø�	‰	�(ÔØ�‰œŸ™Ÿ™ t¨A¡wÓ/Ô0Ø×ÑœŸ™Ÿ™¨¨Q©Ó0Ô1ØˆŒ
Ø�	‰	�"ŒØ�‰œŸ™Ÿ™ t¨A¡wÓ/Ô0Ø�‰œŸ™Ÿ™ t¨A¡wÓ/Ô0Ø×ÑœŸ™Ÿ™¨¨Q©Ó0Ô1ØˆŒ
Ø�	‰	�#ŒØ×ÑœŸ™Ÿ™¨¨Q©Ó0Õ1ùò% Qs   Á	+Hc                ó’  — g d¢}t        | j                  | j                  «      }| j                  |j                  «       |D ]  }|j                  |«       Œ |j                  «        |j                  d«      }| j                  |j                  «       | j                  ||j                  «       «       | j                  t        |j                  d«       d|_        |j	                  «        |j                  «        |j                  d«      }| j                  |j                  «       | j                  ||j                  «       «       y)zH
        Test retrieving log files with L{DailyLogFile.getLog}.
        )z1
z2
z3
r®   r¿   i�Q r   N)r­   r   r   r   r    r/   r0   rW   r2   rV   r!   rX   r·   rG   )r   Údatar%   ÚdÚrs        r   Útest_getLogzDailyLogFileTests.test_getLog˜  sé   € ò %ˆÜ  §¡¨D¯H©HÓ5ˆØ�‰˜Ÿ	™	Ô"Øò 	ˆAØ�I‰I�a�Lð	à�	‰	Œð �J‰J�s‹OˆØ�‰˜Ÿ™Ô à×Ñ˜˜qŸ{™{›}Ô-ð 	×Ñœ* c§j¡j°%Ô8àˆŒ
Ø	�‰Œ	Ø�
‰
ŒØ�J‰J�q‹MˆØ�‰˜Ÿ™Ô Ø×Ñ˜˜qŸ{™{›}Õ-r   c                ó¢  — t        | j                  | j                  «      }| j                  |j                  «       |j
                  › d|j                  |j                  «      › �}t        |d«      5 }|j                  d«       ddd«       |j                  }|j                  «        | j                  ||j                  «       y# 1 sw Y   ŒBxY w)zu
        L{DailyLogFile.rotate} doesn't do anything if they new log file already
        exists on the disk.
        r    r]   r(   N)r­   r   r   r   r    r   rÀ   r³   r1   r/   rO   rG   r2   )r   r%   ÚnewFilePathrt   ÚpreviousFiles        r   Útest_rotateAlreadyExistsz*DailyLogFileTests.test_rotateAlreadyExists³  sž   € ô
 ! §¡¨D¯H©HÓ5ˆØ�‰˜Ÿ	™	Ô"ð Ÿ™˜
 ! C§J¡J¨s¯|©|Ó$<Ð#=Ð>ˆÜ�+˜sÓ#ð 	 rØ�H‰H�UŒO÷	à—y‘yˆØ�
‰
ŒØ×Ñ˜ s§y¡yÕ1÷		ð 	ús   Á2CÃCzVMaking read-only directories on Windows is too complex for this test to reasonably do.c                ó”  — t        j                  | j                  | j                  «      }| j	                  |j
                  «       t        j                  |j                  d«       | j	                  t        j                  |j                  d«       |j                  }|j                  «        | j                  ||j                  «       y)zƒ
        L{DailyLogFile.rotate} doesn't do anything if the directory containing
        the log files can't be written to.
        r…   ií  N)r   r°   r   r   r   r    r   r   rš   rO   rG   r2   ©r   r%   rÊ   s      r   Ú#test_rotatePermissionDirectoryNotOkz5DailyLogFileTests.test_rotatePermissionDirectoryNotOkÄ  s~   € ô ×"Ñ" 4§9¡9¨d¯h©hÓ7ˆØ�‰˜Ÿ	™	Ô"ä
�‰�—‘ Ô&à�‰œŸ™ #§-¡-°Ô7Ø—y‘yˆØ�
‰
ŒØ×Ñ˜ s§y¡yÕ1r   c                ó>  — t        j                  | j                  | j                  «      }| j	                  |j
                  «       t        j                  |j                  d«       |j                  }|j                  «        | j                  ||j                  «       y)zi
        L{DailyLogFile.rotate} doesn't do anything if the log file can't be
        written to.
        r…   N)r   r°   r   r   r   r    r   r   r   rO   rG   r2   rÍ   s      r   Útest_rotatePermissionFileNotOkz0DailyLogFileTests.test_rotatePermissionFileNotOkØ  sf   € ô
 ×"Ñ" 4§9¡9¨d¯h©hÓ7ˆØ�‰˜Ÿ	™	Ô"ä
�‰�—‘˜5Ô!Ø—y‘yˆØ�
‰
ŒØ×Ñ˜ s§y¡yÕ1r   c                óú   — t        j                  | j                  | j                  «      }| j	                  |j
                  «       t        j                  d«      }| j                  d|j                  |«      «       y)z~
        Test that L{DailyLogFile.toDate} converts its timestamp argument to a
        time tuple (year, month, day).
        )	éÐ  rB   rB   r   r   r   r   r   r   )rÒ   rB   rB   N)
r   r°   r   r   r   r    rµ   Úmktimer2   r²   )r   r%   Ú	timestamps      r   Útest_toDatezDailyLogFileTests.test_toDateå  sV   € ô
 ×"Ñ" 4§9¡9¨d¯h©hÓ7ˆØ�‰˜Ÿ	™	Ô"ä—K‘KÐ >Ó?ˆ	Ø×Ñ˜ s§z¡z°)Ó'<Õ=r   c                ó  ‡ — dˆ fd„}t        j                  ‰ j                  ‰ j                  «      }‰ j	                  |j
                  «       ‰ j                  t        d|«       |j                  «       }‰ j                  g d¢|«       y)aË  
        Test that L{DailyLogFile.toDate} returns today's date by default.

        By mocking L{time.localtime}, we ensure that L{DailyLogFile.toDate}
        returns the first 3 values of L{time.localtime} which is the current
        date.

        Note that we don't compare the *real* result of L{DailyLogFile.toDate}
        to the *real* current date, as there's a slight possibility that the
        date changes between the 2 function calls.
        c                 óR   •— ‰j                  d| «       t        t        dd«      «      S )Nr«   r   é	   )r2   Úlistr¡   )r¸   r   s    €r   Úmock_localtimezADailyLogFileTests.test_toDateDefaultToday.<locals>.mock_localtimeý  s$   ø€ Ø×Ñ˜R Ô&Üœ˜a ›Ó$Ð$r   Ú	localtime)r   rB   rC   N)r¸   Úobjectr¥   z	list[int])
r   r°   r   r   r   r    Úpatchrµ   r²   r2   )r   rÚ   r%   ÚlogDates   `   r   Útest_toDateDefaultTodayz)DailyLogFileTests.test_toDateDefaultTodayð  s_   ø€ õ	%ô ×"Ñ" 4§9¡9¨d¯h©hÓ7ˆØ�‰˜Ÿ	™	Ô"à�
‰
”4˜ nÔ5Ø—*‘*“,ˆØ×Ñš GÕ,r   c                ó  — t        j                  | j                  | j                  «      }| j	                  |j
                  «       d}t        j                  |dz   «      }|j                  |«      }| j                  ||«       y)zc
        Test that L{DailyLogFile.toDate} uses its arguments to create a new
        date.
        )iÞ  r8   é   )r   r   r   r   r   r   N)
r   r°   r   r   r   r    rµ   rÓ   r²   r2   )r   r%   ÚdateÚsecondsrÞ   s        r   Ú#test_toDateUsesArgumentsToMakeADatez5DailyLogFileTests.test_toDateUsesArgumentsToMakeADate  sc   € ô
 ×"Ñ" 4§9¡9¨d¯h©hÓ7ˆØ�‰˜Ÿ	™	Ô"àˆÜ—+‘+˜d X™oÓ.ˆà—*‘*˜WÓ%ˆØ×Ñ˜˜wÕ'r   Nr¤   )r§   r¨   r©   rª   r   r6   rI   rÇ   rË   r   r   r†   r‡   rÎ   rÐ   rÕ   rß   rä   r«   r   r   r»   r»   f  sd   „ ñó6ó5ó2ó4.ó62ñ" Ø×Ñ×"Ñ"Ó$ð	!óò
2óð
2ó2ó	>ó-ô0(r   r»   )Ú
__future__r   r,   r“   r   rb   rµ   Úunittestr   Útwisted.pythonr   r   Útwisted.trial.unittestr   r	   r°   r­   r»   r«   r   r   ú<module>ré      sQ   ðõ #ã Û Û 	Û Û Ý ç +Ý +ôE1�8ô E1ôP
,˜×-Ñ-ô ,ôn(˜õ n(r   