403Webshell
Server IP : 209.209.40.120  /  Your IP : 216.73.217.112
Web Server : Microsoft-IIS/10.0
System : Windows NT NEWWWW 10.0 build 17763 (Windows Server 2019) i586
User : NEWWWW$ ( 0)
PHP Version : 8.3.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Python312/Lib/site-packages/_pytest/assertion/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/Python312/Lib/site-packages/_pytest/assertion/__pycache__/rewrite.cpython-312.pyc
�

��Hg���
�f�dZddlmZddlZddlmZddlZddlZddlZ	ddl
Z	ddlZ	ddlZddl
Z
ddlZddlZddlmZddlmZddlZddlZddlZddlZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl)m+Z+ddl,m-Z-ddl.m/Z0erddl#m1Z1Gd�d�Z2e-d�Z3ejhjj�de"��Z6ddxsdzZ7de6ze7zZ8e2�Z9Gd �d!e	jtjve	jtjx�Z=								dSd"�Z>										dTd#�Z?dUd$�Z@d%�f							dVd&�ZA		dW									dXd'�ZBdYd(�ZCdZd)�ZDdYd*�ZEd[d+�ZFd\d,�ZG										d]d-�ZHd^d.�ZId_d/�ZJej�d0ej�d1ej�d2ej�d3iZOiej�d4�ej�d5�ej�d6�ej�d7�ej�d8�ej�d9�ej�d:�ej�d;�ej�d<�ej�d=�ej�d>�ej�d?�ej�d@�ej�dA�ej�dB�ej�dC�ej�dD�ej�dEej�dFej�dGej�dHej�dIej�dJi�Zgd`dK�Zhej�dL�M�dadN��ZjGdO�dPej��ZldbdQ�ZmdcdR�Zny)dz5Rewrite assertion AST to produce nice error messages.�)�annotationsN)�defaultdict)�Path)�PurePath)�Callable)�IO)�Iterable)�Iterator)�Sequence)�
TYPE_CHECKING)�DEFAULT_REPR_MAX_SIZE)�saferepr)�version)�util)�Config)�Session)�absolutepath)�
fnmatch_ex)�StashKey)�format_explanation)�AssertionStatec��eZdZy)�SentinelN)�__name__�
__module__�__qualname__���;C:\Python312\Lib\site-packages\_pytest/assertion/rewrite.pyrr0s��rrrz-pytest-�.py�c�o�.c�$�eZdZdZdd�Zdd�ZejjjZ
		d							dd�Z					dd�Zdd�Zdd�Z
dd	�Zdd
�Zdd�Zdd�Zdd
�Zej(dk\r!ej(dk\rddlmZnddlmZdd�Zyy)�AssertionRewritingHookz1PEP302/PEP451 import hook which rewrites asserts.c���||_	|jd�|_d|_i|_t
�|_d|_dh|_	i|_
d|_y#t$rddg|_Y�OwxYw)N�python_filesz	test_*.pyz	*_test.pyF�conftest)�config�getini�fnpats�
ValueError�session�_rewritten_names�set�
_must_rewrite�_writing_pyc�_basenames_to_check_rewrite�_marked_for_rewrite_cache�_session_paths_checked)�selfr)s  r�__init__zAssertionRewritingHook.__init__Bsz�����	5� �-�-��7�D�K�(,���13���'*�u���"���,6�<��(�:<��&�&+��#���	5�&��4�D�K�	5�s�A�A/�.A/c� �||_d|_y)NF)r-r4)r5r-s  r�set_sessionz"AssertionRewritingHook.set_sessionRs�����&+��#rNc��|jry|jjt}|j	||�ry|jd|���|j
||�}|�-|�+|D]&}tjj||�}|��&n|�c|j�Wt|jtjj�r)tj j#|j�sy|j}|j%|||�sytjj||||j&��S)Nzfind_module called for: )�loader�submodule_search_locations)r1r)�stash�assertstate_key�_early_rewrite_bailout�trace�
_find_spec�	importlibr�spec_from_file_location�origin�
isinstancer:�	machinery�SourceFileLoader�os�path�exists�_should_rewriter;)r5�namerH�target�state�spec�	_path_str�fns        r�	find_specz AssertionRewritingHook.find_specYs'���������!�!�/�2���&�&�t�U�3��
���.�t�f�5�6����t�T�*���<�D�,�"�
�	� �~�~�=�=�d�I�N���#��
�
�L��{�{�"��d�k�k�9�+>�+>�+O�+O�P��7�7�>�>�$�+�+�.�����B��#�#�D�"�e�4���~�~�5�5����'+�'F�'F�	6�
�	
rc��y�Nr)r5rNs  r�
create_modulez$AssertionRewritingHook.create_module�s��rc���|j�J�|jj�J�t|jj�}|jjt
}||j|j<tj}t|�}|r#t|�}|sd}|jd|���|jddtz}||z}t|||j�}	|	�M|jd|���t!||j�\}
}	|r2d|_	t%||	|
|�d|_n|jd|���t'|	|j(�y#d|_wxYw)NFzread only directory: ���z
rewriting Tzfound cached rewritten pyc for )�__spec__rCrr)r<r=r.r�sys�dont_write_bytecode�
get_cache_dir�try_makedirsr?rK�PYC_TAIL�	_read_pyc�
_rewrite_testr1�
_write_pyc�exec�__dict__)r5�modulerPrM�write�	cache_dir�ok�
cache_name�pyc�co�source_stats           r�exec_modulez"AssertionRewritingHook.exec_module�sY�����*�*�*����%�%�1�1�1�
�&�/�/�(�(�
)�����!�!�/�2��13����f�o�o�.��+�+�+��!�"�%�	���i�(�B�������3�I�;�?�@��W�W�S�b�\�H�,�
��*�$���r�3����
,��
�:��K�K�*�R�F�+�,�+�B����<�O�K���$(��!�.��u�b�+�s�;�(-�D�%��K�K�9�"��>�?��R����!��).�D�%�s�(E)�)	E2c��|j��|js�d|_|jjD]h}t|�j	t
j�}|jjt
jj|d�d��j|j	d�}|d|jvryt|�jd�}|jD]1}t
jj|�ryt||�s�1y|j!||�ry|j#d|���y)a'A fast way to get out of rewriting modules.

        Profiling has shown that the call to PathFinder.find_spec (inside of
        the find_spec from this class) is a major slowdown, so, this method
        tries to filter what we're sure won't be rewritten before getting to
        it.
        T���rr#Fr z early skip of rewriting module: )r-r4�
_initialpaths�str�splitrG�sepr2�addrH�splitextr�with_suffixr+�dirnamer�_is_marked_for_rewriter?)r5rKrM�initial_path�partsrH�pats       rr>z-AssertionRewritingHook._early_rewrite_bailout�s���<�<�#�D�,G�,G�*.�D�'� $��� :� :�
U���L�)�/�/����7���0�0�4�4�R�W�W�5E�5E�e�B�i�5P�QR�5S�T�
U��
�
�3�����9��8�8�8�����+�+�E�2���;�;�	�C��w�w���s�#���#�t�$��
	��&�&�t�U�3��
���6�t�f�=�>�rc��tjj|�dk(r|jd|���y|j�9|jjt
|��r|jd|���yt|�}|jD]$}t||�s�|jd|���y|j||�S)Nzconftest.pyzrewriting conftest file: Tz.matched test file (was specified on cmdline): zmatched test file )rGrH�basenamer?r-�
isinitpathrrr+rru)r5rKrPrM�fn_pathrxs      rrJz&AssertionRewritingHook._should_rewrite�s���
�7�7���B��=�0��K�K�3�B�6�:�;���<�<�#��|�|�&�&�|�B�'7�8����L�R�F�S�T���2�,���;�;�	�C��#�w�'����0���7�8��	�
�*�*�4��7�7rc	��	|j|S#t$rf|jD]E}||k(s|j|dz�s�|j	d|�d|�d��d|j|<Yyd|j|<YywxYw)Nr#zmatched marked file z (from �)TF)r3�KeyErrorr0�
startswithr?)r5rKrM�markeds    rruz-AssertionRewritingHook._is_marked_for_rewrite�s���
	��1�1�$�7�7���	��,�,�
 ���6�>�T�_�_�V�c�\�%B��K�K�"6�t�h�g�f�Z�q� Q�R�;?�D�2�2�4�8��	
 �49�D�*�*�4�0��	�s��1B�(B�-B�?Bc���t|�jtj�j	|j
�}|D]j}tj|}tj|jxsd�r�:t|jt|��r�Z|j|��l|jj|�|jj!�y)z�Mark import names as needing to be rewritten.

        The named module or package as well as any nested modules will
        be rewritten on import.
        �N)r/�intersectionrX�modules�
differencer.�AssertionRewriter�is_rewrite_disabled�__doc__rD�
__loader__�type�_warn_already_importedr0�updater3�clear)r5�names�already_importedrK�mods     r�mark_rewritez#AssertionRewritingHook.mark_rewrites���
��J�#�#�C�K�K�0�;�;�D�<Q�<Q�R�	�%�	2�D��+�+�d�#�C�$�8�8����!�r�� �����d��<��+�+�D�1�	2�	
���!�!�%�(��&�&�,�,�.rc�\�ddlm}|jj|d|���d��y)Nr��PytestAssertRewriteWarningz0Module already imported so cannot be rewritten: �)�
stacklevel)�_pytest.warning_typesr�r)�issue_config_time_warning)r5rKr�s   rr�z-AssertionRewritingHook._warn_already_importeds3��D����-�-�&�B�4�&�I�
��		.�	
rc�f�t|d�5}|j�cddd�S#1swYyxYw)zOptional PEP302 get_data API.�rbN)�open�read)r5�pathname�fs   r�get_datazAssertionRewritingHook.get_datas,��
�(�D�
!�	�Q��6�6�8�	�	�	�s�'�0���
)r��r)�TraversableResourcesc��tjdkrddlm}nddlm}|tj|j|���S)N)r��r)�
FileReader)rH)rX�version_info�importlib.readersr��importlib.resources.readers�types�SimpleNamespacer.)r5rKr�s   r�get_resource_readerz*AssertionRewritingHook.get_resource_reader*s7�����'�)�8�B��e�3�3��9N�9N�t�9T�U�V�Vr)r)r�return�None)r-zSession | Noner�r��NN)rKrnrHzSequence[str | bytes] | NonerL�types.ModuleType | Noner�z%importlib.machinery.ModuleSpec | None)rNzimportlib.machinery.ModuleSpecr�r�)rbztypes.ModuleTyper�r�)rKrnrMrr��bool)rKrnrPrnrMrr�r�)r�rnr�r�)rKrnr�r�)r�zstr | bytesr��bytes)rKrnr�r�)rrrr�r6r8rArE�
PathFinderrQr@rTrjr>rJrur�r�r�rXr��importlib.resources.abcr��
importlib.abcr�rrrr%r%?s���;�,� ,�
�$�$�/�/�9�9�J�
.2�*.�	0
��0
�+�0
�(�	0
�

/�0
�d�2��	 ��
("�T%�N8�*�/�$
��
���7�"����w�&�D�:�	W�
#rr%c�^�|jtjj�d}|j|�t	|j
�dz}|jdz}|jtjd||��|jtj|��y)N����z<LL)rcrAr�MAGIC_NUMBER�int�st_mtime�st_size�struct�pack�marshal�dumps)�fprirh�flags�mtime�sizes      r�
_write_pyc_fpr�3s}���H�H�Y�^�^�
(�
(�)��E��H�H�U�O���$�$�%�
�2�E�����+�D��H�H�V�[�[���t�
,�-��H�H�W�]�]�2�
�rc��|�dtj���}	t|d�5}t|||�ddd�	tj||�y#1swY�!xYw#t$r+}|jd|�d|j���Yd}~yd}~wwxYw#t$r!}|jd|�d|���Yd}~yd}~wwxYw)Nr#�wbzerror writing pyc file at z: errno=Fz: T)rG�getpidr�r��OSErrorr?�errno�replace)rMrhrirg�proc_pycr��es       rr_r_Es�����a��	�	��}�%�H��
�(�D�
!�	/�R��"�k�2�.�	/��
�
�
�8�S�!��	/�	/����
���0��
�(�1�7�7�)�L�M�������
���0���R��s�;�<����sD�A!�A�A!�B�A�A!�!	B�*!B�B�	C�!B=�=Cc���tj|�}|j�}t|�}t	j
||��}t
||||�t||dd��}||fS)z1Read and rewrite *fn* and return the code object.)�filenamer`T)�dont_inherit)rG�stat�
read_bytesrn�ast�parse�rewrite_asserts�compile)rPr)r��source�strfn�treerhs       rr^r^^sZ��
�7�7�2�;�D�
�]�]�_�F���G�E��9�9�V�e�,�D��D�&�%��0�	��u�f�4�	8�B���8�Orc��yrSr)�xs r�<lambda>r�js�rc��	t|d�}|5	tj|�}t	|j
�}|j}|jd�}t|�dk7r|d|�d��	ddd�y|ddtjjk7r|d|�d��	ddd�y|dd	d
k7r|d|�d��	ddd�y|d	d}	tj|	d
�|dzk7r|d|�d��	ddd�y|dd}
tj|
d
�|dzk7r|d|�d��	ddd�y	tj|�}t!|t"j$�s|d|�d��	ddd�y|cddd�S#t$rYywxYw#t$r }|d|�d|���Yd}~ddd�yd}~wwxYw#t$r }|d|�d|���Yd}~ddd�yd}~wwxYw#1swYyxYw)zsPossibly read a pytest pyc containing rewritten code.

    Return rewritten code if successful or None if not.
    r�N�z
_read_pyc(z): OSError z): invalid pyc (too short)�z!): invalid pyc (bad magic number)�r�z"): invalid pyc (unsupported flags)r��littler�z): out of datez): invalid pyc (incorrect size)z): marshal.load error z): not a code object)r�r�rGr�r�r�r�r��lenrArr��
from_bytesr��load�	ExceptionrDr��CodeType)r�rgr?r��stat_resultr�r��datar��
mtime_data�	size_datarhs            rr]r]isM���
�#�t�_��
�#�	��'�'�&�/�K���,�,�-�E��&�&�D��7�7�2�;�D�
�t�9����J�v�h�&@�A�B��#�#����8�y�~�~�2�2�2��J�v�h�&G�H�I��#�#� ��!�9�+�+��J�v�h�&H�I�J��%#�#�&�!�B�Z�
��>�>�*�h�/�5�:�3E�E��J�v�h�n�5�6��-#�#�.��B�K�	��>�>�)�X�.�$��2C�C��J�v�h�&E�F�G��5#�#�6	����b�!�B��"�e�n�n�-��J�v�h�&:�;�<��E#�#�F�G#�#��������	��J�v�h�k�!��5�6��#�#��	��.�	��J�v�h�&<�Q�C�@�A��?#�#��:	��;#�#�s��F�G7�AF�G7�=-G7�3G7�.G7�.G7�G�'G7�G7�	F�F�	G�(G�6G7�G�G7�	G4�G/�"G7�/G4�4G7�7Hc�<�t|||�j|�y)z%Rewrite the assert statements in mod.N)r��run)r�r��module_pathr)s    rr�r��s���k�6�6�2�6�6�s�;rc��t|tj�r|jSt	t
j�}t||��jdd�S)a�Get a safe repr of an object for assertion error messages.

    The assertion formatting (util.format_explanation()) requires
    newlines to be escaped since they are a special character for it.
    Normally assertion.util.format_explanation() does this but for a
    custom repr it is possible to contain one of the special escape
    sequences, especially '\n{' and '\n}' are likely to be present in
    JSON reprs.
    ��maxsize�
�\n)	rDr��
MethodTyper�_get_maxsize_for_safereprr�_configrr�)�objr�s  r�	_safereprr��sF���#�u�'�'�(��|�|��'����5�G��C��)�1�1�$��>�>rc�~�|�d}n|jtj�}|dk\ry|dk\r	tdzStS)zJGet `maxsize` configuration for saferepr based on the given config object.Nr��r�)�
get_verbosityr�VERBOSITY_ASSERTIONSr
)r)�	verbositys  rr�r��sD��
�~��	��(�(��)D�)D�E�	��A�~���A�~�$�r�)�)� � rc���ddg}t|t�s4t|ttj
��}|j
d�|D]\}}|j||�}�|S)z�Format the custom assertion message given.

    For strings this simply replaces newlines with '\n~' so that
    util.format_explanation() will preserve them instead of escaping
    newlines.  For other objects saferepr() is used first.
    )r��
~)�%�%%)r�r)rDrnrr�rr��appendr�)r��replaces�r1�r2s    r�_format_assertmsgr�sd���{�+�H��c�3���s�5�d�l�l�C�D������'��"���B��k�k�"�b�!��"��Jrc�T�t|�ry	t|d�S#t$rYywxYw)NFrT)�callable�hasattrr�)r�s r�_should_repr_global_namer�s3����}����3�
�+�+�+������s��	'�'c�d�d|xrdxsdj|�zdz}|jdd�S)N�(z or z and r~rr)�joinr�)�explanations�is_or�explanations   r�_format_boolopr�s9����)�6�4�W�:�:�<�H�H�3�N�K����s�D�)�)rc��ttt|��||�D]\}}}	|}|s�ntj
�'t	j
|||||dz�}|�|SS#t$rd}Y�LwxYw)NTr�)�zip�ranger�r�r�_reprcompare)	�ops�results�expls�each_obj�i�res�expl�done�customs	         r�_call_reprcomparer!�s����E�#�c�(�O�W�e�<����3��	��7�D���
����$��"�"�3�q�6�8�A�;���Q���H�����M��K���	��D�	�s�A*�*A8�7A8c�T�tj�tj|||�yyrS�r�_assertion_pass)�lineno�origrs   r�_call_assertion_passr'�s%�����'����V�T�4�0�(rc�*�tjrdSdS)z�Check if any plugins implement the pytest_assertion_pass hook
    in order not to generate explanation unnecessarily (might be expensive).TFr#rrr�_check_if_assertion_pass_implr)s���'�'�4�2�U�2rznot %sz~%sz-%sz+%s�|�^�&z<<z>>�+�-�*�/z//rz==z!=�<z<=�>z>=�**�iszis not�inznot in�@c#�rK�|��tj|�D]}t|�Ed{����y7��w)zARecursively yield node and all its children in depth-first order.N)r��iter_child_nodes�
traverse_node)�node�childs  rr9r9$s6����
�J��%�%�d�+�(�� ��'�'�'�(�'�s�+7�5�7r�r�c��
���
��i�
d�g�d�
t��d
�
���
�fd�}tjtj|�j�}|D�]g\}}\}}}}|tj
k(r|dk(r|�
�(�
��+|tjk(r
|dvr�dz
�n|tjk(r	|dvr�dz��s&�j||d��j|����dk(r�|tjk(rm|dk(rh|�vr7t��dk(r)|t�d	�zt|�z
}	�d	d|	�d	<n$|�vr�d	d|�d	<n�j|d|�|���|tjtjhvr	|���<�s��@|�vs��F�j|��j|���j�
S)z<Return a mapping from {lineno: "assertion test expression"}.rNc�����J�dj��j�jd���<d�g�d�t��y)Nr��\r)r�rstripr/)�
assert_lineno�depth�lines�ret�
seen_liness�����r�_write_and_resetz._get_assertion_exprs.<locals>._write_and_reset5sK����(�(�(��W�W�U�^�2�2�4�;�;�D�A��M�������
��U�
r�assertz([{r�z)]}�,rl�r�r�)r/�tokenize�io�BytesIO�readline�NAME�OPrrqr��NEWLINE�	ENDMARKER)�srcrE�tokens�tpr�r%�offset�_�line�offset_in_trimmedr@rArBrCrDs          @@@@@r�_get_assertion_exprsrX+s�����C�
�E��E� $�M��5�J����
�
�r�z�z�#��7�7�
8�F�17�'�-��F�$�V�V�a��
�����6�X�#5�"�M�
�
&��X�[�[� �V�u�_���
���x�{�{�"�v�����
������T�&�'�]�+����v�&��!���h�k�k� 1�f��m��Z�'�C��J�!�O�(.��U�2�Y��(?�#�d�)�(K�%� %�b�	�*<�+<� =�E�"�I��z�)� %�b�	�'�6� 2�E�"�I��L�L��g�v��/� �"���(�(�(�*<�*<�=�=� �"��6��3����T�"����v�&�='�@�Jrc����eZdZdZ								d�fd�Zdd�Zedd��Zdd�Zdd�Z	dd�Z
dd�Zdd	�Zd d
�Z
d!d�Zd"d�Zd#d
�Zd$d�Zd%d�Zd&d�Zd'd�Zd(d�Zd)d�Zd*d�Zd+d�Zd,d�Zd-d�Z�xZS).r�a�
Assertion rewriting implementation.

    The main entrypoint is to call .run() with an ast.Module instance,
    this will then find all the assert statements and rewrite them to
    provide intermediate values and a detailed assertion error.  See
    http://pybites.blogspot.be/2011/07/behind-scenes-of-pytests-new-assertion.html
    for an overview of how this works.

    The entry point here is .run() which will iterate over all the
    statements in an ast.Module and for each ast.Assert statement it
    finds call .visit() with it.  Then .visit_Assert() takes over and
    is responsible for creating new ast statements to replace the
    original assert statement: it rewrites the test of an assertion
    to provide intermediate values and replace it with an if statement
    which raises an assertion error with a detailed explanation in
    case the expression is false and calls pytest_assertion_pass hook
    if expression is true.

    For this .visit_Assert() uses the visitor pattern to visit all the
    AST nodes of the ast.Assert.test field, each visit call returning
    an AST node and the corresponding explanation string.  During this
    state is kept in several instance attributes:

    :statements: All the AST statements which will replace the assert
       statement.

    :variables: This is populated by .variable() with each variable
       used by the statements so that they can all be set to None at
       the end of the statements.

    :variable_counter: Counter to create new unique variables needed
       by statements.  Variables are created using .variable() and
       have the form of "@py_assert0".

    :expl_stmts: The AST statements which will be executed to get
       data from the assertion.  This is the code which will construct
       the detailed assertion message that is used in the AssertionError
       or for the pytest_assertion_pass hook.

    :explanation_specifiers: A dict filled by .explanation_param()
       with %-formatting placeholders and their corresponding
       expressions to use in the building of an assertion message.
       This is used by .pop_format_context() to build a message.

    :stack: A stack of the explanation_specifiers dicts maintained by
       .push_format_context() and .pop_format_context() which allows
       to build another %-formatted string while already building one.

    :scope: A tuple containing the current scope used for variables_overwrite.

    :variables_overwrite: A dict filled with references to variables
       that change value within an assert. This happens when a variable is
       reassigned with the walrus operator

    This state, except the variables_overwrite,  is reset on every new assert
    statement visited and used by the other visitors.
    c����t�|��||_||_|�|j	d�|_nd|_||_d|_tt�|_
y)N�enable_assertion_pass_hookFr)�superr6r�r)r*r[r��scoper�dict�variables_overwrite)r5r�r)r��	__class__s    �rr6zAssertionRewriter.__init__�sa���	����&��������.4�m�m�,�/�D�+�/4�D�+����*,��
����	
� rc���|jsyt|dd�}|du}|�|j|�ryd}d}|jD]�}|r�t|tj
�rtt|jtj�rPt|jjt�r,|jj}|j|�ryd}n;t|tj�r|jdk(r|jdk(rnn|dz
}��t|tj�r&|jr|jdj}n|j}tj dk\r3t	j"dd	|d�
�t	j"dd|d�
�g}n,t	j"dd	�t	j"dd�g}|D�cgc]}t	j$|g|d�
���}	}|	|j|||f|_|g}
|
�r�|
j)�}t|tjtj*tj,f�r4t/g|j&�|���|_|
j1t2�|t2k(r|j&dd
|_��t|tj4�sJ�t	j6|�D]�\}}
t|
t8�r�g}t;|
�D]}\}}t|tj<�r!|j?|jA|���A|j1|�t|tj4�s�m|
j1|��tC|||���t|
tj4�s��t|
tjD�r��|
j1|
���|
r���yycc}w)z5Find all assert statements in *mod* and rewrite them.N�	docstringrF�
__future__r�r��builtins�@py_builtins)r%�
col_offsetz_pytest.assertion.rewrite�
@pytest_arrl)#�body�getattrr�rDr��Expr�value�Constantrn�
ImportFrom�levelrb�FunctionDef�decorator_listr%rXr��alias�Importr]�pop�AsyncFunctionDef�ClassDef�tupler�_SCOPE_END_MARKER�AST�iter_fields�list�	enumerate�Assert�extend�visit�setattr�expr)r5r��doc�expect_docstring�pos�itemr%�aliasesrq�imports�nodesr:rK�field�newrr;s                 rr�zAssertionRewriter.run�s+���x�x���c�;��-���$�;���?�t�7�7��<�������H�H�	�D� ��t�S�X�X�.��t�z�z�3�<�<�8��t�z�z�/�/��5��j�j�&�&���+�+�C�0��#(� ��4����0��J�J�!�O��K�K�<�/����1�H�C�'	�,�d�C�O�O�,��1D�1D��(�(��+�2�2�F��[�[�F����w�&��	�	�*�n�V�PQ�R��	�	�/� �!� �	��G��	�	�*�n�5��	�	�5�|�D��G�
KR�
�AF�C�J�J��w�v�!�<�
��
�$�����S���V��
�+.�%����9�9�;�D��$����#�2F�2F���� U�V�"�#6�T�Z�Z�#6��#6�7��
����.�/��(�(�!�Z�Z���_��
���d�C�G�G�,�,�,�"���t�4�
(���e��e�T�*�)+�C�$-�e�$4�4���5�%�e�S�Z�Z�8��J�J�t�z�z�%�'8�9��J�J�u�-�)�%����9� %���U� 3�4��D�$��,��u�c�g�g�.�'�u�c�h�h�7��L�L��'�%
(���
s� O%c�
�d|vS)N�PYTEST_DONT_REWRITEr)rbs rr�z%AssertionRewriter.is_rewrite_disableds
��$�	�1�1rc�~�dtt|j��z}|jj	|�|S)zGet a new variable.z
@py_assert)rn�next�variable_counter�	variablesr)r5rKs  r�variablezAssertionRewriter.variables5���c�$�t�'<�'<�"=�>�>�������d�#��rc	��|j�}|jjtjtj
|tj��g|��tj
|tj��S)zGive *expr* a name.)r��
statementsrr��Assign�Name�Store�Load)r5r�rKs   r�assignzAssertionRewriter.assignsU���}�}��������s�z�z�3�8�8�D�#�)�)�+�+F�*G��N�O��x�x��c�h�h�j�)�)rc�&�|jd|�S)z Call saferepr on the expression.r�)�helper)r5r�s  r�displayzAssertionRewriter.displays���{�{�;��-�-rc���tjdtj��}tj||tj��}tj|t|�g�S)zCall a helper in this module.rg)r�r�r��	Attribute�Callrz)r5rK�args�py_name�attrs     rr�zAssertionRewriter.helper!sG���(�(�<�����4���}�}�W�d�C�H�H�J�7���x�x��d�4�j�"�-�-rc��tjdtj��}tj||tj��S)z!Return the builtin called *name*.re)r�r�r�r�)r5rK�builtin_names   r�builtinzAssertionRewriter.builtin's1���x�x�����
�;���}�}�\�4�����<�<rc�r�dtt|j��z}||j|<d|zdzS)aJReturn a new named %-formatting placeholder for expr.

        This creates a %-formatting placeholder for expr in the
        current formatting context, e.g. ``%(py0)s``.  The placeholder
        and expr are placed in the current format context so that it
        can be used on the next call to .pop_format_context().
        �pyz%(z)s)rnr�r��explanation_specifiers)r5r��	specifiers   r�explanation_paramz#AssertionRewriter.explanation_param,s>���3�t�D�$9�$9�:�;�;�	�15��#�#�I�.��i��$�&�&rc�\�i|_|jj|j�y)a�Create a new formatting context.

        The format context is used for when an explanation wants to
        have a variable value formatted in the assertion message.  In
        this case the value required can be added using
        .explanation_param().  Finally .pop_format_context() is used
        to format a string of %-formatted values as added by
        .explanation_param().
        N)r��stackr)r5s r�push_format_contextz%AssertionRewriter.push_format_context8s$��<>��#��
�
���$�5�5�6rc	��|jj�}|jr|jd|_|j�D�cgc]}t	j
|���}}t	j|t|j���}t	j|t	j�|�}dtt|j��z}|jr|jj!|�|j"j!t	j$t	j&|t	j(��g|��t	j&|t	j*��Scc}w)aZFormat the %-formatted string with current format context.

        The expl_expr should be an str ast.expr instance constructed from
        the %-placeholders created by .explanation_param().  This will
        add the required code to format said string to .expl_stmts and
        return the ast.Name instance of the formatted string.
        rlz
@py_format)r�rsr��keysr�rl�Dictrz�values�BinOp�Modrnr�r�r[�format_variablesr�
expl_stmtsr�r�r�r�)r5�	expl_expr�current�keyr��format_dict�formrKs        r�pop_format_contextz$AssertionRewriter.pop_format_contextEs���*�*�.�.�"���:�:�*.�*�*�R�.�D�'�DK�L�L�N�&S�S�s�|�|�C�'8�&S��&S��h�h�t�T�'�.�.�*:�%;�<���y�y��C�G�G�I�{�;���c�$�t�'<�'<�"=�>�>���*�*��!�!�(�(��.������s�z�z�3�8�8�D�#�)�)�+�+F�*G��N�O��x�x��c�h�h�j�)�)��'Ts�
Fc��t|tj�sJ�|j|�}||j	|j|��fS)z1Handle expressions we don't have custom code for.)rDr�r�r�r�r�)r5r:rs   r�
generic_visitzAssertionRewriter.generic_visitYsC���$����)�)�)��k�k�$����D�*�*�4�<�<��+<�=�=�=rc	��t|jtj�rit	|jj
�dk\rGddl}ddlm}|j�J�|j|d�d|j|j��g|_g|_
tj�|_|j"rg|_g|_g|_|j+�|j-|j�\}}tj.tj0�|�}|j"�r�|j3tj4|��}|j6r|j9d|j6�}d}	ntj4d	�}d
}	tj:tj4|	�tj<�|�}
tj:|tj<�|
�}tj>dtj@��}|j9d|�}
tjB||
gg�}tjD|d�}g}|jG|j(�|jI|�|j9d|�}tK|jL�|j}tjN|j9d
tj4|j�tj4|�|��}tjP|j9d�g|j(�|�g�}|g}tjP|||�}|jjI|�|j$�r�|j$D�cgc]*}tj>|tjR����,}}tjT|tj4d��}|jjI|��nJ|j(}|jjItjP||g��|j6r"|j9d|j6�}d|z}ntj4d	�}d
|z}tj:|tj<�tj4|��}|j3|�}|j9d|�}
tj>dtj@��}tjB||
gg�}tjD|d�}|jI|�|jr�|jD�cgc]*}tj>|tjR����,}}tjT|tj4d��}|jjI|�|jD](}tW|�D]}tjX||���*|jScc}wcc}w)a.Return the AST statements to replace the ast.Assert instance.

        This rewrites the test of an assertion to provide
        intermediate values and replace it with an if statement which
        raises an assertion error with a detailed explanation in case
        the expression is false.
        r�rNr�z5assertion is always true, perhaps remove parentheses?)�categoryr�r%rz	
>assert r�zassert �AssertionError�_format_explanationr'r))-rD�testr��Tupler��elts�warningsr�r�r��
warn_explicitr%r�r��	itertools�countr�r[r�r�r�r�r~�UnaryOp�Notr�rl�msgr�r��Addr�r�r��Raiser}rrXr�rj�Ifr�r�r9�
copy_location)r5�assert_r�r��
top_conditionr�negationr��	assertmsg�gluestr�err_explanation�err_msg�err_name�fmt�exc�raise_�statements_fail�fmt_passr&�hook_call_pass�hook_impl_test�statements_pass�	main_testrKr��clear_formatrh�templater��stmtr:s                               r�visit_AssertzAssertionRewriter.visit_Assert_s����g�l�l�C�I�I�.�3�w�|�|�7H�7H�3I�Q�3N��H��#�#�/�/�/��"�"�*�K����)�)��~�~�

#�
�+-���$&��� )��� 1����*�*�/1�D�!�02��
�*,���� � �"�%)�Z�Z����%=�"�
�{��;�;�s�w�w�y�-�8���*�*��)�)�#�,�,�{�*C�D�C��{�{� �K�K�(;�W�[�[�I�	�&���L�L��,�	�#��!�i�i����W�(=�s�w�w�y�#�N�O��i�i�	�3�7�7�9�o�F�G��x�x� 0�#�(�(�*�=�H��+�+�3�W�=�C��(�(�8�c�U�B�/�C��Y�Y�s�D�)�F� �O��"�"�4�?�?�3��"�"�6�*��{�{�#8�#�>�H�'����4�W�^�^�D�D� �X�X����*��L�L����0��L�L��&��	��N�!�V�V����;�<�2�$�/�/�2�>�2���N�
0>�.>�O����x��/�J�I��O�O�"�"�9�-��$�$�<@�<Q�<Q�-�48�C�H�H�T�3�9�9�;�/�-�	�-� #�z�z�)�S�\�\�$�5G�H�����&�&�|�4��?�?�D��O�O�"�"�3�6�6�(�D�"�#=�>��{�{� �K�K�(;�W�[�[�I�	�*�[�8���L�L��,�	�'�+�5���y�y��C�G�G�I�s�|�|�K�7P�Q�H��)�)�(�3�C��+�+�3�S�9�C��x�x� 0�#�(�(�*�=�H��(�(�8�c�U�B�/�C��Y�Y�s�D�)�F��K�K����>�>�AE���P�����$��	�	��4�P�I�P��J�J�y�#�,�,�t�*<�=�E��O�O�"�"�5�)��O�O�	1�D�%�d�+�
1���!�!�$��0�
1�	1������E-��6Qs�)/X<�/Yc��tj|jd�gg�}|jj}tj
tj|�tj�g|g�}|jd|�}tjtj�||g�}tj||j|�tj|��}||j|�fS�N�localsr)r�r�r�rL�id�Comparerl�Inr��BoolOp�Or�IfExpr�r�)r5rK�locs�	target_id�inlocs�doreprr�r�s        r�visit_NamedExprz!AssertionRewriter.visit_NamedExpr�s����x�x����X�.��B�7���K�K�N�N�	����S�\�\�)�4�s�v�v�x�j�4�&�I�����7��>���z�z�#�&�&�(�V�V�$4�5���y�y��t�|�|�D�1�3�<�<�	�3J�K���T�+�+�D�1�1�1rc��tj|jd�gg�}tjtj|j
�tj�g|g�}|jd|�}tjtj�||g�}tj||j|�tj|j
��}||j|�fSr�)
r�r�r�r�rlr�r�r�r�r�r�r�r�)r5rKr�r�r�r�r�s       r�
visit_NamezAssertionRewriter.visit_Name�s����x�x����X�.��B�7�����S�\�\�$�'�'�2�S�V�V�X�J���G�����7��>���z�z�#�&�&�(�V�V�$4�5���y�y��t�|�|�D�1�3�<�<����3H�I���T�+�+�D�1�1�1rc
��|j�}|jtjgtj���}tj
|dtj��}t
t|jtj��}|jx}}|j}t|j�dz
}	|j�t|j�D�]�\}
}|
�r9g}|jj!tj"
|g��||_t|tj$�r�t|j&tj(�r�|j&j*j,|jd|
D�cgc]}t/|d�r|j,��c}vro|j�}|j&|j0|j2|j&j*j,<||j&j*_|j�|j5|�\}}|j!tj6tj8|tj:��g|��|j=tj>|��}tj@||gg�}|jj!tjB|��|
|	ks��$|}
|r(tjDtjF�|
�}
g}|jj!tj"|
|g��|x|_
}���||_
||_|jId|tj>|��}|j=|�}tj8|tj��|jK|�fScc}w)Nrr�r�r)&r�r�r��Listr�r�r�rD�opr�r�r�r�r�r�r{rr�r��left�	NamedExprrLr�rr_r]r~r�r�r�r�rlr�rjr�r�r�r�)r5�boolop�res_var�	expl_list�apprrh�save�	fail_save�levelsr�v�
fail_inner�cond�ast_expr�pytest_temprr�expl_format�call�inner�
expl_templates                      r�visit_BoolOpzAssertionRewriter.visit_BoolOp�s����-�-�/���K�K�����S�X�X�Z� 8�9�	��m�m�I�x�����<���J�v�y�y�#�&�&�1�2���o�o�%��t��O�O�	��V�]�]�#�a�'��� � �"��f�m�m�,� 	/�D�A�q��-/�
����&�&�s�v�v�d�J��'C�D�",����q�#�+�+�.�"�1�6�6�3�=�=�9����
�
�(�(�)/�
�
�b�q�(9��$�"�8�T�2�!�����#'�-�-�/�K�MN�V�V�D�,�,�T�Z�Z�8������9I�9I�J�'2�A�F�F�M�M�$��$�$�&��
�
�1�
�I�C���K�K��
�
�C�H�H�W�c�i�i�k�$B�#C�S�I�J��1�1�#�,�,�t�2D�E�K��8�8�C�+���3�D��O�O�"�"�3�8�8�D�>�2��6�z�!$����;�;�s�w�w�y�$�7�D�(*�����&�&�s�v�v�d�E�2�'>�?�).�.���$�A 	/�B���#������$4�i����e�AT�U�
��&�&�}�5���x�x������,�d�.D�.D�T�.J�J�J��5s�&Pc���t|jj}|j|j�\}}|jt
j|j|��}|||fzfSrS)�	UNARY_MAPr�r`r~�operandr�r�r�)r5�unary�pattern�operand_res�operand_explrs      r�
visit_UnaryOpzAssertionRewriter.visit_UnaryOps\���E�H�H�.�.�/��$(�J�J�u�}�}�$=�!��\��k�k�#�+�+�e�h�h��<�=���G�|�o�-�-�-rc�4�t|jj}|j|j�\}}|j|j
�\}}d|�d|�d|�d�}|j
tj||j|��}||fS)Nr� r~)	�	BINOP_MAPr�r`r~r��rightr�r�r�)	r5�binop�symbol�	left_expr�	left_expl�
right_expr�
right_explrrs	         r�visit_BinOpzAssertionRewriter.visit_BinOp"s����5�8�8�-�-�.��#�z�z�%�*�*�5��	�9�!%���E�K�K�!8��
�J��)��A�f�X�Q�z�l�!�<���k�k�#�)�)�I�u�x�x��D�E���K��rc��|j|j�\}}g}g}g}|jD]�}t|tj
�rX|j|jj|ji�vr&|j|j|j}|j|�\}}	|j|	�|j|���|jD�](}
t|
jtj
�rq|
jj|jj|ji�vr5|j|j|
jj|
_|j|
j�\}}	|jt	j|
j|��|
jr#|j|
jdz|	z���|jd|	z���+dj|dj!|��}	t	j"|||�}|j%|�}|j'|j)|��}|�d|�d|	�d�}
||
fS)N�=r3z{}({})z, z
{z = z
})r~�funcr�rDr�r�r�r_�getr]r�keywordsrk�keyword�arg�formatrr�r�r�r�)r5r�new_func�	func_expl�	arg_expls�new_args�
new_kwargsr"rrr!�new_call�res_expl�
outer_expls              r�
visit_CallzAssertionRewriter.visit_Call*s��"�j�j����3���)��	����
��9�9�	!�C��#�s�x�x�(�S�V�V�t�7O�7O�7S�7S��
�
�B�8�.��.�.�t�z�z�:�3�6�6�B���
�
�3��I�C�����T�"��O�O�C� �	!��}�}�
	.�G���
�
�s�x�x���-�-�"�"�d�&>�&>�&B�&B�4�:�:�r�&R�R� $� 8� 8���� D�W�]�]�EU�EU� V��
��
�
�7�=�=�1�I�C�����c�k�k�'�+�+�s�;�<��{�{�� � ����s�!2�T�!9�:�� � ����-�
	.����y�$�)�)�I�*>�?���8�8�H�h�
�;���k�k�(�#���)�)�$�,�,�s�*;�<�� �z��h�Z�s�4�&��=�
��J��rc��|j|j�\}}tj||j�}|d|zfS)Nr/)r~rkr��Starred�ctx)r5�starredrr�new_starreds     r�
visit_StarredzAssertionRewriter.visit_StarredJs;���J�J�w�}�}�-�	��T��k�k�#�w�{�{�3���C�$�J�&�&rc��t|jtj�s|j	|�S|j|j�\}}|jtj||jtj���}|j|j|��}d}|||||jfz}||fS)Nz%s
{%s = %s.%s
})rDr/r�r�r�r~rkr�r�r�r�r�)r5r�rk�
value_explrr*rxrs        r�visit_Attributez!AssertionRewriter.visit_AttributePs����$�(�(�C�H�H�-��%�%�d�+�+� �J�J�t�z�z�2���z��k�k�#�-�-��t�y�y�#�(�(�*�E�F���)�)�$�,�,�s�*;�<��"���h��*�d�i�i�@�@���D�y�rc�H
�|j�t|jtj�rq|jj
|jj|ji�vr5|j|j|jj
|_t|jtj�rD|j|j|j|jjj
<|j|j�\}}t|jtjtjf�rd|�d�}tt|j ��D�cgc]}|j#���}}|D�cgc]*}tj|tj$����,}}|D�cgc]*}tj|tj&����,}}t)tt|j ��|j |j*�}	g}
g}|g}|	D�]�\}}
}t|tj�r�t|tj�rh|jj
|j
k(rE|j#�|j_||j|j|j
<|j|�\}}t|tjtjf�rd|�d�}|j-|�t.|
j0}|j-tj2|��|�d|�d|��}|
j-tj2|��tj||
g|g�}|j4j-tj6||g|��||}}���|j9dtj:|tj$��tj:|tj$��tj:|
tj$��tj:|tj$���}t|j �dkDr)tjtj<�|�}n|d}||j?|jA|��fScc}wcc}wcc}w)Nrr~rr!r�r)!r�rDr�r�r�r�r_rr]r�rLr~r�r�rr�rr�r�r�r�comparatorsrrr`rlr�r�r�r��Andr�r�)r5�comp�left_resrr�
res_variablesr��
load_names�store_names�itr�symsrr��next_operand�next_res�	next_expl�symr�res_expr�	expl_callrs                      r�
visit_ComparezAssertionRewriter.visit_CompareZs���� � �"���I�I�s�x�x�
��i�i�l�l�d�6�6�:�:�4�:�:�r�J�J��0�0����<�T�Y�Y�\�\�J�D�I��d�i�i����/�HL�	�	�D�$�$�T�Z�Z�0����1A�1A�1D�1D�E�"�j�j����3���)��d�i�i�#�+�+�s�z�z�!:�;��I�;�a�(�I�27��D�H�H�
�2F�G�Q�����G�
�G�GT�%U�!�c�h�h�q�#�(�(�*�&=�%U�
�%U�9F�G�A�s�x�x��3�9�9�;�/�G��G�
��s�4�8�8�}�%�t�x�x��1A�1A�
B�� "��!���*��#%�	6��A�r�<��<����7��x����2� �'�'�*�*�h�k�k�9�)-�����#�#�&�DP��(�(����4�X�[�[�A�"&�*�*�\�":��H�i��,����c�j�j�(A�B��	�{�!�,�	��N�N�8�$��B�L�L�)�C��K�K����S�)�*��[��#��a�	�{�3�D��L�L����d�+�,��{�{�8�b�T�H�:�>�H��O�O�"�"�3�:�:�{�1�~�.>��#I�J�"*�I�i�H�%	6�(�K�K���I�I�d�C�H�H�J�'��I�I�j�#�(�(�*�-��I�I�e�S�X�X�Z�(��I�I�g�s�x�x�z�*�
�	��t�x�x�=�1���J�J�s�w�w�y�*�=�C��Q�-�C��D�*�*�4�+B�+B�9�+M�N�N�N��OH��%U��Gs�T�#/T�/T)r��
str | Noner)�
Config | Noner�r�r�r�)r��
ast.Moduler�r�)rbrnr�r�)r�rn)r��ast.exprr��ast.Name)r�rJr�rJ)rKrnr�rJr�rJ)rKrnr��
ast.Attribute)r�rJr�rnrH)r�rJr�rK)r:�ast.ASTr��tuple[ast.Name, str])r�z
ast.Assertr�zlist[ast.stmt])rKz
ast.NamedExprr�ztuple[ast.NamedExpr, str])rKrKr�rN)r�z
ast.BoolOpr�rN)rzast.UnaryOpr�rN)rz	ast.BinOpr�rN)rzast.Callr�rN)r0zast.Starredr�ztuple[ast.Starred, str])r�rLr�rN)r9zast.Comparer�ztuple[ast.expr, str])rrrr�r6r��staticmethodr�r�r�r�r�r�r�r�r�r�r�r�r�rrrr,r2r5rF�
__classcell__)r`s@rr�r�bs����8�t
�%�
�/<�
�FK�
�	
�
�$[(�z�2��2��*�.�.�=�

'�7�*�(>�t�l
2�2�/K�b.� ��@'��3Orr�c��	tj|d��y#tttf$rYyt
$rYyt$r7}|jtjtjhvrYd}~y�d}~wwxYw)z~Attempt to create the given directory and sub-directories exist.

    Returns True if successful or if it already exists.
    T)�exist_okFN)
rG�makedirs�FileNotFoundError�NotADirectoryError�FileExistsError�PermissionErrorr�r��EROFS�ENOSYS)rdr�s  rr[r[�sm��
�
���I��-� ��
�1�?�C��������

�7�7�u�{�{�E�L�L�1�1��
���s%��A9�A9�A9�,A4�3A4�4A9c��tjr/ttj�t|jdd�zS|jdzS)zKReturn the cache directory to write .pyc files for the given .py file path.r�rl�__pycache__)rX�pycache_prefixrrw�parent)�	file_paths rrZrZ�sF��
����C�&�&�'�$�	����"�0E�*F�F�F����-�/�/r)r�z	IO[bytes]ri�os.stat_resultrh�types.CodeTyper�r�)
rMrrhr`rir_rgrr�r�)rPrr)rr�z%tuple[os.stat_result, types.CodeType])r�rrgrr?zCallable[[str], None]r�ztypes.CodeType | Noner�)
r�rIr�r�r�rGr)rHr�r�)r��objectr�rn)r)rHr�z
int | None)r�rar�r�)rz
Iterable[str]rr�r�rn)
r�
Sequence[str]rzSequence[bool]rrbrzSequence[object]r�rn)r%r�r&rnrrnr�r�)r�r�)r:rMr�zIterator[ast.AST])rQr�r�zdict[int, str])rdrr�r�)r^rr�r)or�rcrr��collectionsrr��	functoolsr�rA�importlib.machinery�importlib.utilrJr�r�rG�pathlibrrr�rXrIr��typingrrr	r
rr�_pytest._io.safereprr
r�_pytest._versionr�_pytest.assertionr�_pytest.configr�_pytest.mainr�_pytest.pathlibrr�
_pytest.stashr�_pytest.assertion.utilrr�rrr=�implementation�	cache_tag�
PYTEST_TAG�PYC_EXTr\rw�abc�MetaPathFinder�Loaderr%r�r_r^r]r�r�r�rrrr!r'r)r��Invert�USub�UAddr
�BitOr�BitXor�BitAnd�LShift�RShiftr��Sub�Mult�Div�FloorDivr��Eq�NotEq�Lt�LtE�Gt�GtE�Pow�Is�IsNotr��NotIn�MatMultrr9�	lru_cacherX�NodeVisitorr�r[rZrrr�<module>r�s���;�"�
�#������	���	���
�
�������� �6�)�$�"�!� �(�&�"�M��0�	�	�-�(�+�,�.���"�"�,�,�-�X�g�Y�
?�
�
��+��
,�����g�%���J��qW�Y�]�]�9�9�9�=�=�;O�;O�qW�h �� � .� �4B� �	� �$����� ��
�	�

��2�=K�.��.��.�$9�.��.�h#� �	<�	�<��<��<�
�	<�

�<�?�$
!��,�*�
�	��
�����	�
	��(1�
3��W�W�h��
�
�E�3�8�8�U�C�H�H�e�T�	�
��I�I�s�
��J�J��
��J�J��
��J�J��	
�
�J�J��
��G�G�S�

��G�G�S�
��H�H�c�
��G�G�S�
��L�L�$�
��G�G�T�
��F�F�D�
��I�I�t�
��F�F�C�
��G�G�T�
� �F�F�C�!
�"�G�G�T�#
�$�G�G�T��F�F�D��I�I�x��F�F�D��I�I�x��K�K��/
�	�6(�����Q��3� �3�lkO����kO�\�20r

Youez - 2016 - github.com/yon3zu
LinuXploit