
    FwgM                        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j8                        Z ej<                  ed      Zd Z d Z!d Z"d Z# e$ej8                  d      s%ej8                  jJ                  ej8                  _&        ddZ' e$ej8                  d      s eej8                  de'        G d de(      Z) G d de)      Z*ddZ+ e$ej8                  d      s eej8                  de+       yy)    )print_functionabsolute_importN)dedent)bind_methodPY26PY3PY2PY27)check_outputSTDOUTCalledProcessErrorc                 D    | j                  d      r| dd } t        |       S )z,
    Removes any leading 
 and dedents.
    
   N)
startswithr   )codes    H/var/www/horilla/myenv/lib/python3.12/site-packages/future/tests/base.pyreformat_coder      s%     tABx$<    c                 H   | j                  d      }t        |      D cg c]  \  }}|j                  d      r| }}}t        |      D cg c])  \  }}|j                  d      s|j                  d      r|+ }}}t        |      D cg c]  \  }}|j                  d      r| }}}| j                         | k(  sJ d       d }d } ||       ||      k  sJ d	       t	        |D cg c]  }||   	 c}      }	t        t        ||	            }
t	        |D cg c]  }||   	 c}      }t        t        ||            }t	        |D cg c]  }||   	 c}      }t        t        ||            }g }t        t        |            D ]a  }||v r|j                  |
|          ||v r|j                  ||          5||v r|j                  ||          N|j                  ||          c dj                  |      S c c}}w c c}}w c c}}w c c}w c c}w c c}w )
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   from __future__ import zfrom futurez	from pastzfrom builtinszIinternal usage error: dedent the code before calling order_future_lines()c                 8    t        |       dkD  rt        |       S dS )Nr   )lenmaxnumberss    r   mymaxz!order_future_lines.<locals>.mymax7   s    "7|a/s7|6Q6r   c                 J    t        |       dkD  rt        |       S t        d      S )Nr   inf)r   minfloatr   s    r   myminz!order_future_lines.<locals>.mymin:   s     "7|a/s7|AU5\Ar   z2the __future__ and future imports are out of order)split	enumerater   lstripsorteddictzipranger   appendjoin)r   linesilineuufuture_line_numbersfuture_line_numbersbuiltins_line_numbersr   r"   uulsorted_uufuture_linesflsorted_future_linesblsorted_builtins_lines	new_liness                   r   order_future_linesr9      sZ    JJtE.7.> N71d"&//2K"L  N N -6e,< >D $ > $ <  > > /8.> B71d $ @  B B ;;=D  C $B C 7B &'51D+EE A@AE $9:q%(:
;C %:C!@A	#67aq7	8Bs#6;<	#89aq9	:B %:B!?@ I3u: '%%2156%%034''2156U1X&' 99Y]N>B$ ; 8 :s#   H.H	H.HHHc                       e Zd ZdZddZd Zy)VerboseCalledProcessErrorz
    Like CalledProcessError, but it displays more information (message and
    script output) for diagnosing test failures etc.
    Nc                 <    || _         || _        || _        || _        y N)msg
returncodecmdoutput)selfr>   r?   r@   rA   s        r   __init__z"VerboseCalledProcessError.__init__`   s    $r   c                 d    d| j                   | j                  | j                  | j                  fz  S )Nz>Command '%s' failed with exit status %d
Message: %s
Output: %s)r@   r?   r>   rA   )rB   s    r   __str__z!VerboseCalledProcessError.__str__f   s-    R88T__dhhDE 	Fr   r=   )__name__
__module____qualname____doc__rC   rE    r   r   r;   r;   [   s    Fr   r;   c                       e Zd Zy)FuturizeErrorNrF   rG   rH   rJ   r   r   rL   rL   j       r   rL   c                       e Zd Zy)PasteurizeErrorNrM   rJ   r   r   rP   rP   m   rN   r   rP   c                       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y)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      }|r0dt        j                         t        j                  z   |z   i| _        ydt        j                         i| _        y)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)rB   pypaths     r   setUpzCodeHandler.setUpv   s     & '  & '  !^^,'')BGGKK7<($biikBJJ&>&GHDH$biik2DHr   c                     |rt        |      }| j                  |       | j                  ||||       | j                         }|r#| j                  D ]  }	| j                  |	      }
 |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_scriptrY   _run_test_script)rB   r   rg   rh   ri   reformatrunrj   rA   rk   _s              r   convertzCodeHandler.convert   s|    &  &D%""&k).\ 	# 	K'')#00 C))k)BCr   c                 ~   |r"| j                  |      }| j                  |      }t        |t              r!t        |t              s|j                  d      }t        |t              r!t        |t              s|j                  d      }| j	                  t        |j                               |j                                y)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assertEqualr9   rstrip)rB   rA   expectedignore_importss       r   comparezCodeHandler.compare   s     ..v6F00:Hfe$Z%-H]]7+Fh&z&%/Hw/H+FMMO<!*	,r   c                    g }|j                  d      D ]e  }|j                  d      r|j                  d      r'|j                  d      r9d|v r>d|v rC|j                  d      rU|j                  |       g dj                  |      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.)r#   r   r*   r+   )rB   r   rA   r.   s       r   rv   z CodeHandler.strip_future_imports   s    (  JJt$ 	$DOO$=>~6'78(D0*d2~6d#	$ yy  r   c	                     | j                  ||||||      }	|rd|v r| j                  n| j                  }
nd}
t        |      }|
|v rd}
| j	                  |	|
|z   |       y)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.
        )rg   rh   ri   rq   rj       )r}   N)rs   rV   rU   r   r~   )rB   beforer|   rg   rh   r}   ri   rq   rj   rA   headersreformatteds               r   convert_checkzCodeHandler.convert_check   sv    * fV$)s  O'(F{dmmGG#H-k!GVW{2$2 	 	4r   c                 ,     | j                   ||fi | y)ze
        Convenience method to ensure the code is unchanged by the
        futurize process.
        N)r   )rB   r   kwargss      r   	unchangedzCodeHandler.unchanged  s    
 	400r   mytestscript.pyc                     t        |t              r|j                  d      }t        j                  | j
                  |z   dd      5 }|j                  t        |             ddd       y# 1 sw Y   yxY w)z
        Dedents the given code (a multiline string) and writes it out to
        a file in a temporary folder like /tmp/tmpUDCn7x/mytestscript.py.
        ru   wtencodingN)rw   rx   ry   ioopenr_   writer   )rB   r   filenamefs       r   rl   zCodeHandler._write_test_script!  s\    
 dE";;w'DWWT\\H,dWE 	"GGF4L!	" 	" 	"s   A++A4c                     t        j                  | j                  |z   dd      5 }|j                         }d d d        |S # 1 sw Y   S xY w)Nrtru   r   )r   r   r_   read)rB   r   r   	newsources       r   rn   zCodeHandler._read_test_script,  sD    WWT\\H,dWE 	!I	!	!s   AAc                    g }t        |      }|r|j                  d       |rd}nNd}|dgk(  r|j                  d       n!|dgk(  r|j                  d       n	|ddgk(  sJ |r|j                  d       | j                  |z   }t        j                  |g|z   d	|gz   }		 t        |	t        | j                  
      }
|
S # t        $ r}t        |      5 }ddj                  |	      dd| j                  z  d|dd|j                         z  }d d d        n# 1 sw Y   nxY wd|v rt        nt        }t        |d      sd |_         ||j                   |j"                  |j                        d }~ww xY w)Nz--all-importszpasteurize.pyzfuturize.pyr   z--stage1r   z--stage2z--conservativez-w)stderrrc   Error running the command  r   env=%s
Contents of file :

----
%s
----futurizerA   rA   )listr*   r_   rW   rX   r   r   rc   r   r   r+   r   rL   rP   hasattrrA   r?   r@   )rB   r   rg   rh   ri   rj   paramsscriptfn	call_argsrA   er   r>   
ErrorClasss                  r   rm   z!CodeHandler._futurize_test_script1  sg    fMM/*$F"F!}j)A3j)!Q'''./ \\H$^^V,v5r
B		H!)FIF( ' " 	Hb Q + 488+(16683
   ,6+?-_J1h'S!,,ahhGG%	Hs1   B< <	E3E.<D	E.D	AE..E3c                    | j                   |z   }	 t        ||g| j                  t              }|S # t        $ r}t        |      5 }ddj                  ||g      dd| j                  z  d|dd|j                         z  }d d d        n# 1 sw Y   nxY wt        |d	      sd |_	        t        |j                  |j                  |j                  
      d }~ww xY w)N)rc   r   r   r   r   r   r   r   r   rA   r   )r_   r   rc   r   r   r   r+   r   r   rA   r;   r?   r@   )rB   r   rk   r   rA   r   r   r>   s           r   ro   zCodeHandler._run_test_script`  s     \\H$	W!;"3&*hhv?F& # " 	Wb Q +r!23 488+(16683
   1h'+CquuQXXVV!	Ws-   1 	CC>B	CB	ACCN)r   r   FFTTF)T)r   FTFTF)r   )r   r   FFF)rF   rG   rH   rI   re   rs   r~   rv   r   r   rl   rn   rm   rW   rX   ro   rJ   r   r   rR   rR   q   sm    )3V EJ6;<,, !D JO<@#(!4F1	"
 HN7<+0-^ ):%(^^r   rR   z#this test is known to fail on Py2.6c                 <    t         s| S t        j                  |       S r=   )r   unittestexpectedFailurefuncs    r   expectedFailurePY3r         ##D))r   c                 <    t         s| S t        j                  |       S r=   )r   r   r   r   s    r   expectedFailurePY26r         ##D))r   c                 <    t         s| S t        j                  |       S r=   )r
   r   r   r   s    r   expectedFailurePY27r     r   r   c                 <    t         s| S t        j                  |       S r=   )r	   r   r   r   s    r   expectedFailurePY2r     r   r   assertRaisesRegexc                     t        |t        t        f      r|sJ d       t        j                  |      }|j                  |      s+|xs d}|d|j                  d|}| j                  |      y)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)rw   strunicoderecompilesearchpatternfailureException)rB   textexpected_regexr>   s       r   assertRegexr     sm    .3.1BBB~N3  &))*-~/E/EtL##C(( 'r   r   c                   $    e Zd Z	 	 ddZd Zd Zy)_AssertRaisesBaseContextNc                    || _         || _        |	 |j                  | _        nd | _        t        |t        t
        f      rt        j                  |      }|| _
        d | _        y # t        $ r t        |      | _        Y Uw xY wr=   )r|   	test_caserF   obj_nameAttributeErrorr   rw   rx   r   r   r   r>   )rB   r|   r   callable_objr   s        r   rC   z!_AssertRaisesBaseContext.__init__  sy     "#2 , 5 5 !DMnucl3ZZ7N, " 2 #L 12s   A% %B Bc                     | j                   j                  | j                  |      }| j                   j                  |      r=   )r   _formatMessager>   r   )rB   standardMsgr>   s      r   _raiseFailurez&_AssertRaisesBaseContext._raiseFailure  s1    nn++DHHkBnn--c22r   c                 x    ||j                  dd      | _        | S | 5   ||i | ddd       y# 1 sw Y   yxY w)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.
        Nr>   )popr>   )rB   namer   argsr   s        r   handlez_AssertRaisesBaseContext.handle  sF     zz%.DHK 	*$)&)	* 	* 	*s   	09)NN)rF   rG   rH   rC   r   r   rJ   r   r   r   r     s    9= $ 3
*r   r   c                       e Zd ZdZd Zd Zy)_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.c                 *   t         j                  j                         D ]  }t        |dd       si |_         t        j                  d      | _        | j                  j                         | _        t        j                  d| j                         | S )N__warningregistry__T)recordalways)rW   modulesvaluesgetattrr   warningscatch_warningswarnings_manager	__enter__simplefilterr|   )rB   vs     r   r   z_AssertWarnsContext.__enter__  sy     ##% 	+Aq/6(*%	+ !) 7 7t D--779h6r   c                    | j                   j                  |||       |y 	 | j                  j                  }d }| j                  D ]  }|j                  }t        || j                        s&||}| j                  %| j                  j                  t        |            s[|| _        |j                  | _        |j                  | _         y  |>| j                  dj                  | j                  j                   t        |                   | j"                  r,| j                  dj                  || j"                               y | j                  dj                  |             y # t        $ r t        | j                        }Y Ow xY w)Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)r   __exit__r|   rF   r   r   r   messagerw   r   r   warningr   linenor   formatr   r   )rB   exc_type	exc_valuetbexc_namefirst_matchingmws           r   r   z_AssertWarnsContext.__exit__  sb   &&xB?	*}}--H  	A		Aa/%!"##/''..s1v6DLJJDM((DK	 %9@@((00#n2E G H==7>>x?C}} N O 188BC3  	*4==)H	*s   E& &FFN)rF   rG   rH   rI   r   r   rJ   r   r   r   r     s    L	 Dr   r   c                 D    t        || |      }|j                  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   )rB   expected_warningr   r   r   contexts         r   r   r     s(    8 ""2D,GG>>-tVDDr   r   r=   ),
__future__r   r   r\   rZ   r   rW   r   r   r   textwrapr   future.utilsr   r   r   r	   r
   future.moves.subprocessr   r   r   	unittest2r   r9   r;   rL   rP   TestCaserR   skipIfskip26r   r   r   r   r   assertRaisesRegexpr   r   objectr   r   r   rJ   r   r   <module>r      sF   6 	   
 	  	  : : L L = @F 2 F	- 		/ 	G(## GV 
D	E*
*** x  "56*2*;*;*N*NH') x  -0!!=+> *v  *D.D2 .DbE> x  -0!!=+> 1r   