403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/django/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/django/test/__pycache__/utils.cpython-311.pyc
�

�|�e�w���ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZmZmZddlmZmZdd	lmZdd
lmZddlmZmZddl m!Z!dd
l"m#Z#ddl$m%Z%ddl&m'Z'm(Z(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3ddl4m5Z5	ddl6Z6n
#e7$rdZ6YnwxYwdZ8e9ed��Z:Gd�d��Z;Gd�de<��Z=d�Z>Gd�d��Z?dJd�Z@d�ZAdd d ddd!�d"�ZBd#�ZCdJd$�ZDdKd%�ZEdJd&�ZFGd'�d(��ZGGd)�d*eG��ZHGd+�d,eH��ZIGd-�d.eG��ZJd/�ZKGd0�d1��ZLGd2�d3eG��ZMee:d4��ZNe	d5���ZOe	d6���ZPe	d7���ZQd8�ZRd9�ZSd:�ZTe	d;���ZUd<�ZVGd=�d>eG��ZWGd?�d@��ZXGdA�dBeG��ZYGdC�dD��ZZGdE�dF��Z[dG�Z\e	ddH�dI���Z]dS)L�N)�contextmanager)�wraps)�StringIO)�chain)�SimpleNamespace)�TestCase�skipIf�
skipUnless)�Node�parseString)�apps)�Apps)�UserSettingsHolder�settings)�mail)�ImproperlyConfigured)�request_started)�DEFAULT_DB_ALIAS�connections�
reset_queries)�Options)�Template)�setting_changed�template_rendered)�get_script_prefix�set_script_prefix)�
deactivate)�Approximate�ContextList�isolate_lru_cache�
get_runner�CaptureQueriesContext�ignore_warnings�isolate_apps�modify_settings�override_settings�override_system_checks�tag�requires_tz_support�setup_databases�setup_test_environment�teardown_test_environment�tzsetc�"�eZdZdd�Zd�Zd�ZdS)r�c�"�||_||_dS�N)�val�places)�selfr2r3s   �3/usr/lib/python3/dist-packages/django/test/utils.py�__init__zApproximate.__init__1s����������c�*�t|j��Sr1)�reprr2�r4s r5�__repr__zApproximate.__repr__5s���D�H�~�~�r7c�t�|j|kp-tt|j|z
��|j��dkS�Nr)r2�round�absr3)r4�others  r5�__eq__zApproximate.__eq__8s5���x�5� �R�E�#�d�h��.>�*?�*?���$M�$M�QR�$R�Rr7N)r/)�__name__�
__module__�__qualname__r6r;rA�r7r5rr0sK�������������S�S�S�S�Sr7rc�6��eZdZdZ�fd�Zdd�Zd�Zd�Z�xZS)rzp
    A wrapper that provides direct key access to context items contained
    in a list of context objects.
    c���t|t��r"|D]}||vr
||cS�t|���t���|��Sr1)�
isinstance�str�KeyError�super�__getitem__)r4�key�
subcontext�	__class__s   �r5rLzContextList.__getitem__Ash����c�3���	,�"�
+�
+�
��*�$�$�%�c�?�*�*�*�%��3�-�-���7�7�&�&�s�+�+�+r7Nc�R�	|�|��S#t$r|cYSwxYwr1)rLrJ)r4rM�defaults   r5�getzContextList.getJs?��	��#�#�C�(�(�(���	�	�	��N�N�N�	���s��&�&c�<�	||n#t$rYdSwxYwdS)NFT)rJ)r4rMs  r5�__contains__zContextList.__contains__Ps9��	���I�I�I���	�	�	��5�5�	�����ts��
�c�X�ttjd�|D������S)z0
        Flattened keys of subcontexts.
        c3�$K�|]}|D]}|V���dSr1rE)�.0rN�ds   r5�	<genexpr>z#ContextList.keys.<locals>.<genexpr>[s/����&T�&T�Z��&T�&T�A�q�&T�&T�&T�&T�&T�&T�&Tr7)�setr�
from_iterabler:s r5�keyszContextList.keysWs,���5�&�&T�&T�4�&T�&T�&T�T�T�U�U�Ur7r1)	rBrCrD�__doc__rLrRrTr\�
__classcell__�rOs@r5rr<s{���������,�,�,�,�,��������V�V�V�V�V�V�Vr7rc�d�tj|||���|j�|��S)zt
    An instrumented Template render method, providing a signal that can be
    intercepted by the test Client.
    )�sender�template�context)r�send�nodelist�render)r4rcs  r5�instrumented_test_renderrg^s2��
��$��w�G�G�G�G��=����(�(�(r7c��eZdZdS)�
_TestStateN)rBrCrDrEr7r5ririgs�������Dr7ric���ttd��rtd���|�tj}t��}|t_tj|_gtj�d�t_tj|_	|t_tj
|_dt_
tj
|_tt_
gt _t%��dS)z�
    Perform global pre-test setup, such as installing the instrumented template
    renderer and setting the email backend to the locmem email backend.
    �
saved_datazxsetup_test_environment() was already called and can't be called again without first calling teardown_test_environment().N�
testserverz-django.core.mail.backends.locmem.EmailBackend)�hasattrri�RuntimeErrorr�DEBUGrrk�
ALLOWED_HOSTS�
allowed_hosts�debug�
EMAIL_BACKEND�
email_backendr�_render�template_renderrgr�outboxr)rrrks  r5r+r+ks���
�z�<�(�(�
��
G�
�
�	
�

�}���� �"�"�J�&�J��'�5�J��D�x�5�D�|�D�H���~�J���H�N�'�5�J��L�H��!)�!1�J��/�H���D�K��L�L�L�L�Lr7c���tj}|jt_|jt_|jt_|j	t_t`t`
dS)z�
    Perform any global post-test teardown, such as restoring the original
    template renderer and restoring the email sending functions.
    N)rirkrqrrprrrortrsrvrrurrw)rks r5r,r,�sF��
�&�J�'�5�H���%�H�N�'�5�H��!�1�H�������r7F)�time_keeper�keepdb�	debug_sql�parallel�aliasesc��|�t��}t|��\}}	g}
|���D�]T\}}d}|D�]H}
t|
}|
�|||duf��|��|
}|�d|
z��5|j�||||jd�	dd�����ddd��n#1swxYwY|dkrot|��D]_}|�d|
z��5|j�t|dz��||�	��ddd��n#1swxYwY�`��t|
j�
t|j����J��V|	���D]:\}
}t|
j�
t|j���;|rtD]}
dt|
_�|
S)
zCreate the test databases.Nz  Creating '%s'�TEST�	SERIALIZET)�	verbosity�autoclobberrz�	serialize�z  Cloning '%s'��suffixr�rz)�NullTimeKeeper� get_unique_databases_and_mirrors�valuesr�append�timed�creation�create_test_db�
settings_dictrR�range�
clone_test_dbrI�set_as_test_mirror�items�force_debug_cursor)r��interactiveryrzr{r|r}�kwargs�test_databases�mirrored_aliases�	old_names�db_name�first_alias�alias�
connection�index�mirror_aliass                 r5r*r*�s�����$�&�&��'G��'P�'P�$�N�$��I�*�1�1�3�3�g�g�������	g�	g�E�$�U�+�J����j�'�;�$�3F�G�H�H�H��"�#�� �&�&�'8�5�'@�A�A����'�6�6�"+�(3�O�%�",�":�6�"B�"F�"F�{�TX�"Y�"Y�	7�����������������������a�<�<�!&�x������(�.�.�/?�%�/G�H�H���&�/�=�=�'*�5�1�9�~�~�*3�'-�>�������������������������E�"�+�>�>�{�;�?W�?e�f�f�f�f�1	g�6 0�5�5�7�7�5�5���|��E��#�6�6���%�3�	5�	5�	5�	5��9� �	9�	9�E�48�K���1�1��s$�	?C�C�C�.E	�E
�E
c�&�g}t��}i}|D]p\}\}}t��}|D]+}	|�|�|	g�����,|�|��st	d|z���|||<�q|r�d}
g}|D]m\}\}
}||�|��r1|�|��|�||
|ff��d}
�T|�||
|ff���n|
st	d���|}|��|S)zp
    Reorder test_databases into an order that honors the dependencies
    described in TEST[DEPENDENCIES].
    zHCircular dependency: databases %r depend on each other, but are aliases.FTz)Circular dependency in TEST[DEPENDENCIES])rZ�updaterR�
isdisjointr�issubsetr�)r��dependencies�ordered_test_databases�resolved_databases�dependencies_map�sig�_r}�all_depsr��changed�deferred�	signaturer�s              r5�dependency_orderedr��s���
 ��������,�	)�	)���\�a���5�5���	9�	9�E��O�O�L�,�,�U�B�7�7�8�8�8�8��"�"�7�+�+�	�&�#�%,�-���
�!)�����
�"�����.<�	A�	A�)�I�)����	�*�3�3�4F�G�G�
A�"�)�)�'�2�2�2�&�-�-�y�7�G�:L�.M�N�N�N��������W�g�,>� ?�@�@�@�@��	T�&�'R�S�S�S�!���"� "�!r7c��|�t}i}i}i}ttj���}tD�]	}t|}|jd}|dr|d||<�1||vr�|�|j���|jdgf��}|tkr|d�d|��n|d�|��d|vr|d||<��|tkr<|j���|kr|�dtg��||<��tt|���|����}||fS)a�
    Figure out which databases actually need to be created.

    Deduplicate entries in DATABASES that correspond the same database or are
    configured as test mirrors.

    Return two values:
    - test_databases: ordered mapping of signatures to (name, list of aliases)
                      where all aliases share the same underlying database.
    - mirrored_aliases: mapping of mirror aliases to original aliases.
    Nr�MIRROR�NAMEr�r�DEPENDENCIES)rrr��test_db_signaturer��
setdefault�insertr�rR�dictr�r�)	r}r�r�r��default_sigr�r��
test_settings�items	         r5r�r��s����������N��L��.�/�8�J�J�L�L�K��`�`�� ��'�
�"�0��8�
���"�	`�&3�H�&=��U�#�#�
�g�
�
�"�,�,��#�5�5�7�7��)�&�1�2�6���D��(�(�(��Q����q�%�(�(�(�(��Q����u�%�%�%���.�.�&3�N�&C��U�#�#��,�,�,��1D�1V�1V�1X�1X�\g�1g�1g�*7�*;�*;�N�M]�L^�*_�*_�L��'���,�^�-A�-A�-C�-C�\�R�R�S�S�N��+�+�+r7c���|D]i\}}}|ra|dkr?t|��D]/}|j�t|dz��||����0|j�|||���jdS)z%Destroy all the non-mirror databases.r�r�N)r�r��destroy_test_dbrI)�
old_configr�r|rzr��old_name�destroyr�s        r5�teardown_databasesr�.s���)3�	M�	M�%�
�H�g��	M��!�|�|�"�8�_�_���E��'�7�7�"�5�1�9�~�~�"+�%�8�����

��/�/��)�V�L�L�L��	M�	Mr7c��|p|j}|�d��}t|��dkrd�|dd���}nd}t	|ii|d��}t||d��S)N�.r����)�TEST_RUNNER�split�len�join�
__import__�getattr)r�test_runner_class�	test_path�test_module_name�test_modules     r5r!r!<s���)�A�X�-A��!�'�'��,�,�I�
�9�~�~�����8�8�I�c�r�c�N�3�3������-�r�2�y��}�E�E�K��;�	�"�
�.�.�.r7c�D�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�ZdS)�TestContextDecoratora�
    A base class that can either be used as a context manager during tests
    or as a test function or unittest.TestCase subclass decorator to perform
    temporary alterations.

    `attr_name`: attribute assigned the return value of enable() if used as
                 a class decorator.

    `kwarg_name`: keyword argument passing the return value of enable() if
                  used as a function decorator.
    Nc�"�||_||_dSr1)�	attr_name�
kwarg_name)r4r�r�s   r5r6zTestContextDecorator.__init__Ts��"���$����r7c��t�r1��NotImplementedErrorr:s r5�enablezTestContextDecorator.enableX���!�!r7c��t�r1r�r:s r5�disablezTestContextDecorator.disable[r�r7c�*�|���Sr1)r�r:s r5�	__enter__zTestContextDecorator.__enter__^s���{�{�}�}�r7c�.�|���dSr1)r��r4�exc_type�	exc_value�	tracebacks    r5�__exit__zTestContextDecorator.__exit__as���������r7c�z���t|t��r|j���fd�}||_|Std���)Nc�������}|��j���jrt	|�j|���|��dSr1)r��
addCleanupr�r��setattr)�
inner_selfrc�decorated_setUpr4s  ��r5�setUpz2TestContextDecorator.decorate_class.<locals>.setUphs[����+�+�-�-���%�%�d�l�3�3�3��>�A��J����@�@�@���
�+�+�+�+�+r7z1Can only decorate subclasses of unittest.TestCase)�
issubclassrr��	TypeError)r4�clsr�r�s`  @r5�decorate_classz#TestContextDecorator.decorate_classdsX�����c�8�$�$�	�!�i�O�
,�
,�
,�
,�
,�
,��C�I��J��K�L�L�Lr7c����tj���rt�����fd���}nt�����fd���}|S)Nc��~�K��5}�jr
||�j<�|i|���d{V��cddd��S#1swxYwYdSr1�r���argsr�rc�funcr4s   ��r5�innerz5TestContextDecorator.decorate_callable.<locals>.innerws�������7�W���:�29��t��/�!%��t�!6�v�!6�!6�6�6�6�6�6�6�7�7�7�7�7�7�7�7�7�7�7�7����7�7�7�7�7�7s�2�6�6c�n���5}�jr
||�j<�|i|��cddd��S#1swxYwYdSr1r�r�s   ��r5r�z5TestContextDecorator.decorate_callable.<locals>.inner~s�����1�W���:�29��t��/��4��0��0�0�1�1�1�1�1�1�1�1�1�1�1�1����1�1�1�1�1�1s�*�.�.)�asyncio�iscoroutinefunctionr)r4r�r�s`` r5�decorate_callablez&TestContextDecorator.decorate_callabless������&�t�,�,�	1��4�[�[�
7�
7�
7�
7�
7��[�
7�
7��4�[�[�
1�
1�
1�
1�
1��[�
1�
�r7c���t|t��r|�|��St|��r|�|��Stdt|��z���)Nz!Cannot decorate object of type %s)rH�typer��callabler�r�)r4�	decorateds  r5�__call__zTestContextDecorator.__call__�sf���i��&�&�	5��&�&�y�1�1�1�
�i�
 �
 �	5��)�)�)�4�4�4��;�d�9�o�o�M�N�N�Nr7)NN)rBrCrDr]r6r�r�r�r�r�r�r�rEr7r5r�r�Hs�������
�
�%�%�%�%�"�"�"�"�"�"�������
M�
M�
M����&O�O�O�O�Or7r�c�>��eZdZdZdZ�fd�Zd�Zd�Zd�Zd�Z	�xZ
S)r&a4
    Act as either a decorator or a context manager. If it's a decorator, take a
    function and return a wrapped function. If it's a contextmanager, use it
    with the ``with`` statement. In either event, entering/exiting are called
    before and after, respectively, the function/block is executed.
    Nc�V��||_t�����dSr1)�optionsrKr6�r4r�rOs  �r5r6zoverride_settings.__init__�s&������
���������r7c�\�d|jvrC	tj|jd��n"#t$rtj���wxYwttj��}|j���D]\}}t|||���tj|_
|t_|j���D]_\}}	tjtjj
||d����.#t$r%}||_|���Yd}~�Xd}~wwxYwdS)N�INSTALLED_APPST�ra�setting�value�enter)r�r
�set_installed_apps�	Exception�unset_installed_appsrr�_wrappedr�r��wrappedrrdrO�enable_exceptionr�)r4�overriderM�	new_value�excs     r5r�zoverride_settings.enable�sX���t�|�+�+�
��'���5E�(F�G�G�G�G���
�
�
��)�+�+�+��
����&�h�&7�8�8��"�l�0�0�2�2�	.�	.�N�C���H�c�9�-�-�-�-��(���$���"�l�0�0�2�2�	�	�N�C��
��$�#�,�6��y���������
�
�
�(+��%����������������
����
	�	s!�+�A
�'C:�:
D)�D$�$D)c��d|jvrtj��|jt_|`g}|jD]T}t
t|d��}tjtjj	||d���}|�
|���U|j�|j}d|_|�|D]\}}t|t��r|��dS)NrFr)r�r
rr	rrr�r�send_robustrO�extendr
rHr)r4�	responsesrMr�responses_for_settingr
r��responses        r5r�zoverride_settings.disable�s����t�|�+�+��%�'�'�'� �L����L��	��<�	4�	4�C���#�t�4�4�I�$3�$?��(�2��9�E�%�%�%�!�
���2�3�3�3�3�� �,��'�C�$(�D�!��I�$�	�	�K�A�x��(�I�.�.�
���
�	�	r7c�Z�|j�|j|_dSi|j�|j�|_dSr1)�_overridden_settingsr��r4�	test_funcs  r5�save_optionszoverride_settings.save_options�s@���)�1�-1�\�I�*�*�*�.��0�.��,�.�I�*�*�*r7c�z�ddlm}t||��std���|�|��|S)Nr)�SimpleTestCasezPOnly subclasses of Django SimpleTestCase can be decorated with override_settings)�django.testrr��
ValueErrorr)r4r�rs   r5r�z override_settings.decorate_class�sX��.�.�.�.�.�.��#�~�.�.�	*��)�*�*�
*�	
���#�����
r7)rBrCrDr]r
r6r�r�rr�r^r_s@r5r&r&�s��������������������0���*���������r7r&c�2��eZdZdZ�fd�Zd�Z�fd�Z�xZS)r%z�
    Like override_settings, but makes it possible to append, prepend, or remove
    items instead of redefining the entire list.
    c����|r|rJ�|d|_n*|rJ�t|�����|_tt|�����dSr=)�
operations�listr�rKr&r6)r4r�r�rOs   �r5r6zmodify_settings.__init__�sg����	3�����"�1�g�D�O�O��O�O�O�"�6�<�<�>�>�2�2�D�O�
���&�&�/�/�1�1�1�1�1r7c�r�|j�|j|_dSt|j��|jz|_dSr1)�_modified_settingsrr rs  r5rzmodify_settings.save_options�sF���'�/�+/�?�I�(�(�(�,0��,�,.�,.�04��,@�I�(�(�(r7c	�����i|_|jD]�\}}	|j|�n3#t$r&tt	t
|g�����YnwxYw|���D]s\}�t�t��r�g�|dkr��fd��D��z��5|dkr�fd��D���z��M|dkr�fd��D����btd|z����|j|<��t�����dS)Nr�c���g|]}|�v�|��	SrErE�rWr�rs  �r5�
<listcomp>z*modify_settings.enable.<locals>.<listcomp>s#���$Q�$Q�$Q�d�t�5�?P�?P�T�?P�?P�?Pr7�prependc���g|]}|�v�|��	SrErEr%s  �r5r&z*modify_settings.enable.<locals>.<listcomp>�#���I�I�I�d�t�5�7H�7H�T�7H�7H�7Hr7�removec���g|]}|�v�|��	SrErE)rWr�r�s  �r5r&z*modify_settings.enable.<locals>.<listcomp>r)r7zUnsupported action: %s)r�rrJr r�rr�rHrIrrKr�)r4�namer�actionr�rrOs    @@�r5r�zmodify_settings.enable�sc�������� $��	'�	'��D�*�
:���T�*�����
:�
:�
:��W�X�t�R�8�8�9�9����
:����!+�!1�!1�!3�!3�
H�
H�
����e�S�)�)�$�"�G�E��X�%�%�!�$Q�$Q�$Q�$Q�e�$Q�$Q�$Q�Q�E�E��y�(�(�I�I�I�I�e�I�I�I�E�Q�E�E��x�'�'�I�I�I�I�e�I�I�I�E�E�$�%=��%F�G�G�G�!&�D�L����
���������s�
&�-A�A)rBrCrDr]r6rr�r^r_s@r5r%r%�sm���������2�2�2�2�2�@�@�@���������r7r%c�0��eZdZdZd�fd�	Zd�Zd�Z�xZS)r'z�
    Act as a decorator. Override list of registered system checks.
    Useful when you override `INSTALLED_APPS`, e.g. if you exclude `auth` app,
    you also need to exclude its system checks.
    Nc�~��ddlm}||_||_||_t	�����dS)Nr)�registry)�django.core.checks.registryr0�
new_checks�deployment_checksrKr6)r4r2r3r0rOs    �r5r6zoverride_system_checks.__init__sG���8�8�8�8�8�8� ��
�$���!2���
���������r7c	�r�|jj|_t��|j_|jD]$}|jj|gt
|dd���R��%|jj|_|j�Gt��|j_|jD])}|jj|gt
|dd���Rddi��(dSdS)N�tagsrE�deployT)	r0�registered_checks�
old_checksrZr2�registerr�r3�old_deployment_checks)r4�checks  r5r�zoverride_system_checks.enables����-�9���*-�%�%��
�'��_�	G�	G�E�"�D�M�"�5�F�7�5�&�"�+E�+E�F�F�F�F�F�%)�]�%D��"��!�-�.1�e�e�D�M�+��/�
X�
X��&��
�&�u�W�w�u�f�b�/I�/I�W�W�W�RV�W�W�W�W�.�-�
X�
Xr7c�J�|j|j_|j|j_dSr1)r8r0r7r:r3r:s r5r�zoverride_system_checks.disable$s!��*.�/��
�'�*.�*D��
�'�'�'r7r1�rBrCrDr]r6r�r�r^r_s@r5r'r'so���������
������	X�	X�	X�E�E�E�E�E�E�Er7r'c������	�
���tjd����fd��d��	d��
�	�fd��d�����
�fd��d�}|����d	d
��}|����d	d
��}|�d��sd}||z}||z}|t|����}|t|����}�||��S)
al
    Try to do a 'xml-comparison' of want and got. Plain string comparison
    doesn't always work because, for example, attribute ordering should not be
    important. Ignore comment nodes, processing instructions, document type
    node, and leading and trailing whitespaces.

    Based on https://github.com/lxml/lxml/blob/master/src/lxml/doctestcompare.py
    z[ \t\n][ \t\n]+c�0����d|��S)N� )�sub)�v�_norm_whitespace_res �r5�norm_whitespacez$compare_xml.<locals>.norm_whitespace4s���"�&�&�s�A�.�.�.r7c�J�d�d�|jD����S)N�c3�NK�|] }|jtjk�|jV��!dSr1)�nodeTyper�	TEXT_NODE�data�rW�cs  r5rYz2compare_xml.<locals>.child_text.<locals>.<genexpr>8s>����8�8�!��*���6�6��v�6�6�6�6�8�8r7)r��
childNodes��elements r5�
child_textzcompare_xml.<locals>.child_text7s6���w�w�8�8�w�'9�8�8�8�8�8�	8r7c�$�d�|jD��S)Nc�<�g|]}|jtjk�|��SrE)rHr�ELEMENT_NODErKs  r5r&z1compare_xml.<locals>.children.<locals>.<listcomp><s1��4�4�4�a��:��!2�2�2��2�2�2r7)rMrNs r5�childrenzcompare_xml.<locals>.children;s%��4�4�7�-�4�4�4�	4r7c�,����|����Sr1rE)rOrPrDs ��r5�norm_child_textz$compare_xml.<locals>.norm_child_text?s�����z�z�'�2�2�3�3�3r7c�N�t|j�����Sr1)r��
attributesr�rNs r5�
attrs_dictzcompare_xml.<locals>.attrs_dictBs���G�&�,�,�.�.�/�/�/r7c�R��|j|jkrdS�|���|��krdS�|���|��krdS�|��}�|��}t|��t|��krdSt�fd�t||��D����S)NFc3�6�K�|]\}}�||��V��dSr1rE)rW�want�got�
check_elements   �r5rYz5compare_xml.<locals>.check_element.<locals>.<genexpr>Ps3�����^�^�	��c�=�=��s�+�+�^�^�^�^�^�^r7)�tagNamer��all�zip)�want_element�got_element�
want_children�got_childrenrYr^rTrVs    ����r5r^z"compare_xml.<locals>.check_elementEs������;�#6�6�6��5��?�<�(�(�O�O�K�,H�,H�H�H��5��:�l�#�#�z�z�+�'>�'>�>�>��5� ���.�.�
��x��,�,���}����\�!2�!2�2�2��5��^�^�^�^�S��P\�=]�=]�^�^�^�^�^�^r7c�v�|jD]0}|jtjtjtjfvr|cS�1dSr1)rMrHr�COMMENT_NODE�DOCUMENT_TYPE_NODE�PROCESSING_INSTRUCTION_NODE)�document�nodes  r5�
first_nodezcompare_xml.<locals>.first_nodeRsT���'�	�	�D��}��!��'��0�%���
�����	�	r7z\n�
z<?xmlz<root>%s</root>)�re�compile�strip�replace�
startswithr)
r\r]rl�wrapper�	want_root�got_rootrCrYr^rPrTrVrDs
      @@@@@@@r5�compare_xmlrv)sj����������*�%7�8�8��/�/�/�/�/�8�8�8�4�4�4�4�4�4�4�4�4�0�0�0�_�_�_�_�_�_�_�_�����:�:�<�<����t�,�,�D�

�)�)�+�+�
�
�e�T�
*�
*�C��?�?�7�#�#��#����~����m���
�;�t�,�,�-�-�I��z�+�c�*�*�+�+�H��=��H�-�-�-r7c�L�eZdZdZd�Zd�Zd�Zd�Zed���Z	d�Z
d�Zd	S)
r"zU
    Context manager that captures queries executed by the specified connection.
    c��||_dSr1)r�)r4r�s  r5r6zCaptureQueriesContext.__init__ps
��$����r7c�*�t|j��Sr1)�iter�captured_queriesr:s r5�__iter__zCaptureQueriesContext.__iter__ss���D�)�*�*�*r7c��|j|Sr1)r{)r4r�s  r5rLz!CaptureQueriesContext.__getitem__vs���$�U�+�+r7c�*�t|j��Sr1)r�r{r:s r5�__len__zCaptureQueriesContext.__len__ys���4�(�)�)�)r7c�>�|jj|j|j�Sr1)r��queries�initial_queries�
final_queriesr:s r5r{z&CaptureQueriesContext.captured_queries|s����&�t�';�D�<N�'N�O�Or7c���|jj|_d|j_|j���t|jj��|_d|_tjt��|S)NT)
r�r��ensure_connectionr��queries_logr�r�r�
disconnectrr:s r5r�zCaptureQueriesContext.__enter__�sb��"&�/�"D���-1���*�	
��)�)�+�+�+�"�4�?�#>�?�?���!����"�=�1�1�1��r7c��|j|j_tjt��|�dSt|jj��|_dSr1)r�r�r�connectrr�r�r�r�s    r5r�zCaptureQueriesContext.__exit__�sF��-1�-D���*���
�.�.�.����F� ���!<�=�=����r7N)rBrCrDr]r6r|rLr�propertyr{r�r�rEr7r5r"r"ls���������%�%�%�+�+�+�,�,�,�*�*�*��P�P��X�P�	�	�	�>�>�>�>�>r7r"c�*��eZdZ�fd�Zd�Zd�Z�xZS)r#c���||_d|jvs	d|jvrtj|_ntj|_t�����dS)N�message�module)�
ignore_kwargs�warnings�filterwarnings�filter_func�simplefilterrKr6r�s  �r5r6zignore_warnings.__init__�s[���#�����*�*�*�h�$�:L�.L�.L�'�6�D���'�4�D��
���������r7c��tj��|_|j���|jdi|j��dS)N�ignore)r�)r��catch_warningsr�r�r�r:s r5r�zignore_warnings.enable�sJ��&�5�7�7�����%�%�'�'�'����8�8�T�%7�8�8�8�8�8r7c�F�|jjtj���dSr1)r�r��sys�exc_infor:s r5r�zignore_warnings.disable�s!��$���$�c�l�n�n�5�5�5�5r7)rBrCrDr6r�r�r^r_s@r5r#r#�sV������������9�9�9�
6�6�6�6�6�6�6r7r#z|This test relies on the ability to run a program in an arbitrary time zone, but your operating system isn't able to do that.c'�K�tjdd�}tj�|��	dV�|t_dS#|t_wxYw)z5Context manager to temporarily add paths to sys.path.N)r��pathr)�paths�_orig_sys_paths  r5�extend_sys_pathr��sW�����X�a�a�a�[�N��H�O�O�E����"�
����!������>���!�!�!�!s�A	�	Ac#�K�|���	dV�|���dS#|���wxYw)z?Clear the cache of an LRU cache object on entering and exiting.N)�cache_clear)�lru_cache_objects r5r r �sY����� � �"�"�"�'�
�����$�$�&�&�&�&�&���$�$�&�&�&�&���s	�2�Ac#�
K�tt|��}tt|t����	tt|��V�tt||��dS#tt||��wxYw)aReturn a context manager used by captured_stdout/stdin/stderr
    that temporarily replaces the sys stream *stream_name* with a StringIO.

    Note: This function and the following ``captured_std*`` are copied
          from CPython's ``test.support`` module.N)r�r�r�r)�stream_name�orig_stdouts  r5�captured_outputr��sx�����#�{�+�+�K��C��h�j�j�)�)�)�/��c�;�'�'�'�'�'���[�+�.�.�.�.�.����[�+�.�.�.�.���s�A*�*Bc� �td��S)z�Capture the output of sys.stdout:

       with captured_stdout() as stdout:
           print("hello")
       self.assertEqual(stdout.getvalue(), "hello
")
    �stdout�r�rEr7r5�captured_stdoutr������8�$�$�$r7c� �td��S)z�Capture the output of sys.stderr:

       with captured_stderr() as stderr:
           print("hello", file=sys.stderr)
       self.assertEqual(stderr.getvalue(), "hello
")
    �stderrr�rEr7r5�captured_stderrr��r�r7c� �td��S)aCapture the input to sys.stdin:

       with captured_stdin() as stdin:
           stdin.write('hello
')
           stdin.seek(0)
           # call test code that consumes from sys.stdin
           captured = input()
       self.assertEqual(captured, "hello")
    �stdinr�rEr7r5�captured_stdinr��s���7�#�#�#r7c#��K�tj}�fd�t_	dV�|t_dS#|t_wxYw)aM
    Context manager to temporarily freeze time.time(). This temporarily
    modifies the time function of the time module. Modules which import the
    time function directly (e.g. `from time import time`) won't be affected
    This isn't meant as a public API, but helps reduce some repetitive code in
    Django's test suite.
    c����Sr1rE)�ts�r5�<lambda>zfreeze_time.<locals>.<lambda>s����r7N)�time)r��
_real_times` r5�freeze_timer��sI�������J��	�	�	�D�I��
������	�	�	��J��	����s	�2�Ac��ttdud��|��}tddd�ddddid�g�	��|��S)
z�
    Decorator to enable a Jinja2 template engine in addition to the regular
    Django template engine for a test or skip it if Jinja2 isn't available.
    Nzthis test requires jinja2z/django.template.backends.django.DjangoTemplatesT)�BACKEND�APP_DIRSz&django.template.backends.jinja2.Jinja2�keep_trailing_newline)r�r��OPTIONS)�	TEMPLATES)r	�jinja2r&)rs r5�require_jinja2r�s}��
D��v��~�'B�C�C�I�N�N�I���D��)�)�<��+�T�2���(����	���r7c�.��eZdZdZ�fd�Zd�Zd�Z�xZS)�override_script_prefixzEDecorator or context manager to temporary override the script prefix.c�V��||_t�����dSr1)�prefixrKr6)r4r�rOs  �r5r6zoverride_script_prefix.__init__s&������
���������r7c�T�t��|_t|j��dSr1)r�
old_prefixrr�r:s r5r�zoverride_script_prefix.enables%��+�-�-����$�+�&�&�&�&�&r7c�.�t|j��dSr1)rr�r:s r5r�zoverride_script_prefix.disable!s���$�/�*�*�*�*�*r7r=r_s@r5r�r�s\�������O�O������'�'�'�+�+�+�+�+�+�+r7r�c��eZdZdZd�Zd�ZdS)�LoggingCaptureMixinzn
    Capture the output from the 'django' logger and store it on the class's
    logger_output attribute.
    c���tjd��|_|jjdj|_t
��|_|j|jjd_dS)N�djangor)�logging�	getLogger�logger�handlers�stream�
old_streamr�
logger_outputr:s r5r�zLoggingCaptureMixin.setUp*sO���'��1�1����+�.�q�1�8���%�Z�Z���)-�);����Q��&�&�&r7c�>�|j|jjd_dSr=)r�r�r�r�r:s r5�tearDownzLoggingCaptureMixin.tearDown0s��)-�����Q��&�&�&r7N)rBrCrDr]r�r�rEr7r5r�r�%s<��������<�<�<�9�9�9�9�9r7r�c�.��eZdZdZ�fd�Zd�Zd�Z�xZS)r$a
    Act as either a decorator or a context manager to register models defined
    in its wrapped context to an isolated registry.

    The list of installed apps the isolated registry should contain must be
    passed as arguments.

    Two optional keyword arguments can be specified:

    `attr_name`: attribute assigned the isolated registry if used as a class
                 decorator.

    `kwarg_name`: keyword argument passing the isolated registry if used as a
                  function decorator.
    c�H��||_t��jdi|��dS)NrE)�installed_appsrKr6)r4r�r�rOs   �r5r6zisolate_apps.__init__Ds.���,��������"�"�6�"�"�"�"�"r7c�|�tj|_t|j��}ttd|��|S�N�default_apps)rr��old_appsrr�r�)r4r
s  r5r�zisolate_apps.enableHs3���,��
��D�'�(�(������.�.�.��r7c�<�ttd|j��dSr�)r�rr�r:s r5r�zisolate_apps.disableNs�������7�7�7�7�7r7r=r_s@r5r$r$4s`���������#�#�#�#�#����8�8�8�8�8�8�8r7r$c�0�eZdZd�Zed���Zd�ZdS)�
TimeKeeperc�B�tjt��|_dSr1)�collections�defaultdictr �recordsr:s r5r6zTimeKeeper.__init__Ss��"�.�t�4�4����r7c#�6K�|j|tj��}	dV�tj��|z
}|j|�|��dS#tj��|z
}|j|�|��wxYwr1)r�r��perf_counterr�)r4r,�
start_time�end_times    r5r�zTimeKeeper.timedVs�������T����&�(�(�
�	0��E�E�E��(�*�*�Z�7�H��L���%�%�h�/�/�/�/�/���(�*�*�Z�7�H��L���%�%�h�/�/�/�/���s�A � 8Bc��|j���D]=\}}|D]5}d||fz}tj�|t
jz���6�>dS)Nz
%s took %.3fs)r�r�r�r��write�os�linesep)r4r,�	end_times�record_time�records     r5�
print_resultszTimeKeeper.print_results`sp��#�|�1�1�3�3�	6�	6�O�D�)�(�
6�
6��(�D�+�+>�>���
� � ��"�*�!4�5�5�5�5�
6�	6�	6r7N)rBrCrDr6rr�r�rEr7r5r�r�RsM������5�5�5��0�0��^�0�6�6�6�6�6r7r�c�*�eZdZed���Zd�ZdS)r�c#�K�dV�dSr1rE)r4r,s  r5r�zNullTimeKeeper.timedhs����
�����r7c��dSr1rEr:s r5r�zNullTimeKeeper.print_resultsls���r7N)rBrCrDrr�r�rEr7r5r�r�gs<����������^��
�
�
�
�
r7r�c����fd�}|S)z0Decorator to add tags to a test class or method.c���t|d��r |j����|_nt|dt	�����|S)Nr5)rmr5�unionr�rZ)�objr5s �r5�	decoratorztag.<locals>.decoratorrsI����3����	,��x�~�~�d�+�+�C�H�H��C���T���+�+�+��
r7rE)r5r�s` r5r(r(ps$���������r7)�lookup_namec'�K�	|D]}|�||���dV�|D]}|�||���dS#|D]}|�||���wxYw)z�
    Context manager to temporarily register lookups on a model field using
    lookup_name (or the lookup's lookup_name if not provided).
    N)�register_lookup�_unregister_lookup)�fieldr��lookups�lookups    r5r�r�{s�����:��	7�	7�F��!�!�&�+�6�6�6�6�
�����	:�	:�F��$�$�V�[�9�9�9�9�	:�	:��g�	:�	:�F��$�$�V�[�9�9�9�9�	:���s�A�Ar1)rF)^r�r�r�r�rnr�r�r��
contextlibr�	functoolsr�ior�	itertoolsr�typesr�unittestrr	r
�xml.dom.minidomrr�django.appsr
�django.apps.registryr�django.confrr�django.corer�django.core.exceptionsr�django.core.signalsr�	django.dbrrr�django.db.models.optionsr�django.templater�django.test.signalsrr�django.urlsrr�django.utils.translationrr��ImportError�__all__rm�
TZ_SUPPORTrr rrgrir+r,r*r�r�r�r!r�r&r%r'rvr"r#r)r�r r�r�r�r�r�r�r�r�r$r�r�r(r�rEr7r5�<module>rse��������������	�	�	�	�	�	�	�	�
�
�
�
���������%�%�%�%�%�%�������������������!�!�!�!�!�!�1�1�1�1�1�1�1�1�1�1�-�-�-�-�-�-�-�-�������%�%�%�%�%�%�4�4�4�4�4�4�4�4�������7�7�7�7�7�7�/�/�/�/�/�/�B�B�B�B�B�B�B�B�B�B�,�,�,�,�,�,�$�$�$�$�$�$�B�B�B�B�B�B�B�B�<�<�<�<�<�<�<�<�/�/�/�/�/�/���M�M�M�M������
�F�F�F��������W�T�7�
#�
#�
�	S�	S�	S�	S�	S�	S�	S�	S�V�V�V�V�V�$�V�V�V�D)�)�)�	�	�	�	�	�	�	�	�!�!�!�!�H
�
�
� <@��Y^�ij� �/�/�/�/�/�d'"�'"�'"�T0,�0,�0,�0,�fM�M�M�M�	/�	/�	/�	/�CO�CO�CO�CO�CO�CO�CO�CO�LK�K�K�K�K�,�K�K�K�\-�-�-�-�-�'�-�-�-�`E�E�E�E�E�1�E�E�E�:@.�@.�@.�F$>�$>�$>�$>�$>�$>�$>�$>�N6�6�6�6�6�*�6�6�6�.!�j��B�����"�"���"��'�'���'��/�/���/�%�%�%�%�%�%�
$�
$�
$��
�
���
� 
�
�
� +�+�+�+�+�1�+�+�+�9�9�9�9�9�9�9�9�8�8�8�8�8�'�8�8�8�<6�6�6�6�6�6�6�6�*
�
�
�
�
�
�
�
�����15�:�:�:�:���:�:�:s�$B)�)B3�2B3

Youez - 2016 - github.com/yon3zu
LinuXploit