zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
U
¸ý°dkã@s„dZddlmZddlmZddlmZddlmZddlmZddlmZddlm    Z    dd    lm
Z
dd
lm Z dd lm Z dd lm Z dd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl#m%Z%d d!lm&Z'd d"lm(Z(d d#lm)Z)d d$lm#Z#d d%l*m+Z+d d&l*m,Z,d d'l-m.Z.d d(l/m0Z0d d)l/m1Z1d d*l2m3Z3d d+l4m5Z5d d,l4m6Z6d d-l4m7Z7d d.l4m8Z8d d/l4m9Z9d d0l4m:Z:d d1l4m;Z;e ròdd2l<m=Z=dd3l<m>Z>dd4l<m?Z?dd5l<m@Z@dd6lmAZAdd7lBmCZCdd8lDmEZEdd9lFmGZGdd:lHmIZIdd;lHmJZJd d<lKmLZLd d=lMmNZNd d>lMmOZOd d?lPmQZQd d@l4mRZRd dAl4mSZSedBedCZTedDedCZUedEdFdCZVdGdHdIdJdKgZWe)jXGdLdG„dGeeTe eTee)jYƒƒZZGdMdN„dNeZeTeeTƒZ[GdOdP„dPeeeTeeTƒZ\dQS)Rz|MapperProperty implementations.
 
This is a private module which defines the behavior of individual ORM-
mapped attributes.
 
é)Ú annotations)ÚAny)Úcast)ÚDict)ÚList)ÚOptional)ÚSequence)ÚSet)ÚTuple)ÚType)Ú TYPE_CHECKING)ÚTypeVaré)Ú
attributes)Ústrategy_options)Ú_DeclarativeMapped)Ú class_mapper)ÚCompositeProperty)ÚConcreteInheritedProperty)ÚSynonymProperty)Ú_AttributeOptions)Ú_DEFAULT_ATTRIBUTE_OPTIONS)Ú_IntrospectsAnnotations)Ú _MapsColumns)ÚMapperProperty)ÚPropComparator)ÚStrategizedProperty)ÚRelationshipProperty)Úde_stringify_annotation)Úde_stringify_union_elementsé)Úexc)Ú
ForeignKey)Úlog)Úutil)Ú    coercions)Úroles)Ú_NoArg)ÚColumn)Ú SchemaConst)Ú
TypeEngine)Úde_optionalize_union_types)Ú
is_fwd_ref)Úis_optional_union)Ú    is_pep593)Úis_union)ÚSelf)Útyping_get_args)Ú_IdentityKeyType)Ú _InstanceDict)Ú_ORMColumnExprArgument)Ú _RegistryType)ÚMapped)Ú_ClassScanMapperConfig)ÚMapper)ÚSession)Ú_InstallLoaderCallableProto)Ú InstanceState)Ú    _InfoType)Ú ColumnElement)Ú NamedColumn)Ú OperatorType)Ú_AnnotationScanType)ÚRODescriptorReferenceÚ_T)ÚboundÚ_PTÚ_NCzNamedColumn[Any]ÚColumnPropertyrrrrcs¦eZdZUdZejZdZdZde    d<de    d<de    d    <d
e    d <d Z
d d ddd ddd d dddœ ddddddddddddddœ ‡fdd„Z dddddddddddœ
dd „Z e d!d"œd#d$„ƒZe d%d"œd&d'„ƒZdd"œd(d)„Ze d*d+¡d,d"œd-d.„ƒZe d*d+¡d,d"œd/d0„ƒZd1d"œd2d3„Ze d1d"œd4d5„ƒZd6dd7œd8d9„Zdd"œ‡fd:d;„ Zd<d"œd=d>„Zd?d@dAd@dAddBdCddDœ    dEdF„ZGdGdH„dHejeeƒZdd"œdIdJ„Z‡Z S)KrFz¬Describes an object attribute that corresponds to a table column
    or other column expression.
 
    Public constructor is the :func:`_orm.column_property` function.
 
    TFzList[NamedColumn[Any]]ÚcolumnsÚboolÚ_is_polymorphic_discriminatorú Optional[str]Ú_mapped_by_synonymzType[PropComparator[_T]]Úcomparator_factory)rGÚgroupÚdeferredÚ
instrumentrLÚactive_historyÚexpire_on_flushÚ_creation_orderrIrKZ_deferred_column_loaderZ_raise_column_loaderZ_renders_in_subqueriesÚ    raiseloadN) Úattribute_optionsrMrNrSrLrPrQÚinfoÚdocÚ _instrumentÚ_assume_readonly_dc_attributesz_ORMColumnExprArgument[_T]z_ORMColumnExprArgument[Any]zOptional[_AttributeOptions]z"Optional[Type[PropComparator[_T]]]zOptional[_InfoType]) ÚcolumnÚadditional_columnsrTrMrNrSrLrPrQrUrVrWrXc sôtƒj|| d|f| }dd„|Dƒ|_||_||_||_| |_|dk    rN|n|jj|_    ||_
||_ |    dk    rx|j   |    ¡|
dk    rˆ|
|_n4t|jƒD]"}t|ddƒ}
|
dk    r’|
|_q¼q’d|_t |¡d|jfd|jff|_|jrð|jd7_dS)N)rTrXcSsg|]}t tj|¡‘qS©)r%Úexpectr&ZLabeledColumnExprRole©Ú.0Úcr[r[úPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/orm/properties.pyÚ
<listcomp>¡sz+ColumnProperty.__init__.<locals>.<listcomp>rVrNrO))rST)ÚsuperÚ__init__rGrMrNrSrOÚ    __class__Ú
ComparatorrLrPrQrUÚupdaterVÚreversedÚgetattrr$Úset_creation_orderÚ strategy_key)ÚselfrYrTrMrNrSrLrPrQrUrVrWrXrZrGÚcol©rdr[r`rcŒsDþ
ÿÿý  
þzColumnProperty.__init__r7r5ú    Type[Any]ÚstrúOptional[Type[Mapped[Any]]]úOptional[_AnnotationScanType]ÚNone©
Ú    decl_scanÚregistryÚclsÚoriginating_moduleÚkeyÚmapped_containerÚ
annotationÚextracted_mapped_annotationÚis_dataclass_fieldÚreturnc
Cs.|jd}
|
jdkr||
_|
jdkr*||
_dS©Nr)rGrxÚname) rkrtrurvrwrxryrzr{r|rYr[r[r`Údeclarative_scanÇs
 
 
 
zColumnProperty.declarative_scanúOptional[MapperProperty[_T]]©r}cCs|S©Nr[©rkr[r[r`Úmapper_property_to_assignÙsz(ColumnProperty.mapper_property_to_assignúList[Tuple[Column[Any], int]]cCsdd„|jDƒS)NcSs(g|] }t|tƒr|jdkr|df‘qSr~)Ú
isinstancer(Útabler]r[r[r`raàs
 
þz4ColumnProperty.columns_to_assign.<locals>.<listcomp>©rGr„r[r[r`Úcolumns_to_assignÝsþz ColumnProperty.columns_to_assigncCs(d|jkr|jjSd|jkp&||jjkS)N)Zquery_expressionT)rNT)rjZstrategyZ_have_default_expressionÚparentZ_readonly_propsr„r[r[r`Ú%_memoized_attr__renders_in_subqueriesæs
 
 
 
ÿz4ColumnProperty._memoized_attr__renders_in_subquerieszsqlalchemy.orm.statezsqlalchemy.orm.strategiesz _InstallLoaderCallableProto[Any]cCs.tjj}tjj}|j |jj| |j    ¡|j    ¡Srƒ©
r$Ú    preloadedZ    orm_stateZorm_strategiesr;Z"_instance_level_callable_processorr‹Z class_managerZLoadDeferredColumnsrx©rkÚstateZ
strategiesr[r[r`Ú&_memoized_attr__deferred_column_loaderîs
ýz5ColumnProperty._memoized_attr__deferred_column_loadercCs0tjj}tjj}|j |jj| |j    d¡|j    ¡S)NTrrr[r[r`Ú#_memoized_attr__raise_column_loaderús ýz2ColumnProperty._memoized_attr__raise_column_loaderzroles.ColumnsClauseRolecCs|jS)zsAllow the ColumnProperty to work in expression before it is turned
        into an instrumented attribute.
        )Ú
expressionr„r[r[r`Ú__clause_element__sz!ColumnProperty.__clause_element__cCs
|jdS)aÊReturn the primary column or expression for this ColumnProperty.
 
        E.g.::
 
 
            class File(Base):
                # ...
 
                name = Column(String(64))
                extension = Column(String(8))
                filename = column_property(name + '.' + extension)
                path = column_property('C:/' + filename.expression)
 
        .. seealso::
 
            :ref:`mapper_column_property_sql_expressions_composed`
 
        rr‰r„r[r[r`r“ szColumnProperty.expressionz Mapper[Any])Úmapperr}cCs0|js
dStj|j|j| ||¡||jddS)N)Z
comparatorÚ parententityrV)rOrZregister_descriptorÚclass_rxrLrV)rkr•r[r[r`Úinstrument_class#s
ûzColumnProperty.instrument_classcsVtƒ ¡t|jƒdkrRt|jjƒ |j¡rRt     d|j|jd|jd|j
f¡dS)Nrz»On mapper %s, primary key column '%s' is being combined with distinct primary key column '%s' in attribute '%s'. Use explicit properties to give each column its own mapped attribute name.r) rbÚdo_initÚlenrGÚsetr‹Z primary_keyÚ
issupersetr$Úwarnrxr„rmr[r`r™/s
ÿúÿzColumnProperty.do_initzColumnProperty[_T]cCst|j|j|j|jdœŽS)N)rNrMrP)rFrGrNrMrPr„r[r[r`Úcopy?s üzColumnProperty.copyr9zInstanceState[Any]r3zDict[Any, object]z#Dict[_IdentityKeyType[Any], object])    ÚsessionÚ source_stateÚ source_dictÚ
dest_stateÚ    dest_dictÚloadÚ
_recursiveÚ_resolve_conflict_mapr}c     Cst|js
dS|j|krL||j}    |s.|    ||j<qp| |j¡}
|
 |||    d¡n$|jrp|j|krp|j||jgdddS)NT)Z    no_loader)rOrxZget_implr›Z has_identityZ_expire_attributes) rkrŸr r¡r¢r£r¤r¥r¦ÚvalueÚimplr[r[r`ÚmergeGs 
 
  ÿzColumnProperty.mergec@s®eZdZUdZesdZded<ded<dddœd    d
„ZerHd d œd d„Zd d œdd„Z    dd œdd„Z
dd œdd„Z dddœdd„Z dddddœdd„Z dddddœd d!„Zd"S)#zColumnProperty.Comparatora€Produce boolean, comparison, and other operators for
        :class:`.ColumnProperty` attributes.
 
        See the documentation for :class:`.PropComparator` for a brief
        overview.
 
        .. seealso::
 
            :class:`.PropComparator`
 
            :class:`.ColumnOperators`
 
            :ref:`types_operators`
 
            :attr:`.TypeEngine.comparator_factory`
 
        )r”rUÚ expressionsz*RODescriptorReference[ColumnProperty[_PT]]ÚpropzSequence[NamedColumn[Any]]rªrE)rYr}cCsT|j}||||jjdœ}|}|jjr>|}|jj |¡}||d<| |¡ d|dœ¡S)aíannotate and possibly adapt a column to be returned
            as the mapped-attribute exposed version of the column.
 
            The column in this context needs to act as much like the
            column in an ORM mapped context as possible, so includes
            annotations to give hints to various ORM functions as to
            the source entity of this column.   It also adapts it
            to the mapper's with_polymorphic selectable if one is
            present.
 
            )Zentity_namespacer–Z parentmapperÚ    proxy_keyZ adapt_columnZorm)Zcompile_state_pluginZplugin_subject)Z _parententityr«rxZ _parentmapperZ_polymorphic_adapterZtraverseZ    _annotateZ_set_propagate_attrs)rkrYÚperrlZmapper_local_colr[r[r`Ú_orm_annotate_column…s ü
ÿz.ColumnProperty.Comparator._orm_annotate_columnzNamedColumn[_PT]r‚cCsdSrƒr[r„r[r[r`r”¯sz,ColumnProperty.Comparator.__clause_element__cCs4|jr| |jjd|jj¡S| |jjd¡SdSr~)Úadapterr«rGrxr®r„r[r[r`Ú#_memoized_method___clause_element__²sz=ColumnProperty.Comparator._memoized_method___clause_element__r<cCs2| ¡}z|jWStk
r,|jjYSXdS)z(The .info dictionary for this attribute.N)r”rUÚAttributeErrorr«)rkZcer[r[r`Ú_memoized_attr_infoºs
z-ColumnProperty.Comparator._memoized_attr_infocs6ˆjr‡fdd„ˆjjDƒS‡fdd„ˆjjDƒSdS)z¡The full sequence of columns referenced by this
            attribute, adjusted for any aliasing in progress.
 
            .. versionadded:: 1.3.17
 
            csg|]}ˆ |ˆjj¡‘qSr[)r¯r«rx©r^rlr„r[r`raËsÿzHColumnProperty.Comparator._memoized_attr_expressions.<locals>.<listcomp>csg|]}ˆ |¡‘qSr[)r®r³r„r[r`raÐsN)r¯r«rGr„r[r„r`Ú_memoized_attr_expressionsÃs
þ
ÿz4ColumnProperty.Comparator._memoized_attr_expressionsror)rxr}cCst| ¡|ƒS)z‡proxy attribute access down to the mapped column.
 
            this allows user-defined comparison methods to be accessed.
            )rhr”)rkrxr[r[r`Ú_fallback_getattrÔsz+ColumnProperty.Comparator._fallback_getattrr?úColumnElement[Any]©ÚopÚotherÚkwargsr}cOs|| ¡f|ž|ŽSrƒ©r”©rkr¸r¹rºr[r[r`ÚoperateÛsz!ColumnProperty.Comparator.operatecKs| ¡}|| ||¡|f|ŽSrƒ©r”Z _bind_param©rkr¸r¹rºrlr[r[r`Úreverse_operateàsz)ColumnProperty.Comparator.reverse_operateN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r Ú    __slots__Ú__annotations__r®r”r°r²r´rµr½rÀr[r[r[r`reas
 (    recCs.|jr |jst |¡St|jjjƒd|jS)NÚ.)r‹rxÚobjectÚ__repr__ror—rÁr„r[r[r`Ú__str__æs 
zColumnProperty.__str__)!rÁrÂrÃrÄrZ _COLUMN_TOKENZstrategy_wildcard_keyÚ inherit_cacheZ_links_to_entityrÆrÅrcr€Úpropertyr…rŠrŒr$Úpreload_moduler‘r’r”r“r˜r™ržr©Z MemoizedSlotsrrDrerÊÚ __classcell__r[r[rmr`rF_sR
ò.; 
 
  c@seZdZdZdZdS)ÚMappedSQLExpressionaNDeclarative front-end for the :class:`.ColumnProperty` class.
 
    Public constructor is the :func:`_orm.column_property` function.
 
    .. versionchanged:: 2.0 Added :class:`_orm.MappedSQLExpression` as
       a Declarative compatible subclass for :class:`_orm.ColumnProperty`.
 
    .. seealso::
 
        :class:`.MappedColumn`
 
    TN)rÁrÂrÃrÄrËr[r[r[r`rÏìs rÏc @s:eZdZUdZdZded<ded<ded<ded    <d
ed <d ed <dddœdd„Zdddœdd„Zeddœdd„ƒZ    eddœdd„ƒZ
eddœdd„ƒZ ddœd d!„Z d"ddd#d$œd%d&„Z d"ddd#d$œd'd(„Zddœd)d*„Zd+d,d-ddd.d/d/dd0d1œ
d2d3„Ze d4¡d,d-dddd5d0d6œd7d8„ƒZd-d,d5dd0d9œd:d;„Zd<S)=Ú MappedColumna_Maps a single :class:`_schema.Column` on a class.
 
    :class:`_orm.MappedColumn` is a specialization of the
    :class:`_orm.ColumnProperty` class and is oriented towards declarative
    configuration.
 
    To construct :class:`_orm.MappedColumn` objects, use the
    :func:`_orm.mapped_column` constructor function.
 
    .. versionadded:: 2.0
 
 
    ) rYrRÚ _sort_orderÚ foreign_keysÚ _has_nullableÚ_has_insert_defaultrNÚdeferred_groupÚdeferred_raiseloadrPÚ_attribute_optionsÚ_has_dataclass_argumentsÚ_use_existing_columnrHrNrÖrJrÕú
Column[_T]rYzOptional[Set[ForeignKey]]rÒrr×r)ÚargÚkwcOsX| dt¡|_}| dd¡|_d|_|dk    rh|tkrh|jtjk    rJd|_n|jtjk    sb|j    tjk    rhd|_| dtj¡}|tjk    |_
|j
r’||d<n|j tjk    r¨|j |d<| dd¡|_ | dd¡|_ | d    tj¡|_|jtjkròt|j pì|j ƒ|_| d
d¡|_| d d ¡|_td t||Žƒ|_|jj|_d|koF| d¡dtjfk|_t |¡dS)NrTZuse_existing_columnFTÚinsert_defaultÚdefaultrÕrÖrNrPZ
sort_orderrrÚÚnullable)Úpoprr×rÙrØZdataclasses_default_factoryr'ZNO_ARGZdataclasses_initZdataclasses_reprrÔZdataclasses_defaultrÕrÖrNrHrPrÑrr(rYrÒÚgetr)ZNULL_UNSPECIFIEDrÓr$ri)rkrÛrÜZ    attr_optsrÝr[r[r`rc)sHÿ
 
ÿ
þ 
 
 
ÿ
þzMappedColumn.__init__r0)rÜr}cKs†|j |j¡}|jjf|Ž|_|j|_|j|_|j|_|jj|_|j|_|j    |_    |j
|_
|j |_ |j |_ |j |_ |j|_t |¡|Srƒ)rdÚ__new__rYÚ_copyrNrÕrÖrÒrPrÓr×rÔrØrÙrÑr$ri)rkrÜÚnewr[r[r`rãVs
 
zMappedColumn._copyror‚cCs|jjSrƒ)rYrr„r[r[r`rgszMappedColumn.namercCs4|js |jr,t|j|j|j|j|j|jdSdSdS)N)rNrMrSrTrP)rNrPrFrYrÕrÖr×r„r[r[r`r…ks ú    z&MappedColumn.mapper_property_to_assignr†cCs|j|jfgSrƒ)rYrÑr„r[r[r`rŠyszMappedColumn.columns_to_assigncCs|jSrƒ)rYr„r[r[r`r”}szMappedColumn.__clause_element__r?r¶r·cOs|| ¡f|ž|ŽSrƒr»r¼r[r[r`r½€szMappedColumn.operatecKs| ¡}|| ||¡|f|ŽSrƒr¾r¿r[r[r`rÀ…szMappedColumn.reverse_operatecCs| ¡Srƒ)rãr„r[r[r`Úfound_in_pep593_annotated‹sz&MappedColumn.found_in_pep593_annotatedr7r5rnrprqrrrsc
CsÀ|j}
|jr^|jr^|jr^|jr(t d¡‚t|jdƒ} |
jdk    rD|
jn|} | j    j
  | |
¡}
|_|
j dkrn||
_ |
jdkr~||
_|
j } |dkr¬| jr¨|jjs¨| ||¡ndS| ||||¡dS)Nz3Can't use use_existing_column with deferred mappersF)rYrÙZinheritsZsingleZ is_deferredÚsa_excÚ ArgumentErrorrrZ local_tabler_rárxÚtypeÚ_isnullrÒZ_raise_for_requiredÚ_init_column_for_annotation)rkrtrurvrwrxryrzr{r|rYZsupercls_mapperZcolnameÚsqltyper[r[r`r€Žs@ ÿþýÿ ÿ
 
 
üzMappedColumn.declarative_scanzsqlalchemy.orm.decl_baser@)rurvrwrxÚ
param_nameÚparam_annotationr}cCs*tjj}| ||j¡| ||||¡dSrƒ)r$rŽZ orm_decl_baseZ_undefer_column_namerYrê)rkrurvrwrxrìríÚ    decl_baser[r[r`Údeclarative_scan_for_compositeÀs
ÿz+MappedColumn.declarative_scan_for_composite)rvruÚargumentrwr}cCsæ|jj}t|tƒst|ddr:|dk    s*t‚t|||dd}t|ƒrZ|dk    sNt‚t|||ƒ}t    |ƒ}|j
sp||j_ t |ƒ}d}t |ƒràd}    t|ƒ}
|
d} t    | ƒrºd}|j
s²||j_ t | ƒ} |
dd…D]} t| tƒrÆ| }qèqÆnd}    d} |dk    r&|js|jjdk    rd|j_|j |j¡|jj}|jrâ|jjsâd} |    rL|| g}n|g}|D] }| |¡} | dk    rVq֐qVt|tƒsœt|tƒrºt|tƒrºt d|jj›d|›d    ¡‚nt d
|›d |jj›d ¡‚|j | ¡dS) NT)Z check_generic)Zinclude_genericrrFzThe type provided inside the z4 attribute Mapped annotation is the SQLAlchemy type z . Expected a Python type insteadz6Could not locate SQLAlchemy Core type for Python type z  inside the z attribute Mapped annotation)rYrèr‡ror,ÚAssertionErrorrr/rr-rÓrßr+r.r1rÐrÔrÞZ_mergerérÒZ _resolve_typer*Ú
issubclassrærçrxZ    _set_type)rkrvrurðrwrërßZour_typeZ use_args_fromZour_type_is_pep593Zpep_593_componentsZraw_pep_593_typeÚelemZ new_sqltypeZchecksZ
check_typer[r[r`rêÐsˆ ÿ ÿ ÿ
 
ÿ
þ
 
 
 
 ÿþÿÿz(MappedColumn._init_column_for_annotationN)rÁrÂrÃrÄrÅrÆrcrãrÌrr…rŠr”r½rÀrår€r$rÍrïrêr[r[r[r`rÐþs0
-  2rÐN)]rÄÚ
__future__rÚtypingrrrrrrr    r
r r r ÚrrÚbaserrZdescriptor_propsrrrZ
interfacesrrrrrrrZ relationshipsrr$rrr!rær"r#Zsqlr%r&Zsql.baser'Z
sql.schemar(r)Z sql.type_apir*Z util.typingr+r,r-r.r/r0r1Ú_typingr2r3r4r5r6rîr7r•r8rŸr9rr:r;Z sql._typingr<Z sql.elementsr=r>Z sql.operatorsr?r@rArBrDrEÚ__all__Z class_loggerZ
IdentifiedrFrÏrÐr[r[r[r`Ú<module>s°                                                                 û    
ü
ý