https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/db/migrations/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/db/migrations/__pycache__/state.cpython-310.pyc
o

3�akb�@sddlZddlmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZddlmZmZdd	lmZdd
lmZddlmZddlmZd
dlmZd dd�Zdd�Zdd�Zdd�ZGdd�d�Z Gdd�de�Z!Gdd�de�Z"Gdd�d�Z#dS)!�N)�contextmanager)�	AppConfig)�Apps�apps)�settings)�models)�RECURSIVE_RELATIONSHIP_CONSTANT)�
DEFAULT_NAMES�normalize_together)�make_model_tuple)�cached_property)�
import_string)�get_docs_version�)�InvalidBasesError�cCsFt|t�r|�dd�}t|�dkrt|�S||dfS|jj|jjfS)N�.r�r)�
isinstance�str�split�len�tuple�_meta�	app_label�
model_name)�modelrr�r�</usr/lib/python3/dist-packages/django/db/migrations/state.py�_get_app_label_and_model_names
 rcCs�dd�|��D�}t�}|jjddd�D]}|jr0|jdur0t|jt�s0|�|j	�|�
|j�q|j}|jrA||vrA|�
|j�|S)zEReturn all models that have a direct relationship to the given model.cSsg|]
}t|tj�r|�qSr)�
issubclassr�Model)�.0�subclassrrr�
<listcomp>s
��z'_get_related_models.<locals>.<listcomp>T)�include_parents�include_hiddenN)
�__subclasses__�setr�
get_fields�is_relation�
related_modelrr�addr�append�proxy�concrete_model)�m�related_models�related_fields_models�f�optsrrr�_get_related_modelss��r5cCsdd�t|�D�S)zq
    Return a list of typical (app_label, model_name) tuples for all related
    models for the given model.
    cSsh|]
}|jj|jjf�qSr)rrr)r"�rel_modrrr�	<setcomp>2s��z,get_related_models_tuples.<locals>.<setcomp>)r5�rrrr�get_related_models_tuples-s�r9cCsjt�}t|�}|D] }|jj|jj}}||f|vrq	|�||f�|�t|��q	||jj|jjfhS)a�
    Return all models that have a direct or indirect relationship
    to the given model.

    Relationships are either defined by explicit relational fields, like
    ForeignKey, ManyToManyField or OneToOneField, or by inheriting from another
    model (a superclass is related to its subclasses, but not vice versa). Note,
    however, that a model inheriting from a concrete model is also related to
    its superclass through the implicit *_ptr OneToOneField on the subclass.
    )r(r5rrrr,�extend)r�seen�queuer6�
rel_app_label�rel_model_namerrr�get_related_models_recursive8sr?c@s�eZdZdZddd�Zdd�Zdd�Zd d
d�Zd dd
�Zd!dd�Z	dd�Z
dd�Zdd�Ze
dd��Zedd��Zedd��Zdd�ZdS)"�ProjectStatez�
    Represent the entire project's overall state. This is the item that is
    passed around - do it here rather than at the app level so that cross-app
    FKs/etc. resolve properly.
    NcCs|pi|_|pg|_d|_dS�NF)r�	real_apps�
is_delayed)�selfrrBrrr�__init__Us


zProjectState.__init__cCs:|j|j}}||j||f<d|jvr|�||�dSdS�Nr)r�
name_lowerr�__dict__�reload_model)rD�model_staterrrrr�	add_model[s

�zProjectState.add_modelcCs6|j||f=d|jvr|j�||�|j��dSdSrF)rrHr�unregister_model�clear_cache�rDrrrrr�remove_modelas

�zProjectState.remove_modelFc	Cs|rd|_t�}z	|j�||�}Wn	tyYnw|r"t|�}nt|�}|j||f}t�}|j�	�D]}|j
rR|jjt
krAq5t|j|�\}	}
|�|	|
��f�q5|�|�|D](\}	}
z	|j�|	|
�}Wn	typYqZw|r{|�t|��qZ|�t|��qZ|�||f�|S)NT)rCr(r�	get_model�LookupErrorr9r?r�fields�valuesr*�remote_fieldrrrr+r,�lower�update)rDrr�delayr1�	old_modelrJ�direct_related_models�fieldr=r>�	rel_modelrrr�_find_reload_modelis@�
�
�zProjectState._find_reload_modelcCs*d|jvr|�|||�}|�|�dSdSrF)rHr\�_reload)rDrrrWr1rrrrI�s
�zProjectState.reload_modelTcCsDd|jvr t�}|D]\}}|�|�|||��q
|�|�dSdSrF)rHr(rVr\r])rDrrWr1rrrrr�
reload_models�s
�zProjectState.reload_modelsc	Cs�|j���|D]\}}|j�||�qWd�n1swYg}|jjD]}|j|jf|vr8|�|�q)|D]\}}z	|j||f}Wn	tyQYq;w|�|�q;|j�	|�dS�N)
r�bulk_updaterL�real_modelsrrGr-r�KeyError�render_multiple)rDr1r=r>�states_to_be_renderedrJrrrr]�s$��
��zProjectState._reloadcCs@tdd�|j��D�|jd�}d|jvr|j��|_|j|_|S)z*Return an exact copy of this ProjectState.cS�i|]	\}}||���qSr��clone)r"�k�vrrr�
<dictcomp>��z&ProjectState.clone.<locals>.<dictcomp>)rrBr)r@r�itemsrBrHrrgrC)rD�	new_staterrrrg�s�
zProjectState.clonecCs$|jrd|jvr|jd=dSdSdSrF)rCrH�rDrrr�clear_delayed_apps_cache�s�z%ProjectState.clear_delayed_apps_cachecCst|j|j�Sr_)�	StateAppsrBrrnrrrr�szProjectState.appscCst|j|jdd�|_|jS)NT)�ignore_swappable)rprBrrrnrrr�
concrete_apps�szProjectState.concrete_appscCs8i}|jdd�D]}t�|�}|||j|jf<q||�S)z3Take an Apps and return a ProjectState matching it.T)�include_swapped)�
get_models�
ModelState�
from_modelrrG)�clsr�
app_modelsrrJrrr�	from_apps�s

zProjectState.from_appscCs |j|jkot|j�t|j�kSr_)rr(rB�rD�otherrrr�__eq__�s zProjectState.__eq__)NN�F)T)�__name__�
__module__�__qualname__�__doc__rErKrOr\rIr^r]rgrorr�propertyrr�classmethodryr|rrrrr@Ns$


0



r@c@s eZdZdZdd�Zdd�ZdS)�
AppConfigStubzAStub of an AppConfig. Only provides a label and a dict of models.cCsd|_i|_||_||_dSr_)rr�label�name)rDr�rrrrE�s
zAppConfigStub.__init__cCs|jj|j|_dSr_)r�
all_modelsr�rrnrrr�
import_models�szAppConfigStub.import_modelsN)r~rr�r�rEr�rrrrr��s	r�csNeZdZdZd�fdd�	Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
�ZS)rpzo
    Subclass of the global Apps registry class to better handle dynamic model
    additions and removals.
    Fcs�g|_|D]}t�|�}|��D]
}|j�tj|dd��qqdd�|��D�}dd�tg|�|��D�}t	��
|�d|_d|_|�
g|���|j��ddlm}	|r[ttj�hnt�}
|	||
d	�}|rrtd
�dd�|D����dS)
NT)�exclude_relscS�h|]}|j�qSr)r)r"rJrrrr7�z%StateApps.__init__.<locals>.<setcomp>cSsg|]}t|��qSr)r�)r"r�rrrr$�z&StateApps.__init__.<locals>.<listcomp>r)�_check_lazy_references)�ignore�
css�|]}|jVqdSr_)�msg)r"�errorrrr�	<genexpr>s�z%StateApps.__init__.<locals>.<genexpr>)ra�global_apps�get_app_configrtr-rurvrS�sorted�superrE�_lock�ready_eventrc�django.core.checks.model_checksr�rr�AUTH_USER_MODELr(�
ValueError�join)rDrBrrqr�appr�
app_labels�app_configsr�r��errors��	__class__rrrE�s$
��zStateApps.__init__ccs:�|j}d|_z
dVW||_|��dS||_|��wrA)�readyrM)rDr�rrrr`s��
zStateApps.bulk_updatec
Cs�|sdS|���F|}|rFg}|D]}z|�|�Wqty(|�|�Yqwt|�t|�kr:td|t�f��|}|s
Wd�dSWd�dS1sQwYdS)Nz�Cannot resolve bases for %r
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
 in an app with no migrations; see https://docs.djangoproject.com/en/%s/topics/migrations/#dependencies for more)r`�renderrr-rr)rD�model_states�unrendered_models�new_unrendered_modelsrrrrrc#s.
�����"�zStateApps.render_multiplecCsHtgi�}t�|j�|_t�|j�|_|j��D]}||_q|j|_|S)z Return a clone of this registry.)rp�copy�deepcopyr�r�rSrra)rDrg�
app_configrrrrg=s
zStateApps.clonecCs`||j||jj<||jvrt|�|j|<||j|_||j|j|jj<|�|�|��dSr_)	r�rrr�r�rr�do_pending_operationsrM)rDrrrrr�register_modelIs

zStateApps.register_modelcCs6z|j||=|j|j|=WdStyYdSwr_)r�r�rrbrNrrrrLRs�zStateApps.unregister_modelr})r~rr�r�rErr`rcrgr�rL�
__classcell__rrr�rrp�s
	rpc@sleZdZdZddd�Zedd��Zeddd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)rua�
    Represent a Django Model. Don't use the actual Model class as it's not
    designed to have its options changed - instead, mutate this one and then
    render it into a Model as required.

    Note that while you are allowed to mutate .fields, you are not allowed
    to mutate the Field instances inside there themselves - you must instead
    assign new ones, as these are not detached during a clone.
    Nc	Cs�||_||_t|�|_|pi|_|j�dg�|j�dg�|p#tjf|_|p(g|_	|j�
�D].\}}t|d�r>td|��|j
rMt|jd�rMtd|��|jr]t|jjd�r]td|��q/|jdD]}|jsntd|��qcdS)	N�indexes�constraintsrz7ModelState.fields cannot be bound to a model - "%s" is.rz_ModelState.fields cannot refer to a model class - "%s.to" does. Use a string reference instead.zdModelState.fields cannot refer to a model class - "%s.through" does. Use a string reference instead.zKIndexes passed to ModelState require a name attribute. %r doesn't have one.)rr��dictrR�options�
setdefaultrr!�bases�managersrl�hasattrr�r*r+�many_to_manyrT�through)	rDrr�rRr�r�r�rZ�indexrrrrEesF



����������zModelState.__init__cCs
|j��Sr_)r�rUrnrrrrG�s
zModelState.name_lowerFcs&g}�jjD]7}t|dd�r|rqt|tj�rq|j}z|�||��f�Wqt	y=}zt	d|�jj
|f��d}~ww|sl�jjD]'}|j}z|�||��f�WqDt	yk}zt	d|�jj|f��d}~wwi}t
D]j}|dvrwqp|�jjvr�|dkr��jjd}tt|��||<qp|dkr��jjd}	tt|	��||<qp|dkr�d	d
��jjD�}
|
D]
}|js�|���q�|
|d<qp|dkr�dd
��jjD�|d<qp�jj|||<qp|r�d
D]	}||vr�||=q�n|�d�dd��jjD�vr�|d=�fdd��tt�����fdd�d�}
tdd�|
D��}tdd�|D���s&tjf}g}t�}d}�jjD]J}|j|v�r;�q1|j�rIt�|�}|��n#|�ju�sU|�ju�rjt� �}|j!|_!|j|_|�ju�ri|}n�q1|�"|j�|�|j|f��q1|d|fgk�r�g}|�jj#�jj||||�S)z3Given a model, return a ModelState representing it.rTNz'Couldn't reconstruct field %s on %s: %sz+Couldn't reconstruct m2m field %s on %s: %s)rr�unique_together�index_togetherr�cS�g|]}|���qSrrf)r"�idxrrrr$�r�z)ModelState.from_model.<locals>.<listcomp>r�cSr�rrf)r"�conrrrr$�r�)r�r��order_with_respect_tor�cSr�r)r�)r"rZrrrr7�r�z(ModelState.from_model.<locals>.<setcomp>cs@g}|jD]}t|d�r|jjr|��|��q|�|�q|S)Nr)�	__bases__r�r�abstractr:r-)rr��base)�
flatten_basesrrr��s
z,ModelState.from_model.<locals>.flatten_basescs�j�|�Sr_)�__mro__r�)�xr8rr�<lambda>�sz'ModelState.from_model.<locals>.<lambda>��keycss&�|]}t|d�r
|jjn|VqdS)rN)r�r�label_lower�r"r�rrrr��s��
�
�z(ModelState.from_model.<locals>.<genexpr>css&�|]}t|t�pt|tj�VqdSr_)rrr rr!r�rrrr��s�$�objects)$r�local_fields�getattrrr�OrderWrtr�r-rg�	TypeErrorr��local_many_to_many�object_namer	�original_attrsr(r
r��set_name_with_modelr��get�private_fieldsr�r�anyr!r��use_in_migrationsr��_set_creation_counter�
_base_manager�_default_manager�Managerrr,r)rwrr�rRrZr��er��ut�itr�r�r��flattened_basesr�r��
manager_names�default_manager_shim�manager�new_managerr)r�rrrv�s�������
�
����	

��zModelState.from_modelccsp�t|jdd�d�}|D])\}}|��\}}}}}|r't|�}	||	��fVqt|�}
||
|i|��fVqdS)z-Deep-clone the managers using deconstruction.cSs
|djS)Nr)�creation_counter)rirrrr�s
z/ModelState.construct_managers.<locals>.<lambda>r�N)r�r��deconstructr
�
as_manager)rD�sorted_managers�mgr_namer�r��manager_path�qs_path�args�kwargs�qs_class�
manager_classrrr�construct_managerss��zModelState.construct_managerscCs.|j|j|jt|j�t|j�|jt|j�d�S)z(Return an exact copy of this ModelState.)rr�rRr�r�r�)	r�rr�r�rRr�r��listr�rnrrrrgs�zModelState.clonecs�|j�d�|j�}tdd|�}zt�fdd�|jD��}Wnty,td|jf��wdd�|j��D�}||d<d	|d
<|�	|�
��t|j||�S)zACreate a Model object from our current state into the given apps.)rr�Metarc3s(�|]}t|t�r��|�n|VqdSr_)rrrPr��rrrr�.s
��
�z$ModelState.render.<locals>.<genexpr>z(Cannot resolve one or more bases from %rcSrerrf)r"r�rZrrrrj5rkz%ModelState.render.<locals>.<dictcomp>�__fake__r)rr��typerr�rQrrRrlrVr�r�)rDr�
meta_contents�metar��bodyrr�rr�'s��zModelState.rendercC�4|jdD]}|j|kr|Sqtd||jf��)Nr�zNo index named %s on model %s�r�r�r�)rDr�r�rrr�get_index_by_name>�

�zModelState.get_index_by_namecCr�)Nr�z"No constraint named %s on model %sr�)rDr��
constraintrrr�get_constraint_by_nameDr�z!ModelState.get_constraint_by_namecCsd|jj|j|jfS)Nz
<%s: '%s.%s'>)r�r~rr�rnrrr�__repr__JszModelState.__repr__cCs||j|jko=|j|jko=t|j�t|j�ko=tdd�tt|j���t|j����D��o=|j|jko=|j	|j	ko=|j
|j
kS)NcssD�|]\\}}\}}||ko|��dd�|��dd�kVqdS)rN)r�)r"�k1�f1�k2�f2rrrr�Rs
�&�
�z$ModelState.__eq__.<locals>.<genexpr>)rr�rrR�all�zipr�rlr�r�r�rzrrrr|Ms$
�����

�
�
�zModelState.__eq__)NNNr})r~rr�r�rErrGr�rvr�rgr�r�r�r�r|rrrrruZs

"

ru)r)$r��
contextlibr�django.appsr�django.apps.registryrrr��django.confr�	django.dbr�django.db.models.fields.relatedr�django.db.models.optionsr	r
�django.db.models.utilsr�django.utils.functionalr�django.utils.module_loadingr
�django.utils.versionr�
exceptionsrrr5r9r?r@r�rprurrrr�<module>s,
g

https://t.me/RX1948 - 2025