
    4pfM                     |   d dl mZ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Zd dl	Z	d dl
mZ d dlmZmZmZmZmZ d dlmZmZmZ erd dlZd Zd Z G d d	e          Z G d
 de          Z G d de          Z G d dej                  Z ej        ed          Zd Z d Z!d Z"d Z# e$ej        d          sej        j%        ej        _&        ddZ' e$ej        d          s eej        de'            G d de(          Z) G d de)          Z*ddZ+ e$ej        d          s eej        de+           dS dS )    )print_functionabsolute_importN)dedent)bind_methodPY26PY3PY2PY27)check_outputSTDOUTCalledProcessErrorc                 ^    |                      d          r
| dd         } t          |           S )z,
    Removes any leading 
 and dedents.
    
   N)
startswithr   )codes    Q/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/future/tests/base.pyreformat_coder      s1     t ABBx$<<    c                 
   |                      d          d t                    D             }d t                    D             }d t                    D             }|                                 | k    s
J d            d }d } ||           ||          k    s
J d            t          fd	|D                       }t	          t          ||                    }t          fd
|D                       }t	          t          ||                    }	t          fd|D                       }
t	          t          ||
                    }g }t          t                              D ]}}||v r|                    ||                    "||v r|                    |	|                    B||v r|                    ||                    b|                    |                    ~d	                    |          S )a  
    Returns the code block with any ``__future__`` import lines sorted, and
    then any ``future`` import lines sorted, then any ``builtins`` import lines
    sorted.

    This only sorts the lines within the expected blocks.

    See test_order_future_lines() for an example.
    r   c                 B    g | ]\  }}|                     d           |S )from __future__ import r   .0ilines      r   
<listcomp>z&order_future_lines.<locals>.<listcomp>*   sD     N N N71d"&//2K"L"LNQ N N Nr   c                 l    g | ]1\  }}|                     d           s|                     d          /|2S )zfrom futurez	from pastr   r   s      r   r   z&order_future_lines.<locals>.<listcomp>-   sP     > > >D $ > >> $ < <>1 > > >r   c                 B    g | ]\  }}|                     d           |S )zfrom builtinsr   r   s      r   r   z&order_future_lines.<locals>.<listcomp>1   sC     B B B71d $ @ @BQ B B Br   zIinternal usage error: dedent the code before calling order_future_lines()c                 J    t          |           dk    rt          |           ndS )Nr   )lenmaxnumberss    r   mymaxz!order_future_lines.<locals>.mymax7   s"    "7||a//s7|||Q6r   c                 d    t          |           dk    rt          |           nt          d          S )Nr   inf)r"   minfloatr$   s    r   myminz!order_future_lines.<locals>.mymin:   s(    "7||a//s7|||U5\\Ar   z2the __future__ and future imports are out of orderc                      g | ]
}|         S  r-   r   r   liness     r   r   z&order_future_lines.<locals>.<listcomp>C   s    :::q%(:::r   c                      g | ]
}|         S r-   r-   r.   s     r   r   z&order_future_lines.<locals>.<listcomp>F   s    777aq777r   c                      g | ]
}|         S r-   r-   r.   s     r   r   z&order_future_lines.<locals>.<listcomp>I   s    999aq999r   )
split	enumeratelstripsorteddictzipranger"   appendjoin)r   uufuture_line_numbersfuture_line_numbersbuiltins_line_numbersr&   r+   uulsorted_uufuture_linesflsorted_future_linesblsorted_builtins_lines	new_linesr   r/   s                 @r   order_future_linesrE      s    JJtEN Ni.>.> N N N> >Ie,<,< > > >B Bi.>.> B B B ;;==D    $B   7 7 7B B B 5&''551D+E+EEEE@ FEE ::::$9:::
;
;C %:C!@!@AA	7777#6777	8	8Bs#6;;<<	9999#8999	:	:B %:B!?!?@@ I3u:: ' '%%%2156666%%%034444'''2156666U1X&&&&99Yr   c                        e Zd ZdZddZd ZdS )VerboseCalledProcessErrorz
    Like CalledProcessError, but it displays more information (message and
    script output) for diagnosing test failures etc.
    Nc                 >    || _         || _        || _        || _        d S N)msg
returncodecmdoutput)selfrJ   rK   rL   rM   s        r   __init__z"VerboseCalledProcessError.__init__`   s"    $r   c                 <    d| j         | j        | j        | j        fz  S )Nz>Command '%s' failed with exit status %d
Message: %s
Output: %s)rL   rK   rJ   rM   )rN   s    r   __str__z!VerboseCalledProcessError.__str__f   s%    R8T_dhDE 	Fr   rI   )__name__
__module____qualname____doc__rO   rQ   r-   r   r   rG   rG   [   sF            F F F F Fr   rG   c                       e Zd ZdS )FuturizeErrorNrR   rS   rT   r-   r   r   rW   rW   j           Dr   rW   c                       e Zd ZdS )PasteurizeErrorNrX   r-   r   r   r[   r[   m   rY   r   r[   c                   z    e Zd ZdZd Z	 	 ddZddZd Z	 	 	 dd	Zd
 Z	ddZ
ddZ	 	 	 ddZdej        fdZdS )CodeHandlerzt
    Handy mixin for test classes for writing / reading / futurizing /
    running .py files in the test suite.
    c                    t          d          | _        t          d          | _        t          j        g| _        t          j                    t          j	        j
        z   | _        t          j        d          }|r,dt          j                    t          j        z   |z   i| _        dS dt          j                    i| _        dS )zi
        The outputs from the various futurize stages should have the
        following headers:
        z
        from __future__ import absolute_import
        from __future__ import division
        from __future__ import print_function
        a4  
        from __future__ import absolute_import
        from __future__ import division
        from __future__ import print_function
        from __future__ import unicode_literals
        from future import standard_library
        standard_library.install_aliases()
        from builtins import *
        
PYTHONPATHN)r   headers1headers2sys
executableinterpreterstempfilemkdtempospathseptempdirgetenvgetcwdpathsepenv)rN   pypaths     r   setUpzCodeHandler.setUpv   s     & '   & '   !^,'))BGK7<(( 	3$bikkBJ&>&GHDHHH$bikk2DHHHr   r      FTc                     |rt          |          }|                     |           |                     ||||           |                                 }|r | j        D ]}	|                     |	          }
|S )a  
        Converts the code block using ``futurize`` and returns the
        resulting code.

        Passing stages=[1] or stages=[2] passes the flag ``--stage1`` or
        ``stage2`` to ``futurize``. Passing both stages runs ``futurize``
        with both stages by default.

        If from3 is False, runs ``futurize``, converting from Python 2 to
        both 2 and 3. If from3 is True, runs ``pasteurize`` to convert
        from Python 3 to both 2 and 3.

        Optionally reformats the code block first using the reformat() function.

        If run is True, runs the resulting code under all Python
        interpreters in self.interpreters.
        )stagesall_importsfrom3conservative)interpreter)r   _write_test_script_futurize_test_script_read_test_scriptrd   _run_test_script)rN   r   rt   ru   rv   reformatrunrw   rM   rx   _s              r   convertzCodeHandler.convert   s    &  	' &&D%%%""&k).\ 	# 	K 	K 	K'')) 	C#0 C C))k)BBr   c                    |r*|                      |          }|                      |          }t          |t                    r*t          |t                    s|                    d          }t          |t                    r*t          |t                    s|                    d          }|                     t          |                                          |                                           dS )a  
        Compares whether the code blocks are equal. If not, raises an
        exception so the test fails. Ignores any trailing whitespace like
        blank lines.

        If ignore_imports is True, passes the code blocks into the
        strip_future_imports method.

        If one code block is a unicode string and the other a
        byte-string, it assumes the byte-string is encoded as utf-8.
        utf-8N)strip_future_imports
isinstancebytesdecodeassertEqualrE   rstrip)rN   rM   expectedignore_importss       r   comparezCodeHandler.compare   s      	;..v66F00::Hfe$$ 	,Z%-H-H 	,]]7++Fh&& 	0z&%/H/H 	0w//H+FMMOO<<!**	, 	, 	, 	, 	,r   c                 B   g }|                     d          D ]s}|                    d          s\|                    d          sG|                    d          s2d|v s.d|v s*|                    d          s|                    |           td                    |          S )a  
        Strips any of these import lines:

            from __future__ import <anything>
            from future <anything>
            from future.<anything>
            from builtins <anything>

        or any line containing:
            install_hooks()
        or:
            install_aliases()

        Limitation: doesn't handle imports split across multiple lines like
        this:

            from __future__ import (absolute_import, division, print_function,
                                    unicode_literals)
        r   r   zfrom future zfrom builtins zinstall_hooks()zinstall_aliases()zfrom future.)r2   r   r9   r:   )rN   r   rM   r   s       r   r   z CodeHandler.strip_future_imports   s    (  JJt$$ 	$ 	$DOO$=>> $~66$'788$ )D00*d22~66 3 d###yy   r   c	                     |                      ||||||          }	|rd|v r| j        n| j        }
nd}
t          |          }|
|v rd}
|                     |	|
|z   |           dS )a<  
        Convenience method that calls convert() and compare().

        Reformats the code blocks automatically using the reformat_code()
        function.

        If all_imports is passed, we add the appropriate import headers
        for the stage(s) selected to the ``expected`` code-block, so they
        needn't appear repeatedly in the test code.

        If ignore_imports is True, ignores the presence of any lines
        beginning:

            from __future__ import ...
            from future import ...

        for the purpose of the comparison.
        )rt   ru   rv   r~   rw   rr    )r   N)r   ra   r`   r   r   )rN   beforer   rt   ru   r   rv   r~   rw   rM   headersreformatteds               r   convert_checkzCodeHandler.convert_check   s    * fV$)s  O O 	'(F{{dmmGGG#H--k!!GVW{2$2 	 	4 	4 	4 	4 	4r   c                 $     | j         ||fi | dS )ze
        Convenience method to ensure the code is unchanged by the
        futurize process.
        N)r   )rN   r   kwargss      r   	unchangedzCodeHandler.unchanged  s'    
 	40000000r   mytestscript.pyc                    t          |t                    r|                    d          }t          j        | j        |z   dd          5 }|                    t          |                     ddd           dS # 1 swxY w Y   dS )z
        Dedents the given code (a multiline string) and writes it out to
        a file in a temporary folder like /tmp/tmpUDCn7x/mytestscript.py.
        r   wtencodingN)r   r   r   ioopenrj   writer   )rN   r   filenamefs       r   ry   zCodeHandler._write_test_script!  s    
 dE"" 	(;;w''DWT\H,dWEEE 	"GGF4LL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   
#A::A>A>c                     t          j        | j        |z   dd          5 }|                                }d d d            n# 1 swxY w Y   |S )Nrtr   r   )r   r   rj   read)rN   r   r   	newsources       r   r{   zCodeHandler._read_test_script,  s    WT\H,dWEEE 	!I	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   AAAc                    g }t          |          }|r|                    d           |rd}n]d}|dgk    r|                    d           n'|dgk    r|                    d           n
|ddgk    sJ |r|                    d           | j        |z   }t          j        |g|z   d	|gz   }		 t          |	t          | j        
          }
n# t          $ r}t          |          5 }dd
                    |	          dd| j        z  d|dd|                                z  }d d d            n# 1 swxY w Y   d|v rt          nt          }t          |d          sd |_         |||j        |j        |j                  d }~ww xY w|
S )Nz--all-importszpasteurize.pyzfuturize.pyr   z--stage1rr   z--stage2z--conservativez-w)stderrrn   Error running the command  r   env=%s
Contents of file :

----
%s
----futurizerM   rM   )listr9   rj   rb   rc   r   r   rn   r   r   r:   r   rW   r[   hasattrrM   rK   rL   )rN   r   rt   ru   rv   rw   paramsscriptfn	call_argsrM   er   rJ   
ErrorClasss                  r   rz   z!CodeHandler._futurize_test_script1  s    f 	+MM/*** 	0$FF"F!}}j))))A3j))))!Q'''' 0./// \H$^V,v5r
B		H!)FIIIFF! 	H 	H 	Hb QQ ++++ 48+++(1668833
               ,6+?+?--_J1h''  *S!,ahGGGG%	H& s=   ,C	 	
FE?"?D-!E?-D1	1E?4D1	5A
E??Fc                    | j         |z   }	 t          ||g| j        t                    }n# t          $ r}t          |          5 }dd                    ||g          dd| j        z  d|dd|                                z  }d d d            n# 1 swxY w Y   t          |d	          sd |_	        t          ||j        |j        |j	        
          d }~ww xY w|S )N)rn   r   r   r   r   r   r   r   r   rM   r   )rj   r   rn   r   r   r   r:   r   r   rM   rG   rK   rL   )rN   r   rx   r   rM   r   r   rJ   s           r   r|   zCodeHandler._run_test_script`  sI    \H$	W!;"3&*hv? ? ?FF! 	W 	W 	Wb QQ +r!23333 48+++(1668833
               1h''  +CquQXVVVV!	W" s9   + 
CCABCB	CB	<CCN)rq   FFTTF)T)rq   FTFTF)r   )r   rq   FFF)rR   rS   rT   rU   rp   r   r   r   r   r   ry   r{   rz   rb   rc   r|   r-   r   r   r]   r]   q   s	        )3 )3 )3V EJ6;   <, , , ,, !  !  !D JO<@#(!4 !4 !4 !4F1 1 1	" 	" 	" 	"   
 HN7<+0- - - -^ ):%(^     r   r]   z#this test is known to fail on Py2.6c                 <    t           s| S t          j        |           S rI   )r   unittestexpectedFailurefuncs    r   expectedFailurePY3r           #D)))r   c                 <    t           s| S t          j        |           S rI   )r   r   r   r   s    r   expectedFailurePY26r           #D)))r   c                 <    t           s| S t          j        |           S rI   )r
   r   r   r   s    r   expectedFailurePY27r     r   r   c                 <    t           s| S t          j        |           S rI   )r	   r   r   r   s    r   expectedFailurePY2r     r   r   assertRaisesRegexc                     t          |t          t          f          r |s
J d            t          j        |          }|                    |          s(|pd}|d|j        d|}|                     |          dS )z=Fail the test unless the text matches the regular expression.z!expected_regex must not be empty.zRegex didn't matchz: z not found in N)r   strunicoderecompilesearchpatternfailureException)rN   textexpected_regexrJ   s       r   assertRegexr     s    .3.11 4BBBBBBN33  && )))*-##~/E/E/EttL##C((() )r   r   c                   &    e Zd Z	 	 ddZd Zd ZdS )_AssertRaisesBaseContextNc                    || _         || _        |2	 |j        | _        n+# t          $ r t          |          | _        Y nw xY wd | _        t          |t          t
          f          rt          j	        |          }|| _
        d | _        d S rI   )r   	test_caserR   obj_nameAttributeErrorr   r   r   r   r   r   rJ   )rN   r   r   callable_objr   s        r   rO   z!_AssertRaisesBaseContext.__init__  s     "#2 , 5! 2 2 2 #L 1 12 !DMnucl33 	8Z77N,s    A A c                 v    | j                             | j        |          }| j                             |          rI   )r   _formatMessagerJ   r   )rN   standardMsgrJ   s      r   _raiseFailurez&_AssertRaisesBaseContext._raiseFailure  s1    n++DHkBBn--c222r   c                     ||                     dd          | _        | S | 5   ||i | ddd           dS # 1 swxY w Y   dS )z
        If callable_obj is None, assertRaises/Warns is being used as a
        context manager, so check for a 'msg' kwarg and return self.
        If callable_obj is not None, call it passing args and kwargs.
        NrJ   )poprJ   )rN   namer   argsr   s        r   handlez_AssertRaisesBaseContext.handle  s     zz%..DHK 	* 	*L$)&)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   	8<<)NN)rR   rS   rT   rO   r   r   r-   r   r   r   r     sL        9= $    3 3 3
* 
* 
* 
* 
*r   r   c                       e Zd ZdZd Zd ZdS )_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.c                    t           j                                        D ]}t          |dd           ri |_        t          j        d          | _        | j                                        | _        t          j	        d| j
                   | S )N__warningregistry__T)recordalways)rb   modulesvaluesgetattrr   warningscatch_warningswarnings_manager	__enter__simplefilterr   )rN   vs     r   r   z_AssertWarnsContext.__enter__  s     ##%% 	+ 	+Aq/66 +(*% ( 7t D D D-7799h666r   c                    | j                             |||           |d S 	 | j        j        }n$# t          $ r t          | j                  }Y nw xY wd }| j        D ]s}|j        }t          || j                  s||}| j	        (| j	        
                    t          |                    sR|| _        |j        | _        |j        | _         d S |@|                     d                    | j	        j        t          |                               | j        r0|                     d                    || j                             d S |                     d                    |                     d S )Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)r   __exit__r   rR   r   r   r   messager   r   r   warningr   linenor   formatr   r   )rN   exc_type	exc_valuetbexc_namefirst_matchingmws           r   r   z_AssertWarnsContext.__exit__  s   &&xB???F	*}-HH 	* 	* 	*4=))HHH	* 	 	A	Aa// %!"#/'..s1vv66 0DLJDM(DKFF%9@@(0#n2E2E G  G H H H= 	D7>>x?C} N  N O O O O O 188BBCCCCCs   / AAN)rR   rS   rT   rU   r   r   r-   r   r   r   r     s=        LL	 	 	 D  D  D  D  Dr   r   c                 T    t          || |          }|                    d|||          S )a  Fail unless a warning of class warnClass is triggered
       by callable_obj when invoked with arguments args and keyword
       arguments kwargs.  If a different type of warning is
       triggered, it will not be handled: depending on the other
       warning filtering rules in effect, it might be silenced, printed
       out, or raised as an exception.

       If called with callable_obj omitted or None, will return a
       context object used like this::

            with self.assertWarns(SomeWarning):
                do_something()

       An optional keyword argument 'msg' can be provided when assertWarns
       is used as a context object.

       The context manager keeps a reference to the first matching
       warning as the 'warning' attribute; similarly, the 'filename'
       and 'lineno' attributes give you information about the line
       of Python code from which the warning was triggered.
       This allows you to inspect the warning after the assertion::

           with self.assertWarns(SomeWarning) as cm:
               do_something()
           the_warning = cm.warning
           self.assertEqual(the_warning.some_attribute, 147)
    assertWarns)r   r   )rN   expected_warningr   r   r   contexts         r   r   r     s.    8 ""2D,GGG>>-tVDDDr   r   rI   ),
__future__r   r   rg   re   r   rb   r   r   r   textwrapr   future.utilsr   r   r   r	   r
   future.moves.subprocessr   r   r   	unittest2r   rE   rG   rW   r[   TestCaser]   skipIfskip26r   r   r   r   r   assertRaisesRegexpr   r   objectr   r   r   r-   r   r   <module>r     s!   6 6 6 6 6 6 6 6 				   



 				  				       : : : : : : : : : : : : : : L L L L L L L L L L !      =  =  = @F F F F F 2 F F F	 	 	 	 	- 	 	 		 	 	 	 	/ 	 	 	G G G G G(# G G GV 
D	E	E* * *
* * ** * ** * * wx "566 O*2*;*NH') ) ) ) wx -00 ?K!=+>>> *  *  *  *  *v  *  *  *D.D .D .D .D .D2 .D .D .DbE E E E> wx -00 ?K!=+>>>>>? ?r   