U
    aq                     @   s  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 d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZmZ d dlmZ d dlm Z  d dl!m"Z" d dl#m$Z$m%Z%m&Z& d dl'm(Z( d dl)m*Z* d dl+m,Z,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2 zd dl3Z3W n e4k
rR   dZ3Y nX dZ5e6edZ7G dd dZ8G dd de9Z:dd Z;G dd dZ<dXdd Z=d!d" Z>dYd$d%Z?d&d' Z@dZd(d)ZAd[d*d+ZBd\d,d-ZCG d.d/ d/ZDG d0d1 d1eDZEG d2d3 d3eEZFG d4d5 d5eDZGd6d7 ZHG d8d9 d9ZIG d:d; d;eDZJee7d<ZKed=d> ZLed?d@ ZMedAdB ZNdCdD ZOdEdF ZPdGdH ZQedIdJ ZRdKdL ZSG dMdN dNeDZTG dOdP dPZUG dQdR dReDZVdSdT ZWeddUdVdWZXdS )]    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modify_settingsoverride_settingsrequires_tz_supportsetup_test_environmentteardown_test_environmenttzsetc                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
r      c                 C   s   || _ || _d S N)valplaces)selfr*   r+    r-   /home/adriano.carvalho/ftp/files/BrinquedotecaVirtual/brinquedotecavirtual/venv/lib/python3.8/site-packages/django/test/utils.py__init__,   s    zApproximate.__init__c                 C   s
   t | jS r)   )reprr*   r,   r-   r-   r.   __repr__0   s    zApproximate.__repr__c                 C   s$   | j |kp"tt| j | | jdkS Nr   )r*   roundabsr+   )r,   otherr-   r-   r.   __eq__3   s    zApproximate.__eq__N)r(   )__name__
__module____qualname__r/   r2   r7   r-   r-   r-   r.   r   +   s   
r   c                       s:   e Zd ZdZ fddZdddZdd Zd	d
 Z  ZS )r   zp
    A wrapper that provides direct key access to context items contained
    in a list of context objects.
    c                    sB   t |tr2| D ]}||kr||   S qt|nt |S d S r)   )
isinstancestrKeyErrorsuper__getitem__)r,   key
subcontext	__class__r-   r.   r?   <   s    

zContextList.__getitem__Nc                 C   s*   z|  |W S  tk
r$   | Y S X d S r)   )r?   r=   )r,   r@   defaultr-   r-   r.   getE   s    zContextList.getc                 C   s(   z| |  W n t k
r"   Y dS X dS )NFT)r=   )r,   r@   r-   r-   r.   __contains__K   s
    zContextList.__contains__c                 C   s   t tdd | D S )z0
        Flattened keys of subcontexts.
        c                 s   s   | ]}|D ]
}|V  q
qd S r)   r-   ).0rA   dr-   r-   r.   	<genexpr>V   s       z#ContextList.keys.<locals>.<genexpr>)setr   from_iterabler1   r-   r-   r.   keysR   s    zContextList.keys)N)	r8   r9   r:   __doc__r?   rE   rF   rL   __classcell__r-   r-   rB   r.   r   7   s
   	
r   c                 C   s   t j| | |d | j|S )zt
    An instrumented Template render method, providing a signal that can be
    intercepted by the test Client.
    )sendertemplatecontext)r   sendZnodelistrender)r,   rQ   r-   r-   r.   instrumented_test_renderY   s    rT   c                   @   s   e Zd ZdS )
_TestStateN)r8   r9   r:   r-   r-   r-   r.   rU   b   s   rU   c                 C   sz   t tdrtd| dkr tj} t }|t_tj|_tjdt_tj|_	| t_tj
|_dt_
tj|_tt_g t_t  dS )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)rW   )hasattrrU   RuntimeErrorr   DEBUGr   rV   ALLOWED_HOSTSallowed_hostsdebugEMAIL_BACKENDemail_backendr   _rendertemplate_renderrT   r   outboxr   )r]   rV   r-   r-   r.   r%   f   s$    
r%   c                  C   s2   t j} | jt_| jt_| jt_| j	t
_t `t`dS )z
    Perform any global post-test teardown, such as restoring the original
    template renderer and restoring the email sending functions.
    N)rU   rV   r\   r   r[   r]   rZ   r_   r^   ra   r   r`   r   rb   )rV   r-   r-   r.   r&      s    r&   Fc              
   K   s  t |\}}g }	| D ]\}
}d}|D ]}t| }|	||
|dkf |dkr|}|jj| | ||jdi ddd |dkrt|D ]}|jj	t
|d | |d qq(t| jt| j q(q| D ]\}}t| jt| j q|r
tD ]}dt| _q|	S )zCreate the test databases.NTESTZ	SERIALIZET)	verbosityZautoclobberkeepdb	serialize   suffixrd   re   ) get_unique_databases_and_mirrorsvaluesr   appendcreationZcreate_test_dbsettings_dictrE   rangeZclone_test_dbr<   Zset_as_test_mirroritemsforce_debug_cursor)rd   interactivere   Z	debug_sqlparallelaliaseskwargstest_databasesmirrored_aliasesZ	old_namesdb_nameZfirst_aliasalias
connectionindexZmirror_aliasr-   r-   r.   setup_databases   s>    


r|   c                 C   s   g }t  }i }| D ]L\}\}}t  }|D ]}	|||	g  q(||sVtd| |||< q| rd}
g }| D ]N\}\}}|| |r|| ||||ff d}
qp||||ff qp|
std|} q`|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])rJ   updaterE   
isdisjointr   issubsetrl   )rv   dependenciesZordered_test_databasesZresolved_databasesZdependencies_mapsig_rt   Zall_depsry   changeddeferred	signaturerx   r-   r-   r.   dependency_ordered   s6    


r   c           	      C   s   | dkrt } i }i }i }t t j }t D ]}t | }|jd }|d rV|d ||< q*|| kr*||j |jd t f}|d | d|kr|d ||< q*|tkr*|j |kr*|dtg||< q*t	t
| |}||fS )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.
    Nrc   ZMIRRORNAMErg   ZDEPENDENCIES)r   r   rm   Ztest_db_signaturern   
setdefaultrJ   addrE   dictr   rp   )	rt   rw   rv   r   Zdefault_sigry   rz   Ztest_settingsitemr-   r-   r.   rj      s.    
rj   c                 C   sX   | D ]N\}}}|r|dkrBt |D ]}|jjt|d ||d q"|j||| qdS )z%Destroy all the non-mirror databases.rg   rh   N)ro   rm   Zdestroy_test_dbr<   )Z
old_configrd   rs   re   rz   Zold_namedestroyr{   r-   r-   r.   teardown_databases  s    
r   c                 C   sX   |p| j }|d}t|dkr4d|d d }nd}t|i i |d }t||d S )N.rg   )ZTEST_RUNNERsplitlenjoin
__import__getattr)r   Ztest_runner_classZ	test_pathZtest_module_nameZtest_moduler-   r-   r.   r!   ,  s    

r!   c                   @   sR   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )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                 C   s   || _ || _d S r)   )	attr_name
kwarg_name)r,   r   r   r-   r-   r.   r/   D  s    zTestContextDecorator.__init__c                 C   s   t d S r)   NotImplementedErrorr1   r-   r-   r.   enableH  s    zTestContextDecorator.enablec                 C   s   t d S r)   r   r1   r-   r-   r.   disableK  s    zTestContextDecorator.disablec                 C   s   |   S r)   )r   r1   r-   r-   r.   	__enter__N  s    zTestContextDecorator.__enter__c                 C   s   |    d S r)   r   r,   exc_type	exc_value	tracebackr-   r-   r.   __exit__Q  s    zTestContextDecorator.__exit__c                    sN   t |trB|j |j fdd}fdd}||_||_|S tdd S )Nc                    sL     }jrt| j| z |  W n tk
rF      Y nX d S r)   )r   r   setattr	Exceptionr   )
inner_selfrQ   )decorated_setUpr,   r-   r.   setUpY  s    z2TestContextDecorator.decorate_class.<locals>.setUpc                    s    |     d S r)   r   )r   )decorated_tearDownr,   r-   r.   tearDownc  s    z5TestContextDecorator.decorate_class.<locals>.tearDownz1Can only decorate subclasses of unittest.TestCase)
issubclassr   r   r   	TypeError)r,   clsr   r   r-   )r   r   r,   r.   decorate_classT  s    

z#TestContextDecorator.decorate_classc                    s   t   fdd}|S )Nc               
      s6   (}j r||j <  | |W  5 Q R  S Q R X d S r)   )r   )argsru   rQ   funcr,   r-   r.   innerm  s    
z5TestContextDecorator.decorate_callable.<locals>.innerr   )r,   r   r   r-   r   r.   decorate_callablel  s    z&TestContextDecorator.decorate_callablec                 C   s:   t |tr| |S t|r&| |S tdt| d S )Nz!Cannot decorate object of type %s)r;   typer   callabler   r   )r,   Z	decoratedr-   r-   r.   __call__u  s
    


zTestContextDecorator.__call__)NN)r8   r9   r:   rM   r/   r   r   r   r   r   r   r   r-   r-   r-   r.   r   8  s   
	r   c                       sD   e Zd ZdZdZ fddZdd Zdd Zd	d
 Zdd Z	  Z
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                    s   || _ t   d S r)   )optionsr>   r/   r,   ru   rB   r-   r.   r/     s    zoverride_settings.__init__c                 C   s   d| j kr>zt| j d  W n tk
r<   t   Y nX ttj}| j  D ]\}}t	||| qRtj| _
|t_| j  D ]T\}}ztjtjj||dd W q tk
r } z|| _|   W 5 d }~X Y qX qd S )NINSTALLED_APPSTrO   ZsettingvalueZenter)r   r   Zset_installed_appsr   unset_installed_appsr   r   _wrappedrp   r   wrappedr   rR   rC   enable_exceptionr   )r,   overrider@   	new_valueexcr-   r-   r.   r     s,    

  
zoverride_settings.enablec                 C   s   d| j krt  | jt_| `g }| j D ]0}tt|d }tjtjj	||dd}|
| q(| jd k	rt| j}d | _||D ]\}}t|trx|qxd S )Nr   Fr   )r   r   r   r   r   r   r   r   Zsend_robustrC   extendr   r;   r   )r,   	responsesr@   r   Zresponses_for_settingr   r   responser-   r-   r.   r     s*    

  

zoverride_settings.disablec                 C   s&   |j d kr| j|_ n|j | j|_ d S r)   )Z_overridden_settingsr   r,   	test_funcr-   r-   r.   save_options  s
    

zoverride_settings.save_optionsc                 C   s,   ddl m} t||std| | |S )Nr   )SimpleTestCasezPOnly subclasses of Django SimpleTestCase can be decorated with override_settings)Zdjango.testr   r   
ValueErrorr   )r,   r   r   r-   r-   r.   r     s    

z override_settings.decorate_class)r8   r9   r:   rM   r   r/   r   r   r   r   rN   r-   r-   rB   r.   r#   }  s   
r#   c                       s4   e Zd ZdZ fddZdd Z fddZ  ZS )r"   z
    Like override_settings, but makes it possible to append, prepend, or remove
    items instead of redefining the entire list.
    c                    s@   |r|rt |d | _n|r t t| | _tt|   d S r3   )AssertionError
operationslistrp   r>   r#   r/   )r,   r   ru   rB   r-   r.   r/     s    zmodify_settings.__init__c                 C   s*   |j d kr| j|_ nt|j | j |_ d S r)   )Z_modified_settingsr   r   r   r-   r-   r.   r     s    

zmodify_settings.save_optionsc              	      s   i | _ | jD ]\}}z| j | W n$ tk
rF   ttt|g Y nX | D ]\} t trh g |dkrfdd D  qP|dkrfdd D  qP|dkrć fddD qPt	d| qP| j |< qt
   d S )	Nrl   c                    s   g | ]}| kr|qS r-   r-   rG   r   r   r-   r.   
<listcomp>  s      z*modify_settings.enable.<locals>.<listcomp>prependc                    s   g | ]}| kr|qS r-   r-   r   r   r-   r.   r     s      removec                    s   g | ]}| kr|qS r-   r-   r   )rp   r-   r.   r     s      zUnsupported action: %s)r   r   r=   r   r   r   rp   r;   r<   r   r>   r   )r,   namer   actionrB   )rp   r   r.   r     s$    
zmodify_settings.enable)r8   r9   r:   rM   r/   r   r   rN   r-   r-   rB   r.   r"     s   
r"   c                       s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )
override_system_checksz
    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                    s,   ddl m} || _|| _|| _t   d S )Nr   )registry)Zdjango.core.checks.registryr   
new_checksdeployment_checksr>   r/   )r,   r   r   r   rB   r-   r.   r/     s
    zoverride_system_checks.__init__c                 C   s   | j j| _t | j _| jD ]}| j j|ft|dd  q| j j| _| jd k	rt | j _| jD ]$}| j j|ft|ddddi q^d S )Ntagsr-   ZdeployT)	r   registered_checks
old_checksrJ   r   registerr   r   old_deployment_checks)r,   checkr-   r-   r.   r     s    






zoverride_system_checks.enablec                 C   s   | j | j_| j| j_d S r)   )r   r   r   r   r   r1   r-   r-   r.   r     s    
zoverride_system_checks.disable)Nr8   r9   r:   rM   r/   r   r   rN   r-   r-   rB   r.   r     s   r   c                    s   t d  fdddd dd fdd	d
d fdddd }|  dd} | dd}| dsd}||  } || }|t| }|t|}||S )aS  
    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, 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                    s     d| S )N )sub)v)_norm_whitespace_rer-   r.   norm_whitespace#  s    z$compare_xml.<locals>.norm_whitespacec                 S   s   d dd | jD S )N c                 s   s    | ]}|j tjkr|jV  qd S r)   )nodeTyper   Z	TEXT_NODEdatarG   cr-   r-   r.   rI   '  s    z2compare_xml.<locals>.child_text.<locals>.<genexpr>)r   
childNodeselementr-   r-   r.   
child_text&  s    zcompare_xml.<locals>.child_textc                 S   s   dd | j D S )Nc                 S   s   g | ]}|j tjkr|qS r-   )r   r   ZELEMENT_NODEr   r-   r-   r.   r   +  s    z1compare_xml.<locals>.children.<locals>.<listcomp>)r   r   r-   r-   r.   children*  s    zcompare_xml.<locals>.childrenc                    s    | S r)   r-   r   )r   r   r-   r.   norm_child_text.  s    z$compare_xml.<locals>.norm_child_textc                 S   s   t | j S r)   )r   
attributesrp   r   r-   r-   r.   
attrs_dict1  s    zcompare_xml.<locals>.attrs_dictc                    sx   | j |j krdS | |kr$dS  |  |kr8dS | }|}t|t|kr\dS tfddt||D S )NFc                 3   s   | ]\}} ||V  qd S r)   r-   )rG   wantgot)check_elementr-   r.   rI   ?  s     z5compare_xml.<locals>.check_element.<locals>.<genexpr>)ZtagNamer   allzip)Zwant_elementZgot_elementZwant_childrenZgot_children)r   r   r   r   r-   r.   r   4  s    z"compare_xml.<locals>.check_elementc                 S   s*   | j D ]}|jtjtjfkr|  S qd S r)   )r   r   r   ZCOMMENT_NODEZDOCUMENT_TYPE_NODE)documentnoder-   r-   r.   
first_nodeA  s    
zcompare_xml.<locals>.first_nodez\n
z<?xmlz<root>%s</root>)recompilestripreplace
startswithr   )r   r   r   wrapperZ	want_rootZgot_rootr-   )r   r   r   r   r   r   r   r.   compare_xml  s"    	

r   c                   @   sL   e Zd ZdZdd Zdd Zdd Zdd	 Zed
d Z	dd Z
dd ZdS )CaptureQueriesContextzU
    Context manager that captures queries executed by the specified connection.
    c                 C   s
   || _ d S r)   )rz   )r,   rz   r-   r-   r.   r/   [  s    zCaptureQueriesContext.__init__c                 C   s
   t | jS r)   )itercaptured_queriesr1   r-   r-   r.   __iter__^  s    zCaptureQueriesContext.__iter__c                 C   s
   | j | S r)   )r  )r,   r{   r-   r-   r.   r?   a  s    z!CaptureQueriesContext.__getitem__c                 C   s
   t | jS r)   )r   r  r1   r-   r-   r.   __len__d  s    zCaptureQueriesContext.__len__c                 C   s   | j j| j| j S r)   )rz   Zqueriesinitial_queriesfinal_queriesr1   r-   r-   r.   r  g  s    z&CaptureQueriesContext.captured_queriesc                 C   s>   | j j| _d| j _| j   t| j j| _d | _tt	 | S )NT)
rz   rq   Zensure_connectionr   queries_logr  r  r   Z
disconnectr   r1   r-   r-   r.   r   k  s    


zCaptureQueriesContext.__enter__c                 C   s2   | j | j_ tt |d k	r d S t| jj| _d S r)   )rq   rz   r   connectr   r   r  r  r   r-   r-   r.   r   v  s
    

zCaptureQueriesContext.__exit__N)r8   r9   r:   rM   r/   r  r?   r  propertyr  r   r   r-   r-   r-   r.   r  W  s   
r  c                       s,   e Zd Z fddZdd Zdd Z  ZS )ignore_warningsc                    s:   || _ d| j ksd| j kr$tj| _ntj| _t   d S )Nmessagemodule)ignore_kwargswarningsfilterwarningsfilter_funcsimplefilterr>   r/   r   rB   r-   r.   r/     s
    
zignore_warnings.__init__c                 C   s&   t  | _| j  | jd| j d S )Nignore)r  )r  catch_warningsr   r  r  r1   r-   r-   r.   r     s    

zignore_warnings.enablec                 C   s   | j jt   d S r)   )r  r   sysexc_infor1   r-   r-   r.   r     s    zignore_warnings.disable)r8   r9   r:   r/   r   r   rN   r-   r-   rB   r.   r  ~  s   r  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                  g   s2   t jdd }t j|  z
dV  W 5 |t _X dS )z5Context manager to temporarily add paths to sys.path.N)r  pathr   )pathsZ_orig_sys_pathr-   r-   r.   extend_sys_path  s
    
r  c                 c   s"   |    z
dV  W 5 |    X dS )z?Clear the cache of an LRU cache object on entering and exiting.N)cache_clear)Zlru_cache_objectr-   r-   r.   r      s    
r    c              
   c   s<   t t| }tt| t  zt t| V  W 5 tt| | X dS )a  Return 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_stdoutr-   r-   r.   captured_output  s
    
r  c                   C   s   t dS )zCapture the output of sys.stdout:

       with captured_stdout() as stdout:
           print("hello")
       self.assertEqual(stdout.getvalue(), "hello
")
    stdoutr  r-   r-   r-   r.   captured_stdout  s    r   c                   C   s   t dS )zCapture the output of sys.stderr:

       with captured_stderr() as stderr:
           print("hello", file=sys.stderr)
       self.assertEqual(stderr.getvalue(), "hello
")
    stderrr  r-   r-   r-   r.   captured_stderr  s    r"  c                   C   s   t dS )a  Capture 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  r-   r-   r-   r.   captured_stdin  s    
r$  c                 #   s,   t j } fddt _ z
dV  W 5 |t _ X dS )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                      s    S r)   r-   r-   tr-   r.   <lambda>      zfreeze_time.<locals>.<lambda>N)time)r&  Z
_real_timer-   r%  r.   freeze_time  s
    	
r*  c                 C   s6   t tdkd| } tdddddddidgd	| 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.
    Nzthis test requires jinja2z/django.template.backends.django.DjangoTemplatesT)BACKENDAPP_DIRSz&django.template.backends.jinja2.Jinja2Zkeep_trailing_newline)r+  r,  OPTIONS)Z	TEMPLATES)r	   jinja2r#   )r   r-   r-   r.   require_jinja2  s    r/  c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )override_script_prefixzEDecorator or context manager to temporary override the script prefix.c                    s   || _ t   d S r)   )prefixr>   r/   )r,   r1  rB   r-   r.   r/     s    zoverride_script_prefix.__init__c                 C   s   t  | _t| j d S r)   )r   
old_prefixr   r1  r1   r-   r-   r.   r     s    zoverride_script_prefix.enablec                 C   s   t | j d S r)   )r   r2  r1   r-   r-   r.   r     s    zoverride_script_prefix.disabler   r-   r-   rB   r.   r0    s   r0  c                   @   s    e Zd ZdZdd Zdd ZdS )LoggingCaptureMixinzn
    Capture the output from the 'django' logger and store it on the class's
    logger_output attribute.
    c                 C   s8   t d| _| jjd j| _t | _| j| jjd _d S )NZdjangor   )logging	getLoggerloggerhandlersstream
old_streamr   Zlogger_outputr1   r-   r-   r.   r     s    zLoggingCaptureMixin.setUpc                 C   s   | j | jjd _d S r3   )r9  r6  r7  r8  r1   r-   r-   r.   r     s    zLoggingCaptureMixin.tearDownN)r8   r9   r:   rM   r   r   r-   r-   r-   r.   r3    s   r3  c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )isolate_appsa  
    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                    s   || _ t jf | d S r)   )installed_appsr>   r/   )r,   r;  ru   rB   r-   r.   r/   /  s    zisolate_apps.__init__c                 C   s"   t j| _t| j}tt d| |S Ndefault_apps)r   r=  old_appsr   r;  r   )r,   r   r-   r-   r.   r   3  s    
zisolate_apps.enablec                 C   s   t td| j d S r<  )r   r   r>  r1   r-   r-   r.   r   9  s    zisolate_apps.disabler   r-   r-   rB   r.   r:    s   r:  c                     s    fdd}|S )z0Decorator to add tags to a test class or method.c                    s.   t | dr| j | _nt| dt  | S )Nr   )rX   r   unionr   rJ   )objr   r-   r.   	decorator?  s    
ztag.<locals>.decoratorr-   )r   rB  r-   rA  r.   tag=  s    rC  )lookup_namec                g   s>   z |D ]}| || qdV  W 5 |D ]}|  || q&X dS )z
    Context manager to temporarily register lookups on a model field using
    lookup_name (or the lookup's lookup_name if not provided).
    N)Z_unregister_lookupregister_lookup)fieldrD  Zlookupslookupr-   r-   r.   rE  H  s    
rE  )N)FFr   N)N)r   F)N)Yr4  r   r  r)  r  
contextlibr   	functoolsr   ior   	itertoolsr   typesr   Zunittestr   r	   r
   Zxml.dom.minidomr   r   Zdjango.appsr   Zdjango.apps.registryr   Zdjango.confr   r   Zdjango.corer   Zdjango.core.exceptionsr   Zdjango.core.signalsr   Z	django.dbr   r   r   Zdjango.db.models.optionsr   Zdjango.templater   Zdjango.test.signalsr   r   Zdjango.urlsr   r   Zdjango.utils.translationr   r.  ImportError__all__rX   Z
TZ_SUPPORTr   r   r   rT   rU   r%   r&   r|   r   rj   r   r!   r   r#   r"   r   r   r  r  r$   r  r    r  r   r"  r$  r*  r/  r0  r3  r:  rC  rE  r-   r-   r-   r.   <module>   s   

"	
$
,*
.

EN0?'


	



