
    ;e                        	 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 d dlmZmZ  ed          Zd Z e            Z G d d	          Zd
 Zd Z G d dej                  Zedk    r ej                     dS dS )    N)Process)verbosecpython_only)import_module)TESTFNunlinkfcntlc            
         	 t           j         d} n# t          $ r d} Y nw xY wt          j                            d          st          j        dk    rNt          j        d          dk    rd}d}nd}d}t          j        ||z   |z   d	z   d
d
d
t          j
        d
          }nt          j                            d          r%t          j        dd
d
d
t          j
        d
d
          }n^t          j        dv r&t          j        dt          j
        d
d
d
d
d
d
          }n*t          j        d	| z   d	z   t          j
        d
d
d
d
d
          }|r$t          rt          dt          |                     |S )Nqqll)netbsdfreebsdopenbsddarwinl   ilxxxxhhr   gnukfreebsdqqihhi)zhp-uxB	unixware7hhllliizstruct.pack: )osO_LARGEFILEAttributeErrorsysplatform
startswithstructcalcsizepackr	   F_WRLCKr   printrepr)	start_lenoff_tpid_tlockdatas       &/usr/lib/python3.11/test/test_fcntl.pyget_lockdatar+      sy   
 		    			
 	 @AA R<8##?31$$EEEEE;uu}u4t;Q1$}a1 1		 	 	/	/ R;xAq%-AFF	0	0	0;y%-Aq!QJJ;tI~d2EM1aAqQQ 3 	3/4>>222Os      c                       e Zd Zd Zd ZdS )BadFilec                     || _         d S Nfn)selfr1   s     r*   __init__zBadFile.__init__3   s        c                     | j         S r/   r0   r2   s    r*   filenozBadFile.fileno5   s	    wr4   N)__name__
__module____qualname__r3   r7    r4   r*   r-   r-   2   s2              r4   r-   c                     t          | d          }	 t                              ||           n# t          $ r Y nw xY w|                                 d S # |                                 w xY wNwb+)openr	   lockfBlockingIOErrorclosefnamecmdfs      r*   try_lockf_on_other_process_failrG   8   sr    UEAAs    	
									s!   . A 
;A ;A A*c                     t          | d          }t                              ||           t                              |t          j                   |                                 d S r=   )r?   r	   r@   LOCK_UNrB   rC   s      r*   try_lockf_on_other_processrJ   A   sL    UEA	KK3	KK5=!!!GGIIIIIr4   c                   J   e Zd Zd Zd Zd Zd Zd Zed             Z	 e
j         ej                                        d          o ej                    dk    d	          d
             Zd Z e
j         ej                    dk    d          d             Z e
j         ej                    dk    d          d             Zed             Z e
j        ej        dk    d          d             Z e
j         eed          o eed          d          d             ZdS )	TestFcntlc                     d | _         d S r/   )rF   r6   s    r*   setUpzTestFcntl.setUpI   s    r4   c                     | j         r%| j         j        s| j                                          t          t                     d S r/   )rF   closedrB   r   r   r6   s    r*   tearDownzTestFcntl.tearDownL   s5    6 	$&- 	FLLNNNvr4   c                    t          t          d          | _        t                              | j                                        t          j        t          j                  }t          rt          d|           t                              | j                                        t          j
        t                    }t          rt          dt          |                     | j                                         d S Nwbz#Status from fcntl with O_NONBLOCK: z!String from fcntl with F_SETLKW: )r?   r   rF   r	   r7   F_SETFLr   
O_NONBLOCKr   r$   F_SETLKWr)   r%   rB   r2   rvs     r*   test_fcntl_filenozTestFcntl.test_fcntl_filenoQ   s    fd##[[%-GG 	=7<<<[[%.(CC 	A5tBxx@@@r4   c                    t          t          d          | _        t                              | j        t          j        t
          j                  }t          rt          d|           t                              | j        t          j	        t                    }t          rt          dt          |                     | j                                         d S rS   )r?   r   rF   r	   rU   r   rV   r   r$   rW   r)   r%   rB   rX   s     r*   test_fcntl_file_descriptorz$TestFcntl.test_fcntl_file_descriptor\   s    fd##[[>> 	=7<<<[[:: 	A5tBxx@@@r4   c                 L   |                      t                    5  t                              dt          j        t          j                   d d d            n# 1 swxY w Y   |                      t                    5  t                              t          d          t          j        t          j                   d d d            n# 1 swxY w Y   |                      t                    5  t                              dt          j        t          j                   d d d            n# 1 swxY w Y   |                      t                    5  t                              t          d          t          j        t          j                   d d d            d S # 1 swxY w Y   d S )Nspam)assertRaises
ValueErrorr	   rU   r   rV   r-   	TypeErrorr6   s    r*   test_fcntl_bad_filezTestFcntl.test_fcntl_bad_fileg   sN   z** 	: 	:KKEM2=999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:z** 	C 	CKKU]BMBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cy)) 	> 	>KKr}===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>y)) 	G 	GKKFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	GsG   1AAA=>CCC,1D))D-0D->FF Fc                 t   ddl m}m} |                     t                    5  t
                              |dz   t
          j        t          j                   d d d            n# 1 swxY w Y   |                     t                    5  t
                              t          |dz             t
          j        t          j                   d d d            n# 1 swxY w Y   |                     t                    5  t
                              |dz
  t
          j        t          j                   d d d            n# 1 swxY w Y   |                     t                    5  t
                              t          |dz
            t
          j        t          j                   d d d            d S # 1 swxY w Y   d S )Nr   )INT_MAXINT_MIN   )
	_testcapire   rf   r`   OverflowErrorr	   rU   r   rV   r-   )r2   re   rf   s      r*   test_fcntl_bad_file_overflowz&TestFcntl.test_fcntl_bad_file_overflowq   s   ........}-- 	C 	CKK!U]BMBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C}-- 	L 	LKK!,,emR]KKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L}-- 	C 	CKK!U]BMBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C}-- 	L 	LKK!,,emR]KKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	LsI   4A##A'*A'ACCC:4D::D>D>AF--F14F1armLinuxz2ARM Linux returns EINVAL for F_NOTIFY DN_MULTISHOTc                    	 t           j        }t           j        }n%# t          $ r |                     d           Y nw xY wt          j        t
          j                            t
          j        	                    t                              t
          j                  }	 t                                |||           t          j        |           d S # t          j        |           w xY w)Nz$F_NOTIFY or DN_MULTISHOT unavailable)r	   F_NOTIFYDN_MULTISHOTr   skipTestr   r?   pathdirnameabspathr   O_RDONLYrB   )r2   rE   flagsfds       r*   test_fcntl_64_bitzTestFcntl.test_fcntl_64_bit~   s    	B.C&EE 	B 	B 	BMM@AAAAA	BWRW__RW__V%<%<==r{KK	KKC'''HRLLLLLBHRLLLLs    ==C C'c                    t          t          d          | _        | j                                        }t                              |t          j                   t                              |t          j                   t                              | j        t          j        t          j        z             t                              | j        t          j                   t                              |t          j	                   t                              |t          j                   | 
                    t          t          j        dt          j                   | 
                    t          t          j        dt          j                   d S )Nr>   r^   r_   )r?   r   rF   r7   r	   flockLOCK_SHrI   LOCK_NBLOCK_EXr`   ra   rb   )r2   r7   s     r*   
test_flockzTestFcntl.test_flock   s    fe$$FEM***FEM***DFEMEM9:::DFEM***FEM***FEM****ek2u}EEE)U[&%-HHHHHr4   AIXzAIX returns PermissionErrorc                    t          t          d          | _        t          j        t          j        z  }t                              | j        |           t          t          t          |f          }|	                                 |
                                 t                              | j        t          j                   |                     |j        d           d S Nr>   )targetargsr   )r?   r   rF   r	   r|   r{   r@   r   rG   startjoinrI   assertEqualexitcoder2   rE   ps      r*   test_lockf_exclusivezTestFcntl.test_lockf_exclusive   s    fe$$mem+DFC   :&#OOO					DFEM***Q'''''r4   c                    t          t          d          | _        t          j        t          j        z  }t                              | j        |           t          t          t          |f          }|	                                 |
                                 t                              | j        t          j                   |                     |j        d           d S r   )r?   r   rF   r	   rz   r{   r@   r   rJ   r   r   rI   r   r   r   s      r*   test_lockf_sharezTestFcntl.test_lockf_share   s    fe$$mem+DFC   5VSMJJJ					DFEM***Q'''''r4   c                     dd l }|                     t          t          j        |j        dz   t          j                   d S )Nr   rg   )rh   r`   ri   r	   ry   re   rz   )r2   rh   s     r*   test_flock_overflowzTestFcntl.test_flock_overflow   sE    -i6G6I-	) 	) 	) 	) 	)r4   r   z$F_GETPATH is only available on macosc           	         t          t          d          | _        t          j                            t                                        d          }t                              | j                                        t          j	        t          t          |                              }|                     ||           d S )NrT   zutf-8)r?   r   rF   r   rq   rs   encoder	   r7   	F_GETPATHbyteslenr   )r2   expectedress      r*   test_fcntl_f_getpathzTestFcntl.test_fcntl_f_getpath   s    fd##7??6**11'::kk$&--//5?E#h--<P<PQQ3'''''r4   F_SETPIPE_SZF_GETPIPE_SZzAF_SETPIPE_SZ and F_GETPIPE_SZ are not available on all platforms.c                 $   t          j                    \  }}	 t                              |t          j                  }|dz  }|dk     rt	          j        d          t                              |t          j        |           |                     t                              |t          j                  |           t          j        |           t          j        |           d S # t          j        |           t          j        |           w xY w)N   i   z+default pipesize too small to perform test.)	r   piper	   r   unittestSkipTestr   r   rB   )r2   test_pipe_rtest_pipe_wpipesize_defaultpipesizes        r*   test_fcntl_f_pipesizezTestFcntl.test_fcntl_f_pipesize   s     $&799 [	"${{;8JKK'1,H#~~'AC C CKKU%7BBBU[[e6HII%' ' ' H[!!!H[!!!!! H[!!!H[!!!!s   B#C% %*DN)r8   r9   r:   rN   rQ   rZ   r\   rc   r   rj   r   skipIfr   machiner   systemrw   r}   r   r   r   r   r   
skipUnlesshasattrr	   r   r;   r4   r*   rL   rL   G   s	           
	 	 		 	 	G G G 
L 
L \
L X_%%e,,M1B1Bg1M<> > > >I I I X__X_&&%/1NOO( ( PO( X__X_&&%/1NOO( ( PO( ) ) \)
 X_S\X-/UVV( ( WV( X~&&I775.+I+IKM M" "M M" " "r4   rL   __main__)r   r   r    r   r   multiprocessingr   test.supportr   r   test.support.import_helperr   test.support.os_helperr   r   r	   r+   r)   r-   rG   rJ   TestCaserL   r8   mainr;   r4   r*   <module>r      sZ    				  



  # # # # # # . . . . . . . . 4 4 4 4 4 4 1 1 1 1 1 1 1 1 	g  : <>>           K" K" K" K" K"! K" K" K"\ zHMOOOOO r4   