
    Yfg                         d Z ddlZddlZddlmZ ddlm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          ZdS )z
Test strerror
    N)skipIf)ECONNABORTED)platform)_ErrorFormatterformatError)TestCasec                       e Zd ZdZdS )_MyWindowsExceptionzT
    An exception type like L{ctypes.WinError}, but available on all platforms.
    N)__name__
__module____qualname____doc__     L/var/www/html/env/lib/python3.11/site-packages/twisted/test/test_strerror.pyr
   r
      s           r   r
   c                       e Zd ZdZeZdZd Zd Zd Z	d Z
d Z e ej                    dk    d	          d
             Z e ej                    dk    d	          d             ZdS )ErrorFormatingTestsz3
    Tests for C{_ErrorFormatter.formatError}.
    zcorrect message valuec                     t          ddd          }|                    | j                  }|                     |t	          j        | j                             dS )z
        L{_ErrorFormatter.formatError} should use L{os.strerror} to format
        error messages if it is constructed without any better mechanism.
        N)r   r   probeErrorCodeassertEqualosstrerrorself	formattermessages      r   test_strerrorFormattingz+ErrorFormatingTests.test_strerrorFormatting    sT    
 $D$55	''(;<<"+d.A"B"BCCCCCr   c                     d}|                      | j        |           t          dd|di          }|                    | j                  }|                     |t          j        | j                             dS )z
        L{_ErrorFormatter.formatError} should use L{os.strerror} to format
        error messages if it is constructed with only an error tab which does
        not contain the error code it is called with.
           Nwrong message)assertNotEqualr   r   r   r   r   r   )r   errorr   r   s       r   test_emptyErrorTabz&ErrorFormatingTests.test_emptyErrorTab)   sw     D/777#D$0HII	''(;<<"+d.A"B"BCCCCCr   c                     t          dd| j        | j        i          }|                    | j                  }|                     || j                   dS )z
        L{_ErrorFormatter.formatError} should use C{errorTab} if it is supplied
        and contains the requested error code.
        N)r   r   probeMessager   r   r   s      r   test_errorTabz!ErrorFormatingTests.test_errorTab6   s\    
 $$,d.?@
 
	 ''(;<<$"344444r   c                      g  fd}t          d| j        di          }|                     j                  }                     | j                                         j        g           dS )z~
        L{_ErrorFormatter.formatError} should return the return value of
        C{formatMessage} if it is supplied.
        c                 <                         |            j        S N)appendr%   )	errorCodeformatCallsr   s    r   formatMessagez=ErrorFormatingTests.test_formatMessage.<locals>.formatMessageH   s     y)))$$r   Nr    r   r   r   r   r%   )r   r-   r   r   r,   s   `   @r   test_formatMessagez&ErrorFormatingTests.test_formatMessageA   s    
 	% 	% 	% 	% 	% 	% $-$"5!G
 
	 ''(;<<$"3444t':&;<<<<<r   c                      g  fd}t          |d  j        di          }|                     j                  }                     | j                   dS )z
        L{_ErrorFormatter.formatError} should return the message argument from
        the exception L{winError} returns, if L{winError} is supplied.
        c                 X                         |            t          | j                  S r)   )r*   r
   r%   )r+   r   winCallss    r   winErrorz3ErrorFormatingTests.test_winError.<locals>.winErrorZ   s(    OOI&&&&y$2CDDDr   c                     dS )NzformatMessage: wrong messager   )r"   s    r   <lambda>z3ErrorFormatingTests.test_winError.<locals>.<lambda>`   s    8 r   zerrorTab: wrong messageNr.   )r   r3   r   r   r2   s   `   @r   test_winErrorz!ErrorFormatingTests.test_winErrorS   s    
 	E 	E 	E 	E 	E 	E $88 ";<
 
	
 ''(;<<$"344444r   win32zTest will run only on Windows.c                    t          j                    }|j        Nddlm} |                     |                    | j                   || j                  j                   d|_        |j	        Iddl
m} |                     |                    | j                   || j                             d|_	        |j        Addlm} |                     |                    | j                  || j                            dS dS )z
        L{_ErrorFormatter.fromEnvironment} should create an L{_ErrorFormatter}
        instance with attributes populated from available modules.
        Nr   WinErrorFormatMessage)errorTab)r   fromEnvironmentr3   ctypesr:   r   r   r   r   r-   win32apir<   r=   socket)r   r   r:   r<   r=   s        r   test_fromEnvironmentz(ErrorFormatingTests.test_fromEnvironmentf   s;    $355	)''''''%%d&9::,--6   "&I".......%%d&9::d122   '+I#)''''''%%d&9::,-     *)r   c                 |   t           j        t                   g}	 ddlm} |                     |t                    j                   n# t          $ r Y nw xY w	 ddlm	} |                     |t                               n# t          $ r Y nw xY w| 
                    t          t                    |           dS )z
        Given a known-good errno, make sure that formatMessage gives results
        matching either C{socket.errorTab}, C{ctypes.WinError}, or
        C{win32api.FormatMessage}.
        r   r9   r;   N)rA   r=   r   r?   r:   r*   r   ImportErrorr@   r<   assertInr   )r   
acceptabler:   r<   s       r   test_correctLookupsz'ErrorFormatingTests.test_correctLookups   s     ol34
	''''''hh|44=>>>> 	 	 	D		......mmL99:::: 	 	 	D	 	k,//<<<<<s#   .A	 	
AA)B 
BBN)r   r   r   r   r   r   r%   r   r#   r&   r/   r6   r   r   getTyperB   rG   r   r   r   r   r      s          "N*LD D DD D D	5 	5 	5= = =$5 5 5& VH')+KLL  MLB VH')+KLL= = ML= = =r   r   )r   r   rA   unittestr   twisted.internet.tcpr   twisted.python.runtimer   twisted.python.win32r   r   twisted.trial.unittestr   OSErrorr
   r   r   r   r   <module>rO      s     
			        - - - - - - + + + + + + = = = = = = = = + + + + + +    '   E= E= E= E= E=( E= E= E= E= E=r   