ó
    ¼RjŒ;  ã                   ó0  • S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	J
r
Jr  SSKJr  SSKJr  \R                   " S5      r\" S	S
5      rS r " S S\R(                  5      r " S S5      r " S S5      r " S S5      rSS jrS rS r " S S5      rg)zî
Various data structures used in query construction.

Factored out from django.db.models.query to avoid making the main module very
large and/or so that they can be used by other modules without getting into
circular import difficulties.
é    N)Ú
namedtuple)Ú
FieldError)ÚDEFAULT_DB_ALIASÚDatabaseErrorÚconnections)Ú
LOOKUP_SEP)Útreeúdjango.db.modelsÚPathInfozGfrom_opts to_opts target_fields join_field m2m direct filtered_relationc              #   ól   #   • U v •  U R                  5        H  n[        U5       S h  v•N   M     g  N	7f©N)Ú__subclasses__Ú
subclasses©ÚclsÚsubclasss     ÚHD:\diplom_project\venv\Lib\site-packages\django/db/models/query_utils.pyr   r      s.   é € Ø
‚IØ×&Ñ&Ö(ˆÜ˜hÓ'×'Ò'ò )Ù'ùs   ‚&4¨2©
4c                   óŒ   ^ • \ rS rSrSrSrSrSr\rSr	SSS	.U 4S
 jjr
S rS rS rS rS r SS jrS r\4S jrS rSrU =r$ )ÚQé#   zY
Encapsulate filters as objects that can then be combined logically (using
`&` and `|`).
ÚANDÚORÚXORTNF)Ú
_connectorÚ_negatedc                óZ   >• [         TU ]  / UQ[        UR                  5       5      QUUS9  g )N)ÚchildrenÚ	connectorÚnegated)ÚsuperÚ__init__ÚsortedÚitems)Úselfr   r   ÚargsÚkwargsÚ	__class__s        €r   r!   Ú
Q.__init__0   s3   ø€ Ü‰ÑØ5�tÐ5œf V§\¡\£^Ó4Ð5Ø Øð 	ò 	
ó    c                 ó$  • [        USS5      SL a  [        U5      eU (       d  UR                  5       $ U(       d%  [        U[        5      (       a  U R                  5       $ U R                  US9nUR                  X5        UR                  X5        U$ )NÚconditionalF)r   )ÚgetattrÚ	TypeErrorÚcopyÚ
isinstancer   ÚcreateÚadd)r$   ÚotherÚconnÚobjs       r   Ú_combineÚ
Q._combine7   su   € Ü�5˜-¨Ó/°5Ò8Ü˜EÓ"Ð"ÞØ—:‘:“<ÐÞœ E¬1×-Ñ-Ø—9‘9“;Ðà�k‰k DˆkÐ)ˆØ�‰�ÔØ�‰�ÔØˆ
r)   c                 ó8   • U R                  XR                  5      $ r   )r5   r   ©r$   r2   s     r   Ú__or__ÚQ.__or__D   s   € Ø�}‰}˜U§G¡GÓ,Ð,r)   c                 ó8   • U R                  XR                  5      $ r   )r5   r   r8   s     r   Ú__and__Ú	Q.__and__G   ó   € Ø�}‰}˜U§H¡HÓ-Ð-r)   c                 ó8   • U R                  XR                  5      $ r   )r5   r   r8   s     r   Ú__xor__Ú	Q.__xor__J   r>   r)   c                 óF   • U R                  5       nUR                  5         U$ r   )r.   Únegate)r$   r4   s     r   Ú
__invert__ÚQ.__invert__M   s   € Ø�i‰i‹kˆØ�
‰
ŒØˆ
r)   c           	      óT   • UR                  U UUSSUS9u  pgUR                  U5        U$ )NF)Úallow_joinsÚ
split_subqÚcheck_filterableÚ	summarize)Ú_add_qÚpromote_joins)r$   ÚqueryrG   ÚreuserJ   Úfor_saveÚclauseÚjoinss           r   Úresolve_expressionÚQ.resolve_expressionR   s@   € ð
 Ÿ™ØØØ#ØØ"Øð %ð 
‰ˆð 	×Ñ˜EÔ"Øˆr)   c              #   óÐ   #   • U v •  U R                    HL  n[        U[        5      (       a  US   n[        US5      (       a  UR	                  5        Sh  v•N   MH  Uv •  MN     g N7f)zO
Recursively yield this Q object and all subexpressions, in depth-first
order.
é   ÚflattenN)r   r/   ÚtupleÚhasattrrV   )r$   Úchilds     r   rV   Ú	Q.flattenb   sV   é € ð
 Š
Ø—]”]ˆEÜ˜%¤×'Ñ'à˜a™�Ü�u˜i×(Ñ(Ø Ÿ=™=›?×*Ò*à”ò #ñ
 +ùs   ‚AA&ÁA$ÁA&c           
      óL  • SSK JnJn  SSKJn  SSKJn  SSKJn  U" S5      nUR                  5        H.  u  pš[        U
S5      (       d  U" U
5      n
UR                  X©SS	9  M0     UR                  U" S
5      S5        [        U   R                  R                  (       a&  UR                  [!        U" U SU" 5       S95      5        OUR                  U 5        UR#                  US9n UR%                  U5      SL$ ! [&         a   n[(        R+                  SX5         SnAgSnAff = f)zd
Do a database query to check if the expressions of the Q instance
matches against the expressions.
r   )ÚBooleanFieldÚValue)ÚCoalesce)ÚQuery)ÚSINGLENrR   F)ÚselectrU   Ú_checkT)Úoutput_field)Úusingz.Got a database error calling check() on %r: %s)Údjango.db.modelsr\   r]   Údjango.db.models.functionsr^   Údjango.db.models.sqlr_   Údjango.db.models.sql.constantsr`   r#   rX   Úadd_annotationr   ÚfeaturesÚsupports_comparing_boolean_exprÚadd_qr   Úget_compilerÚexecute_sqlr   ÚloggerÚwarning)r$   Úagainstrd   r\   r]   r^   r_   r`   rM   ÚnameÚvalueÚcompilerÚes                r   ÚcheckÚQ.checkq   s÷   € ÷ 	9Ý7Ý.Ý9á�d“ˆØ"Ÿ=™=ž?‰KˆDÜ˜5Ð"6×7Ñ7Ù˜e›�Ø× Ñ  °UÐ Ó;ñ +ð 	×Ñ™U 1›X xÔ0ä�uÑ×&Ñ&×F×FØ�K‰Kœ™( 4¨¹L»NÑKÓLÕMà�K‰K˜ÔØ×%Ñ%¨EÐ%Ð2ˆð	Ø×'Ñ'¨Ó/°tÐ;Ð;øÜó 	Ü�N‰NÐKÈTÔUÜûð	ús   Ã&C9 Ã9
D#ÄDÄD#c                 óh  • U R                   R                  < SU R                   R                  < 3nUR                  S5      (       a  UR	                  SS5      n[        U R                  5      n0 nU R                  U R                  :w  a  U R                  US'   U R                  (       a  SUS'   XU4$ )NÚ.zdjango.db.models.query_utilsr
   r   Tr   )
r'   Ú
__module__Ú__name__Ú
startswithÚreplacerW   r   r   Údefaultr   )r$   Úpathr%   r&   s       r   ÚdeconstructÚQ.deconstructŽ   s�   € ØŸ.™.×3Ô3°T·^±^×5LÓ5LÐMˆØ�?‰?Ð9×:Ñ:Ø—<‘<Ð >Ð@RÓSˆDÜ�T—]‘]Ó#ˆØˆØ�>‰>˜TŸ\™\Ó)Ø#'§>¡>ˆF�<Ñ Ø�<�<Ø!%ˆF�:ÑØ˜6Ð!Ð!r)   © )NTNFF)r{   rz   Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r~   r+   r!   r5   r9   r<   r@   rD   rR   rV   r   rv   r€   Ú__static_attributes__Ú__classcell__)r'   s   @r   r   r   #   sp   ø† ñð €CØ	€BØ
€CØ€GØ€Kà)-¸÷ 
ð 
òò-ò.ò.òð SXôò ð $4ô ÷:
"ð 
"r)   r   c                   ó.   • \ rS rSrSrS rSS jrS rSrg)	ÚDeferredAttributeé›   zx
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
c                 ó   • Xl         g r   ©Úfield)r$   r�   s     r   r!   ÚDeferredAttribute.__init__¡   s   € Ø�
r)   Nc                 óº   • Uc  U $ UR                   nU R                  R                  nXC;  a,  U R                  U5      nUc  UR	                  U/S9  X4   $ XSU'   X4   $ )z`
Retrieve and caches the value from the datastore on the first lookup.
Return the cached value.
)Úfields)Ú__dict__r�   ÚattnameÚ_check_parent_chainÚrefresh_from_db)r$   Úinstancer   ÚdataÚ
field_nameÚvals         r   Ú__get__ÚDeferredAttribute.__get__¤   sw   € ð
 ÑØˆKØ× Ñ ˆØ—Z‘Z×'Ñ'ˆ
ØÓ!ð ×*Ñ*¨8Ó4ˆCØ‰{Ø×(Ñ(°°Ð(Ñ=ð ÑÐð $'�ZÑ ØÑÐr)   c                 óæ   • UR                   nUR                  U R                  R                  5      nU R                  R                  (       a%  U R                  U:w  a  [        XR                  5      $ g)z¡
Check if the field value can be fetched from a parent field already
loaded in the instance. This can be done if the to-be fetched
field is a primary key field.
N)Ú_metaÚget_ancestor_linkr�   ÚmodelÚprimary_keyr,   r’   )r$   r•   ÚoptsÚ
link_fields       r   r“   Ú%DeferredAttribute._check_parent_chain·   sS   € ð �~‰~ˆØ×+Ñ+¨D¯J©J×,<Ñ,<Ó=ˆ
Ø�:‰:×!×! d§j¡j°JÓ&>Ü˜8×%7Ñ%7Ó8Ð8Ør)   rŒ   r   )	r{   rz   rƒ   r„   r…   r!   r™   r“   r†   r‚   r)   r   r‰   r‰   ›   s   † ñò
ô õ&
r)   r‰   c                   ó$   • \ rS rSrSrS rS rSrg)Úclass_or_instance_methodéÄ   z€
Hook used in RegisterLookupMixin to return partial functions depending on
the caller type (instance or class of models.Field).
c                 ó   • Xl         X l        g r   ©Úclass_methodÚinstance_method)r$   r¨   r©   s      r   r!   Ú!class_or_instance_method.__init__Ê   s   € Ø(ÔØ.Õr)   c                 óŒ   • Uc!  [         R                  " U R                  U5      $ [         R                  " U R                  U5      $ r   )Ú	functoolsÚpartialr¨   r©   )r$   r•   Úowners      r   r™   Ú class_or_instance_method.__get__Î   s:   € ØÑÜ×$Ò$ T×%6Ñ%6¸Ó>Ð>Ü× Ò  ×!5Ñ!5°xÓ@Ð@r)   r§   N)r{   rz   rƒ   r„   r…   r!   r™   r†   r‚   r)   r   r¤   r¤   Ä   s   † ñò
/õAr)   r¤   c                   ó  • \ rS rSrS r\R                  " SS9S 5       rS r\	" \\5      r
\" \5      rS rS r\S	 5       r\S
 5       rSS jrSS jr\	" \\5      r\" \5      rSS jrSS jr\	" \\5      r\" \5      rSrg)ÚRegisterLookupMixinéÔ   c                 óB   • U R                  5       R                  US 5      $ r   )Úget_lookupsÚget)r$   Úlookup_names     r   Ú_get_lookupÚRegisterLookupMixin._get_lookupÕ   s   € Ø×ÑÓ!×%Ñ% k°4Ó8Ð8r)   N)Úmaxsizec                 ó¬   • [         R                  " U 5       Vs/ s H  oR                  R                  S0 5      PM      nnU R	                  U5      $ s  snf ©NÚclass_lookups)ÚinspectÚgetmror‘   rµ   Úmerge_dicts)r   Úparentr¼   s      r   Úget_class_lookupsÚ%RegisterLookupMixin.get_class_lookupsØ   sR   € ô DKÇ>Â>ÐRUÔCVó
ÚCV¸�O‰O×Ñ °Ö4ÑCVð 	ð 
ð �‰˜}Ó-Ð-ùò
s   ™%Ac                 óZ   • U R                  5       n[        U SS 5      =n(       a  0 UEUE$ U$ ©NÚinstance_lookups)rÁ   r,   )r$   r¼   rÅ   s      r   Úget_instance_lookupsÚ(RegisterLookupMixin.get_instance_lookupsß   s=   € Ø×.Ñ.Ó0ˆÜ& tÐ-?ÀÓFÐFÐÕFØ8�mÐ8Ð'7Ð8Ð8ØÐr)   c                 óº   • SSK Jn  U R                  U5      nUc,  [        U S5      (       a  U R                  R                  U5      $ Ub  [        X25      (       d  g U$ )Nr   )ÚLookuprc   )Údjango.db.models.lookupsrÉ   r·   rX   rc   Ú
get_lookupÚ
issubclass)r$   r¶   rÉ   Úfounds       r   rË   ÚRegisterLookupMixin.get_lookupè   sU   € Ý3à× Ñ  Ó-ˆØ‰=œW T¨>×:Ñ:Ø×$Ñ$×/Ñ/°Ó<Ð<ØÑ¤Z°×%>Ñ%>ØØˆr)   c                 óº   • SSK Jn  U R                  U5      nUc,  [        U S5      (       a  U R                  R                  U5      $ Ub  [        X25      (       d  g U$ )Nr   )Ú	Transformrc   )rÊ   rÐ   r·   rX   rc   Úget_transformrÌ   )r$   r¶   rÐ   rÍ   s       r   rÑ   Ú!RegisterLookupMixin.get_transformò   sU   € Ý6à× Ñ  Ó-ˆØ‰=œW T¨>×:Ñ:Ø×$Ñ$×2Ñ2°;Ó?Ð?ØÑ¤Z°×%AÑ%AØØˆr)   c                 óP   • 0 n[        U 5       H  nUR                  U5        M     U$ )z“
Merge dicts in reverse to preference the order of the original list. e.g.,
merge_dicts([a, b]) will preference the keys in 'a' over those in 'b'.
)ÚreversedÚupdate)ÚdictsÚmergedÚds      r   r¿   ÚRegisterLookupMixin.merge_dictsü   s(   € ð ˆÜ˜%–ˆAØ�M‰M˜!Öñ !àˆr)   c                 ó\   • [        U 5       H  nUR                  R                  5         M     g r   )r   rÁ   Úcache_clearr   s     r   Ú_clear_cached_class_lookupsÚ/RegisterLookupMixin._clear_cached_class_lookups  s"   € ä" 3žˆHØ×&Ñ&×2Ñ2Ö4ò (r)   c                 óŽ   • Uc  UR                   nSU R                  ;  a  0 U l        XR                  U'   U R                  5         U$ r»   )r¶   r‘   r¼   rÜ   ©r   Úlookupr¶   s      r   Úregister_class_lookupÚ)RegisterLookupMixin.register_class_lookup  sF   € ØÑØ ×,Ñ,ˆKØ #§,¡,Ó.Ø "ˆCÔØ)/×Ñ˜+Ñ&Ø×'Ñ'Ô)Øˆr)   c                 ón   • Uc  UR                   nSU R                  ;  a  0 U l        XR                  U'   U$ rÄ   )r¶   r‘   rÅ   ©r$   rà   r¶   s      r   Úregister_instance_lookupÚ,RegisterLookupMixin.register_instance_lookup  s:   € ØÑØ ×,Ñ,ˆKØ T§]¡]Ó2Ø$&ˆDÔ!Ø-3×Ñ˜kÑ*Øˆr)   c                 ó\   • Uc  UR                   nU R                  U	 U R                  5         g)zV
Remove given lookup from cls lookups. For use in tests only as it's
not thread-safe.
N)r¶   r¼   rÜ   rß   s      r   Ú_unregister_class_lookupÚ,RegisterLookupMixin._unregister_class_lookup"  s/   € ð
 ÑØ ×,Ñ,ˆKØ×Ñ˜kÐ*Ø×'Ñ'Õ)r)   c                 ó<   • Uc  UR                   nU R                  U	 g)z[
Remove given lookup from instance lookups. For use in tests only as
it's not thread-safe.
N)r¶   rÅ   rä   s      r   Ú_unregister_instance_lookupÚ/RegisterLookupMixin._unregister_instance_lookup,  s#   € ð
 ÑØ ×,Ñ,ˆKØ×!Ñ! +Ñ.r)   )rÅ   r   )r{   rz   rƒ   r„   r·   r¬   Ú	lru_cacherÁ   rÆ   r¤   r´   ÚclassmethodrË   rÑ   Ústaticmethodr¿   rÜ   rá   rå   Úregister_lookuprè   rë   Ú_unregister_lookupr†   r‚   r)   r   r±   r±   Ô   sÎ   † ò9ð ×Ò Ñ&ñ.ó 'ð.òñ +Ð+<Ð>RÓS€KÙ#Ð$5Ó6Ðòòð ñó ðð ñ5ó ð5ôôñ /ØÐ7ó€Oñ (Ð(=Ó>Ðô*ô/ñ 2Ø Ð"=óÐñ  +Ð+CÓDÓr)   r±   c                 óÐ  • U R                   (       d  gU R                   R                  (       a  U(       d  gU(       a4  U(       a  U R                  5       U;  a  gU(       d  U R                  U;  a  gU(       d  U R                  (       a  gU(       aV  U(       aO  U R                  U;   a?  X;  a:  [        SU R                  R                  R                   SU R                   S35      eg)a6  
Return True if this field should be used to descend deeper for
select_related() purposes. Used by both the query construction code
(compiler.get_related_selections()) and the model instance creation code
(compiler.klass_info).

Arguments:
 * field - the field to be checked
 * restricted - a boolean field, indicating if the field list has been
   manually restricted using a requested clause)
 * requested - The select_related() dictionary.
 * select_mask - the dictionary of selected fields.
 * reverse - boolean, True if we are checking a reverse select related
FzField ry   zM cannot be both deferred and traversed using select_related at the same time.T)	Úremote_fieldÚparent_linkÚrelated_query_namerr   Únullr   rž   rœ   Úobject_name)r�   Ú
restrictedÚ	requestedÚselect_maskÚreverses        r   Úselect_related_descendrü   ;  s³   € ð ××ØØ×Ñ×%×%®gØÞÞ�u×/Ñ/Ó1¸ÓBØÞ˜5Ÿ:™:¨YÓ6ØÞ˜%Ÿ*Ÿ*ØæÞØ�J‰J˜)Ó#ØÓ$äØ�U—[‘[×&Ñ&×2Ñ2Ð3°1°U·Z±Z°Lð ALð Ló
ð 	
ð r)   c                 ó°   • [        S[        U 5      S-   5       H:  n[        R                  " U SU 5      nUR	                  U5      (       d  M4  X0US 4s  $    g)zÅ
Check if the lookup_parts contains references to the given annotations set.
Because the LOOKUP_SEP is contained in the default annotation names, check
each prefix of the lookup_parts for a match.
rU   r   N)Nr‚   )ÚrangeÚlenr   Újoinrµ   )Úlookup_partsÚannotationsÚnÚlevel_n_lookups       r   Úrefs_expressionr  b  sX   € ô �1”c˜,Ó'¨!Ñ+Ö,ˆÜ#Ÿš¨°a¸Ð):Ó;ˆØ�?‰?˜>×*Ó*Ø!°°Ð#3Ð3Ò3ñ -ð r)   c                 óŽ   ^ • U 4S jnU" U5      =(       d0    [        USS5      =(       a    U" UR                  R                  5      $ )zÊ
Check that self.model is compatible with target_opts. Compatibility
is OK if:
  1) model and opts match (where proxy inheritance is removed)
  2) model is parent of opts' model or the other way around
c                 óÚ   >• TR                   R                  U R                  :H  =(       dA    U R                  TR                   R                  5       ;   =(       d    TU R                  5       ;   $ r   )rœ   Úconcrete_modelÚget_parent_list)r    rž   s    €r   rv   Ú-check_rel_lookup_compatibility.<locals>.checkw  sV   ø€ à�K‰K×&Ñ&¨$×*=Ñ*=Ñ=÷ /Ø×"Ñ" e§k¡k×&AÑ&AÓ&CÑC÷/à˜×,Ñ,Ó.Ñ.ð	
r)   rŸ   F)r,   rž   rœ   )rž   Útarget_optsr�   rv   s   `   r   Úcheck_rel_lookup_compatibilityr  o  s<   ø€ õ
ñ  �Ó÷ Ü��} eÓ,×I±°u·{±{×7HÑ7HÓ1Iðr)   c                   óH   • \ rS rSrSr\" 5       S.S jrS rS rS r	S r
S	rg
)ÚFilteredRelationiŒ  z7Specify custom filtering in the ON clause of SQL joins.©Ú	conditionc                óœ   • U(       d  [        S5      eXl        S U l        [        U[        5      (       d  [        S5      eX l        / U l        g )Nzrelation_name cannot be empty.z*condition argument must be a Q() instance.)Ú
ValueErrorÚrelation_nameÚaliasr/   r   r  r   )r$   r  r  s      r   r!   ÚFilteredRelation.__init__�  sC   € ÞÜÐ=Ó>Ð>Ø*ÔØˆŒ
Ü˜)¤Q×'Ñ'ÜÐIÓJÐJØ"ŒØˆ�	r)   c                 óô   • [        XR                  5      (       d  [        $ U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ r   )r/   r'   ÚNotImplementedr  r  r  r8   s     r   Ú__eq__ÚFilteredRelation.__eq__™  sZ   € Ü˜%§¡×0Ñ0Ü!Ð!à×Ñ %×"5Ñ"5Ñ5÷ 2Ø—
‘
˜eŸk™kÑ)÷2à—‘ %§/¡/Ñ1ð	
r)   c                 óŒ   • [        U R                  U R                  S9nU R                  Ul        U R                  S S  Ul        U$ )Nr  )r  r  r  r  r   )r$   Úclones     r   r  ÚFilteredRelation.clone¢  s7   € Ü  ×!3Ñ!3¸t¿~¹~ÑNˆØ—j‘jˆŒØ—Y‘Y™q�\ˆŒ
Øˆr)   c                 ó   • [        S5      e)zb
QuerySet.annotate() only accepts expression-like arguments
(with a resolve_expression() method).
z0FilteredRelation.resolve_expression() is unused.)ÚNotImplementedError)r$   r%   r&   s      r   rR   Ú#FilteredRelation.resolve_expression¨  s   € ô
 "Ð"TÓUÐUr)   c                 ó–   • UR                   nUR                  U R                  [        U R                  5      S9nUR                  U5      $ )N)rN   )rM   Úbuild_filtered_relation_qr  Úsetr   Úcompile)r$   rt   Ú
connectionrM   Úwheres        r   Úas_sqlÚFilteredRelation.as_sql¯  s=   € à—‘ˆØ×/Ñ/°·±ÄcÈ$Ï)É)ÃnÐ/ÐUˆØ×Ñ Ó&Ð&r)   )r  r  r   r  N)r{   rz   rƒ   r„   r…   r   r!   r  r  rR   r&  r†   r‚   r)   r   r  r  Œ  s$   † ÙAá34³3õ ò
òòVõ'r)   r  )F)r…   r¬   r½   ÚloggingÚcollectionsr   Údjango.core.exceptionsr   Ú	django.dbr   r   r   Údjango.db.models.constantsr   Údjango.utilsr	   Ú	getLoggerro   r   r   ÚNoder   r‰   r¤   r±   rü   r  r  r  r‚   r)   r   Ú<module>r0     s¢   ðñó Û Û Ý "å -ß BÑ BÝ 1Ý à	×	Ò	Ð-Ó	.€ñ
 ØØMó€ò(ôu"ˆ�	‰	ô u"÷p&ñ &÷RAñ A÷ dEñ dEôN$òN
ò÷:''ò ''r)   