
    9iM                        S SK JrJr  S SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
Jr  S SKJrJrJrJrJr  S SKJrJrJr  \(       a  S SKrS rS r " S S	\5      r " S
 S\5      r " S S\5      r " S S\R8                  5      r\R<                  " \S5      rS r S r!S r"S r#\$" \R8                  S5      (       d%  \R8                  RJ                  \R8                  l&        SS jr'\$" \R8                  S5      (       d  \" \R8                  S\'5         " S S\(5      r) " S S\)5      r*SS jr+\$" \R8                  S5      (       d  \" \R8                  S\+5        gg)    )print_functionabsolute_importN)dedent)bind_methodPY26PY3PY2PY27)check_outputSTDOUTCalledProcessErrorc                 N    U R                  S5      (       a  U SS n [        U 5      $ )z)
   Removes any leading 
and dedents.
   
   N)
startswithr   )codes    Q/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/future/tests/base.pyreformat_coder      s(     tABx$<    c                    U R                  S5      n[        U5       VVs/ s H  u  p#UR                  S5      (       d  M  UPM!     nnn[        U5       VVs/ s H5  u  p#UR                  S5      (       d  UR                  S5      (       d  M3  UPM7     nnn[        U5       VVs/ s H  u  p#UR                  S5      (       d  M  UPM!     nnnU R                  5       U :X  d   S5       eS nS nU" U5      U" U5      ::  d   S	5       e[	        U Vs/ s H  o!U   PM	     sn5      n	[        [        XI5      5      n
[	        U Vs/ s H  o!U   PM	     sn5      n[        [        X[5      5      n[	        U Vs/ s H  o!U   PM	     sn5      n[        [        Xm5      5      n/ n[        [        U5      5       Hd  nX$;   a  UR                  X   5        M  X%;   a  UR                  X   5        M7  X&;   a  UR                  X   5        MQ  UR                  X   5        Mf     SR                  U5      $ s  snnf s  snnf s  snnf s  snf s  snf s  snf )
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                 :    [        U 5      S:  a  [        U 5      $ S$ )Nr   )lenmaxnumberss    r   mymax!order_future_lines.<locals>.mymax7   s    "7|a/s7|6Q6r   c                 L    [        U 5      S:  a  [        U 5      $ [        S5      $ )Nr   inf)r   minfloatr   s    r   mymin!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_linesr;      sH    JJtE.7.> N.>71"&//2K"L .> N -6e,< >,< $ > > $ < ,< > /8.> B.>71 $ @ .> B ;;=D  C $B C 7B &'51D+EE A@AE $9:$9q($9:
;C %:!@A	#67#6aq#67	8Bs#6;<	#89#8aq#89	:B %:!?@ I3u:%256%034'256UX&  99Y]N>B$ ; 8 :s5   H, H,2H2H2$H8H8H>I4Ic                   (    \ rS rSrSrSS jrS rSrg)VerboseCalledProcessError[   zy
Like CalledProcessError, but it displays more information (message and
script output) for diagnosing test failures etc.
Nc                 4    Xl         X l        X0l        X@l        g N)msg
returncodecmdoutput)selfrA   rB   rC   rD   s        r   __init__"VerboseCalledProcessError.__init__`   s    $r   c                 d    SU R                   U R                  U R                  U R                  4-  $ )Nz>Command '%s' failed with exit status %d
Message: %s
Output: %s)rC   rB   rA   rD   )rE   s    r   __str__!VerboseCalledProcessError.__str__f   s-    R88T__dhhDE 	Fr   )rC   rA   rD   rB   r@   )__name__
__module____qualname____firstlineno____doc__rF   rI   __static_attributes__ r   r   r=   r=   [   s    Fr   r=   c                       \ rS rSrSrg)FuturizeErrorj   rQ   NrK   rL   rM   rN   rP   rQ   r   r   rS   rS   j       r   rS   c                       \ rS rSrSrg)PasteurizeErrorm   rQ   NrU   rQ   r   r   rX   rX   m   rV   r   rX   c                       \ rS rSrSrS r  SS jrSS jrS r   SS jr	S r
SS
 jrSS jr   SS jrS	\R                  4S jrSrg)CodeHandlerq   zh
Handy mixin for test classes for writing / reading / futurizing /
running .py files in the test suite.
c                    [        S5      U l        [        S5      U l        [        R                  /U l        [        R                  " 5       [        R                  R                  -   U l        [        R                  " S5      nU(       a1  S[        R                  " 5       [        R                  -   U-   0U l        gS[        R                  " 5       0U l        g)zQ
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)rE   pypaths     r   setUpCodeHandler.setUpv   s     & '  & '  !^^,'')BGGKK7<($biikBJJ&>&GHDH$biik2DHr   c                     U(       a  [        U5      nU R                  U5        U R                  X#XGS9  U R                  5       nU(       a"  U R                   H  n	U R                  U	S9n
M     U$ )a5  
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_scriptrc   _run_test_script)rE   r   rr   rs   rt   reformatrunru   rD   rv   _s              r   convertCodeHandler.convert   sq    &  &D%""&). 	# 	K'')#00))k)B  1r   c                    U(       a"  U R                  U5      nU R                  U5      n[        U[        5      (       a&  [        U[        5      (       d  UR                  S5      n[        U[        5      (       a&  [        U[        5      (       d  UR                  S5      nU R	                  [        UR                  5       5      UR                  5       5        g)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assertEqualr;   rstrip)rE   rD   expectedignore_importss       r   compareCodeHandler.compare   s     ..v6F00:Hfe$$Z%-H-H]]7+Fh&&z&%/H/Hw/H+FMMO<!*	,r   c                 Z   / nUR                  S5       H  nUR                  S5      (       a  M  UR                  S5      (       a  M3  UR                  S5      (       a  MK  SU;   a  MS  SU;   a  M[  UR                  S5      (       a  Ms  UR                  U5        M     SR                  U5      $ )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-   )rE   r   rD   r0   s       r   r    CodeHandler.strip_future_imports   s    (  JJt$DOO$=>>~66'788(D0*d2~66d# % yy  r   c	           	          U R                  XUXgUS9n	U(       a  SU;   a  U R                  OU R                  n
OSn
[        U5      nX;   a  Sn
U R	                  XU-   US9  g)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.
)rr   rs   rt   r|   ru       )r   N)r~   r`   r_   r   r   )rE   beforer   rr   rs   r   rt   r|   ru   rD   headersreformatteds               r   convert_checkCodeHandler.convert_check   sn    * f$)  O'(F{dmmGG#H-!GV{2$2 	 	4r   c                 *    U R                   " X40 UD6  g)zM
Convenience method to ensure the code is unchanged by the
futurize process.
N)r   )rE   r   kwargss      r   	unchangedCodeHandler.unchanged  s    
 	400r   mytestscript.pyc                     [        U[        5      (       a  UR                  S5      n[        R                  " U R
                  U-   SSS9 nUR                  [        U5      5        SSS5        g! , (       d  f       g= f)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openri   writer   )rE   r   filenamefs       r   rw   CodeHandler._write_test_script!  sW    
 dE"";;w'DWWT\\H,dWEGGF4L! FEEs   
A..
A<c                     [         R                  " U R                  U-   SSS9 nUR                  5       nS S S 5        U$ ! , (       d  f       W$ = f)Nrtr   r   )r   r   ri   read)rE   r   r   	newsources       r   ry   CodeHandler._read_test_script,  sD    WWT\\H,dWEI F FEs	   ?
Ac                 &   / n[        U5      nU(       a  UR                  S5        U(       a  SnOVSnUS/:X  a  UR                  S5        O#US/:X  a  UR                  S5        O
USS/:X  d   eU(       a  UR                  S5        U R                  U-   n[        R                  U/U-   S	U/-   n	 [        U	[        U R                  S
9n
U
$ ! [         a  n[        U5       nSSR                  U	5      < SSU R                  -  < SU< SSUR                  5       -  < 3nS S S 5        O! , (       d  f       O= fSU;   a  [        O[        n[        US5      (       d  S Ul        U" WUR                   UR"                  UR                  S9eS nAff = f)Nz--all-importszpasteurize.pyzfuturize.pyr   z--stage1r   z--stage2z--conservativez-w)stderrrm   Error running the command  r   env=%s
Contents of file :

----
%s
----futurizerD   rD   )listr,   ri   ra   rb   r   r   rm   r   r   r-   r   rS   rX   hasattrrD   rB   rC   )rE   r   rr   rs   rt   ru   paramsscriptfn	call_argsrD   er   rA   
ErrorClasss                  r   rx   !CodeHandler._futurize_test_script1  s_    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s2   0C 
FF A D) 	F)
D7	3AFFc                    U R                   U-   n [        X#/U R                  [        S9nU$ ! [         a  n[        U5       nSSR                  X#/5      < SSU R                  -  < SU< SSUR                  5       -  < 3nS S S 5        O! , (       d  f       O= f[        US	5      (       d  S Ul	        [        WUR                  UR                  UR                  S
9eS nAff = f)N)rm   r   r   r   r   r   r   r   r   rD   r   )ri   r   rm   r   r   r   r-   r   r   rD   r=   rB   rC   )rE   r   rv   r   rD   r   r   rA   s           r   rz   CodeHandler._run_test_script`  s     \\H$	W!;"3&*hhv?F& # " 	WbQ +!23 488+(16683
  1h''+CquuQXXVV!	Ws.   - 
C$CAB	C
B	A	CC$)rm   r_   r`   rc   ri   N)r   r   FFTTF)T)r   FTFTF)r   )r   r   FFF)rK   rL   rM   rN   rO   ro   r~   r   r   r   r   rw   ry   rx   ra   rb   rz   rP   rQ   r   r   r[   r[   q   sm    )3V EJ6;<,, !D JO<@#(!4F1	"
 HN7<+0-^ ):%(^^r   r[   z#this test is known to fail on Py2.6c                 H    [         (       d  U $ [        R                  " U 5      $ r@   )r   unittestexpectedFailurefuncs    r   expectedFailurePY3r         3##D))r   c                 H    [         (       d  U $ [        R                  " U 5      $ r@   )r   r   r   r   s    r   expectedFailurePY26r         4##D))r   c                 H    [         (       d  U $ [        R                  " U 5      $ r@   )r
   r   r   r   s    r   expectedFailurePY27r     r   r   c                 H    [         (       d  U $ [        R                  " U 5      $ r@   )r	   r   r   r   s    r   expectedFailurePY2r     r   r   assertRaisesRegexc                    [        U[        [        45      (       a$  U(       d   S5       e[        R                  " U5      nUR                  U5      (       d3  U=(       d    SnU< SUR                  < SU< 3nU R                  U5      eg)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)rE   textexpected_regexrA   s       r   assertRegexr     ss    .3.11BBB~N3  &&))*-~/E/EtL##C(( 'r   r   c                   .    \ rS rSr  SS jrS rS rSrg)_AssertRaisesBaseContexti  Nc                    Xl         X l        Ub   UR                  U l        OS U l        [        U[        [
        45      (       a  [        R                  " U5      nX@l
        S U l        g ! [         a    [        U5      U l         N[f = fr@   )r   	test_caserK   obj_nameAttributeErrorr   r   r   r   r   r   rA   )rE   r   r   callable_objr   s        r   rF   !_AssertRaisesBaseContext.__init__  sv     "#2 , 5 5 !DMnucl33ZZ7N, " 2 #L 12s   A) )BBc                     U R                   R                  U R                  U5      nU R                   R                  U5      er@   )r   _formatMessagerA   r   )rE   standardMsgrA   s      r   _raiseFailure&_AssertRaisesBaseContext._raiseFailure  s1    nn++DHHkBnn--c22r   c                     Uc  UR                  SS5      U l        U $ U    U" U0 UD6  SSS5        g! , (       d  f       g= f)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.
NrA   )poprA   )rE   namer   argsr   s        r   handle_AssertRaisesBaseContext.handle  s;     zz%.DHK$)&) TTs   	1
?)r   r   rA   r   r   )NN)rK   rL   rM   rN   rF   r   r   rP   rQ   r   r   r   r     s    9= $ 3
*r   r   c                   $    \ rS rSrSrS rS rSrg)_AssertWarnsContexti  zBA context manager used to implement TestCase.assertWarns* methods.c                 8   [         R                  R                  5        H  n[        USS 5      (       d  M  0 Ul        M      [
        R                  " SS9U l        U R                  R                  5       U l        [
        R                  " SU R                  5        U $ )N__warningregistry__T)recordalways)ra   modulesvaluesgetattrr   warningscatch_warningswarnings_manager	__enter__simplefilterr   )rE   vs     r   r   _AssertWarnsContext.__enter__  sw     ##%Aq/66(*% & !) 7 7t D--779h6r   c                 >   U R                   R                  XU5        Ub  g  U R                  R                  nS nU R                   H  nUR                  n[        XpR                  5      (       d  M+  Uc  UnU R                  b+  U R                  R                  [        U5      5      (       d  Mh  Xpl        UR                  U l        UR                  U l          g    Ub>  U R                  SR                  U R                  R                   [        U5      5      5        U R"                  (       a,  U R                  SR                  UU R"                  5      5        g U R                  SR                  U5      5        g ! [         a    [        U R                  5      n GNcf = f)Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)r   __exit__r   rK   r   r   r   messager   r   r   warningr   linenor   formatr   r   )rE   exc_type	exc_valuetbexc_namefirst_matchingmws           r   r   _AssertWarnsContext.__exit__  s]   &&xB?	*}}--H A		Aa//%!"##/''..s1v66LJJDM((DK  %9@@((00#n2E G H==7>>x?C}} N O 188BC3  	*4==)H	*s   E9 9FF)r   r  r   r   r   N)rK   rL   rM   rN   rO   r   r   rP   rQ   r   r   r   r     s    L	 Dr   r   c                 @    [        XU5      nUR                  SX#U5      $ )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   )rE   expected_warningr   r   r   contexts         r   r  r    s$    8 ""2,GG>>-VDDr   r  r@   ),
__future__r   r   rf   rd   r   ra   r   r   r   textwrapr   future.utilsr   r   r   r	   r
   future.moves.subprocessr   r   r   	unittest2r   r;   r=   rS   rX   TestCaser[   skipIfskip26r   r   r   r   r   assertRaisesRegexpr   r   objectr   r   r  rQ   r   r   <module>r     sM   6 	   
 	  	  : : L L = @F 2 F	- 		/ 	G(## GV 
D	E*
*** x  "566*2*;*;*N*NH') x  -00!!=+> *v  *D.D2 .DbE> x  -00!!=+> 1r   