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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
U
¸ý°d¡Uã@s6dZddlmZddlmZddlmZddlZddlmZddlm    Z    ddlm
Z
dd    lm Z dd
lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl#m$Z$ddl#m%Z%dd l#m&Z&dd!l#m'Z'ejr$dd"l(m)Z)dd#l*m+Z+dd$l*m,Z,dd%lm-Z-dd&l.m/Z/dd'l.m0Z0dd(l.m1Z1dd)l.m2Z2dd*l.m3Z3dd+l.m4Z4dd,l.m5Z5dd-l.m6Z6dd.l.m7Z7dd/l8m9Z9dd0l#m:Z:ed1ed2Z;ed3ed4d5Z<ed6ed4d7Z=ed8e>d2Z?ed9d:d2Z@ed;ed2ZAed<eeefZBGd=d>„d>eƒZCeCjDZEGd?d@„d@e$e<ƒZFGdAdB„dBe$e=ƒZGGdCdD„dDe$e<ƒZHGdEdF„dFe$e<ƒZIGdGdH„dHe&ƒZJGdIdJ„dJeJdKdLZKGdMdN„dNe$e;ƒZLGdOdP„dPee e;ƒZMGdQdR„dRƒZNGdSdT„dTeNƒZOGdUdV„dVeOeNeMe;e"jPƒZQGdWdX„dXeNƒZRdYdZd[œd\d]„ZSGd^d_„d_eNƒZTGd`da„daeeOeMe;ƒZUGdbdc„dceUe;ƒZVdddddeœdfdg„ZWedhddddd9diœdjdk„ƒZXedldddddmdiœdndk„ƒZXdodddddpdiœdqdk„ZXd:drd:dsœdtdu„ZYdS)vzBase types API.
 
é)Ú annotations)ÚEnum)Ú
ModuleTypeN)ÚAny)ÚCallable)Úcast)ÚDict)ÚGeneric)ÚMapping)ÚNewType)ÚOptional)Úoverload)ÚSequence)ÚTuple)ÚType)Ú TYPE_CHECKING)ÚTypeVar)ÚUnioné)ÚSchemaEventTarget)Ú
CacheConst)ÚNO_CACHE)ÚColumnOperators)Ú    Visitableé)Úexc)Úutil)ÚProtocol)ÚSelf)Ú    TypedDict)Ú    TypeGuard)Ú_TypeEngineArgument)Ú BindParameter)Ú ColumnElement)Ú OperatorType)Ú_resolve_value_to_type)Ú BOOLEANTYPE)Ú    INDEXABLE)Ú INTEGERTYPE)Ú    MATCHTYPE)ÚNULLTYPE)Ú NUMERICTYPE)Ú
STRINGTYPE)Ú
TABLEVALUE)ÚDialect)ÚGenericProtocolÚ_T)ÚboundÚ_T_coT)r1Ú    covariantÚ_T_con)r1Ú contravariantÚ_OÚ_TEúTypeEngine[Any]Ú_CTzGenericProtocol[Any]c@seZdZdZdS)Ú_NoValueInListrN)Ú__name__Ú
__module__Ú __qualname__ÚNO_VALUE_IN_LIST©r?r?úNd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/sql/type_api.pyr:Isr:c@seZdZdddœdd„ZdS)Ú_LiteralProcessorTyperÚstr©ÚvalueÚreturncCsdS©Nr?©ÚselfrDr?r?r@Ú__call__Ssz_LiteralProcessorType.__call__N©r;r<r=rIr?r?r?r@rARsrAc@seZdZdddœdd„ZdS)Ú_BindProcessorTypezOptional[_T_con]rrCcCsdSrFr?rGr?r?r@rIXsz_BindProcessorType.__call__NrJr?r?r?r@rKWsrKc@seZdZdddœdd„ZdS)Ú_ResultProcessorTyperúOptional[_T_co]rCcCsdSrFr?rGr?r?r@rI]sz_ResultProcessorType.__call__NrJr?r?r?r@rL\srLc@seZdZdddœdd„ZdS)Ú_SentinelProcessorTyperrMrCcCsdSrFr?rGr?r?r@rIbsz_SentinelProcessorType.__call__NrJr?r?r?r@rNasrNc@seZdZUded<ded<dS)Ú_BaseTypeMemoDictr8Úimplz.Dict[Any, Optional[_ResultProcessorType[Any]]]ÚresultN©r;r<r=Ú__annotations__r?r?r?r@rOfs
rOc@s.eZdZUded<ded<ded<ded<d    S)
Ú _TypeMemoDictz$Optional[_LiteralProcessorType[Any]]Úliteralz!Optional[_BindProcessorType[Any]]Úbindz%Optional[_SentinelProcessorType[Any]]ÚsentinelzDict[Any, object]ÚcustomNrRr?r?r?r@rTks
rTF)Útotalc@seZdZdddœdd„ZdS)Ú_ComparatorFactoryúColumnElement[_T]zTypeEngine.Comparator[_T])ÚexprrEcCsdSrFr?©rHr\r?r?r@rIssz_ComparatorFactory.__call__NrJr?r?r?r@rZrsrZc@sPeZdZUdZdZdZdZdZdZdZ    dZ
dZ Gdd„de e eƒZdZeZded<dZd    ed
<dZd ed <ejZd ed<ddœdd„Zdddœdd„Zddddœdd„Zdddœdd„Zdd d!œd"d#„Zdd$d!œd%d&„Zdd'd(d)œd*d+„Zd,d-d.œd/d0„Zej d dœd1d2„ƒZ!d3d-d4œd5d6„Z"dd7d!œd8d9„Z#ej d dœd:d;„ƒZ$e%d<d=d>œd?d@„ƒZ&ddd dAœdBdC„Z'dDdEdFœdGdH„Z(e)dIdœdJdK„ƒZ*dLdMddNœdOdP„Z+dddœdQdR„Z,dIdSdIdTdUœdVdW„Z-ej.dXdœdYdZ„ƒZ/ej.d[dœd\d]„ƒZ0d”d d^d_œd`da„Z1dd^d!œdbdc„Z2dd^d!œddde„Z3dd d!œdfdg„Z4dd$d!œdhdi„Z5ddd(d)œdjdk„Z6dd7d!œdldm„Z7ddMdndodpœdqdr„Z8ddsd!œdtdu„Z9ddd!œdvdw„Z:ej dxdœdydz„ƒZ;e<d{dd=d|œd}d~„ƒZ=e<dddd|œd€d~„ƒZ=dddd|œd‚d~„Z=dƒddd„œd…d†„Z>dd d‡œdˆd‰„Z?d•dŠdMd!œd‹dŒ„Z@e Ad¡ddœdŽd„ƒZBdMdœdd‘„ZCdMdœd’d“„ZDdS)–Ú
TypeEnginea1The ultimate base class for all SQL datatypes.
 
    Common subclasses of :class:`.TypeEngine` include
    :class:`.String`, :class:`.Integer`, and :class:`.Boolean`.
 
    For an overview of the SQLAlchemy typing system, see
    :ref:`types_toplevel`.
 
    .. seealso::
 
        :ref:`types_toplevel`
 
    TFc@sžeZdZUdZdZded<ded<ddœdd    „Zdd
œd d „Ze     d ¡dddddœdd„ƒZ
e     d ¡dddddœdd„ƒZ ddddœdd„Z ddœdd„Z dS)zTypeEngine.Comparatorz†Base class for custom comparison operations defined at the
        type level.  See :attr:`.TypeEngine.comparator_factory`.
 
 
        ©r\ÚtypeúColumnElement[_CT]r\zTypeEngine[_CT]r`©rEcCs|jSrF©r\©rHr?r?r@Ú__clause_element__³sz(TypeEngine.Comparator.__clause_element__rccCs||_|j|_dSrFr_r]r?r?r@Ú__init__¶szTypeEngine.Comparator.__init__z!sqlalchemy.sql.default_comparatorr$r©ÚopÚotherÚkwargsrEcOs:tjj}|j|j\}}|r&| |¡}||j|f|ž|ŽSrF©rÚ    preloadedZsql_default_comparatorZoperator_lookupr;Úunionr\©rHrhrirjZdefault_comparatorZop_fnZaddtl_kwr?r?r@Úoperateºs
 
zTypeEngine.Comparator.operatecKs@tjj}|j|j\}}|r&| |¡}||j||fddi|—ŽS)NÚreverseTrkrnr?r?r@Úreverse_operateÄs
 
z%TypeEngine.Comparator.reverse_operatezTypeEngine.Comparator[Any]z$Tuple[OperatorType, TypeEngine[Any]])rhÚother_comparatorrEcCs
||jfS)aOevaluate the return type of <self> <op> <othertype>,
            and apply any adaptations to the given operator.
 
            This method determines the type of a resulting binary expression
            given two source types and an operator.   For example, two
            :class:`_schema.Column` objects, both of the type
            :class:`.Integer`, will
            produce a :class:`.BinaryExpression` that also has the type
            :class:`.Integer` when compared via the addition (``+``) operator.
            However, using the addition operator with an :class:`.Integer`
            and a :class:`.Date` object will produce a :class:`.Date`, assuming
            "days delta" behavior by the database (in reality, most databases
            other than PostgreSQL don't accept this particular operation).
 
            The method returns a tuple of the form <operator>, <type>.
            The resulting operator and type will be those applied to the
            resulting :class:`.BinaryExpression` as the final operator and the
            right-hand side of the expression.
 
            Note that only a subset of operators make usage of
            :meth:`._adapt_expression`,
            including math operators and user-defined operators, but not
            boolean comparison or special SQL keywords like MATCH or BETWEEN.
 
            )r`)rHrhrrr?r?r@Ú_adapt_expressionÎsz'TypeEngine.Comparator._adapt_expressioncCs t|jffSrF)Ú_reconstitute_comparatorr\rdr?r?r@Ú
__reduce__ïsz TypeEngine.Comparator.__reduce__N)r;r<r=Ú__doc__Ú    __slots__rSrerfrÚpreload_modulerorqrsrur?r?r?r@Ú
Comparator¤s
        !ryú_ComparatorFactory[Any]Úcomparator_factoryNúOptional[Callable[[Any], Any]]Úsort_key_functionÚboolÚshould_evaluate_nonez(util.immutabledict[str, TypeEngine[Any]]Ú_variant_mappingrrbcCs| ¡}d|_|S)aÄReturn a copy of this type which has the
        :attr:`.should_evaluate_none` flag set to True.
 
        E.g.::
 
                Table(
                    'some_table', metadata,
                    Column(
                        String(50).evaluates_none(),
                        nullable=True,
                        server_default='no value')
                )
 
        The ORM uses this flag to indicate that a positive value of ``None``
        is passed to the column in an INSERT statement, rather than omitting
        the column from the INSERT statement which has the effect of firing
        off column-level defaults.   It also allows for types which have
        special behavior associated with the Python None value to indicate
        that the value doesn't necessarily translate into SQL NULL; a
        prime example of this is a JSON type which may wish to persist the
        JSON value ``'null'``.
 
        In all cases, the actual NULL SQL value can be always be
        persisted in any column by using
        the :obj:`_expression.null` SQL construct in an INSERT statement
        or associated with an ORM-mapped attribute.
 
        .. note::
 
            The "evaluates none" flag does **not** apply to a value
            of ``None`` passed to :paramref:`_schema.Column.default` or
            :paramref:`_schema.Column.server_default`; in these cases,
            ``None``
            still means "no default".
 
        .. seealso::
 
            :ref:`session_forcing_null` - in the ORM documentation
 
            :paramref:`.postgresql.JSON.none_as_null` - PostgreSQL JSON
            interaction with this flag.
 
            :attr:`.TypeEngine.should_evaluate_none` - class-level flag
 
        T)Úcopyr)rHÚtypr?r?r@Úevaluates_none3s.zTypeEngine.evaluates_noner©ÚkwrEcKs | |j¡SrF)ÚadaptÚ    __class__)rHr…r?r?r@reszTypeEngine.copyr.r8úOptional[bool])ÚdialectÚ    conn_typerEcCsdS)aœCompare this type against the given backend type.
 
        This function is currently not implemented for SQLAlchemy
        types, and for all built in types will return ``None``.  However,
        it can be implemented by a user-defined type
        where it can be consumed by schema comparison tools such as
        Alembic autogenerate.
 
        A future release of SQLAlchemy will potentially implement this method
        for builtin types as well.
 
        The function should return True if this type is equivalent to the
        given type; the type is typically reflected from the database
        so should be database specific.  The dialect in use is also
        passed.   It can also return False to assert that the type is
        not equivalent.
 
        :param dialect: a :class:`.Dialect` that is involved in the comparison.
 
        :param conn_type: the type object reflected from the backend.
 
        Nr?)rHr‰rŠr?r?r@Úcompare_against_backendhsz"TypeEngine.compare_against_backendrCcCs|SrFr?rGr?r?r@Ú
copy_valueƒszTypeEngine.copy_valueú#Optional[_LiteralProcessorType[_T]]©r‰rEcCsdS)amReturn a conversion function for processing literal values that are
        to be rendered directly without using binds.
 
        This function is used when the compiler makes use of the
        "literal_binds" flag, typically used in DDL generation as well
        as in certain scenarios where backends don't accept bound parameters.
 
        Returns a callable which will receive a literal Python value
        as the sole positional argument and will return a string representation
        to be rendered in a SQL statement.
 
        .. note::
 
            This method is only called relative to a **dialect specific type
            object**, which is often **private to a dialect in use** and is not
            the same type object as the public facing one, which means it's not
            feasible to subclass a :class:`.types.TypeEngine` class in order to
            provide an alternate :meth:`_types.TypeEngine.literal_processor`
            method, unless subclassing the :class:`_types.UserDefinedType`
            class explicitly.
 
            To provide alternate behavior for
            :meth:`_types.TypeEngine.literal_processor`, implement a
            :class:`_types.TypeDecorator` class and provide an implementation
            of :meth:`_types.TypeDecorator.process_literal_param`.
 
            .. seealso::
 
                :ref:`types_typedecorator`
 
 
        Nr?©rHr‰r?r?r@Úliteral_processor†s#zTypeEngine.literal_processorú Optional[_BindProcessorType[_T]]cCsdS)a¯Return a conversion function for processing bind values.
 
        Returns a callable which will receive a bind parameter value
        as the sole positional argument and will return a value to
        send to the DB-API.
 
        If processing is not necessary, the method should return ``None``.
 
        .. note::
 
            This method is only called relative to a **dialect specific type
            object**, which is often **private to a dialect in use** and is not
            the same type object as the public facing one, which means it's not
            feasible to subclass a :class:`.types.TypeEngine` class in order to
            provide an alternate :meth:`_types.TypeEngine.bind_processor`
            method, unless subclassing the :class:`_types.UserDefinedType`
            class explicitly.
 
            To provide alternate behavior for
            :meth:`_types.TypeEngine.bind_processor`, implement a
            :class:`_types.TypeDecorator` class and provide an implementation
            of :meth:`_types.TypeDecorator.process_bind_param`.
 
            .. seealso::
 
                :ref:`types_typedecorator`
 
 
        :param dialect: Dialect instance in use.
 
        Nr?rr?r?r@Úbind_processor«s"zTypeEngine.bind_processorÚobjectú"Optional[_ResultProcessorType[_T]]©r‰ÚcoltyperEcCsdS)a Return a conversion function for processing result row values.
 
        Returns a callable which will receive a result row column
        value as the sole positional argument and will return a value
        to return to the user.
 
        If processing is not necessary, the method should return ``None``.
 
        .. note::
 
            This method is only called relative to a **dialect specific type
            object**, which is often **private to a dialect in use** and is not
            the same type object as the public facing one, which means it's not
            feasible to subclass a :class:`.types.TypeEngine` class in order to
            provide an alternate :meth:`_types.TypeEngine.result_processor`
            method, unless subclassing the :class:`_types.UserDefinedType`
            class explicitly.
 
            To provide alternate behavior for
            :meth:`_types.TypeEngine.result_processor`, implement a
            :class:`_types.TypeDecorator` class and provide an implementation
            of :meth:`_types.TypeDecorator.process_result_value`.
 
            .. seealso::
 
                :ref:`types_typedecorator`
 
        :param dialect: Dialect instance in use.
 
        :param coltype: DBAPI coltype argument received in cursor.description.
 
        Nr?)rHr‰r–r?r?r@Úresult_processorÏs#zTypeEngine.result_processorr[úOptional[ColumnElement[_T]])ÚcolexprrEcCsdS)a<Given a SELECT column expression, return a wrapping SQL expression.
 
        This is typically a SQL function that wraps a column expression
        as rendered in the columns clause of a SELECT statement.
        It is used for special data types that require
        columns to be wrapped in some special database function in order
        to coerce the value before being sent back to the application.
        It is the SQL analogue of the :meth:`.TypeEngine.result_processor`
        method.
 
        This method is called during the **SQL compilation** phase of a
        statement, when rendering a SQL string. It is **not** called
        against specific values.
 
        .. note::
 
            This method is only called relative to a **dialect specific type
            object**, which is often **private to a dialect in use** and is not
            the same type object as the public facing one, which means it's not
            feasible to subclass a :class:`.types.TypeEngine` class in order to
            provide an alternate :meth:`_types.TypeEngine.column_expression`
            method, unless subclassing the :class:`_types.UserDefinedType`
            class explicitly.
 
            To provide alternate behavior for
            :meth:`_types.TypeEngine.column_expression`, implement a
            :class:`_types.TypeDecorator` class and provide an implementation
            of :meth:`_types.TypeDecorator.column_expression`.
 
            .. seealso::
 
                :ref:`types_typedecorator`
 
 
        .. seealso::
 
            :ref:`types_sql_value_processing`
 
        Nr?)rHr™r?r?r@Úcolumn_expressionôs+zTypeEngine.column_expressioncCs|jjjtjjk    S©z¾memoized boolean, check if column_expression is implemented.
 
        Allows the method to be skipped for the vast majority of expression
        types that don't use this feature.
 
        )r‡ršÚ__code__r^rdr?r?r@Ú_has_column_expression!s
ÿÿz!TypeEngine._has_column_expressionúBindParameter[_T])Ú    bindvaluerEcCsdS)a;Given a bind value (i.e. a :class:`.BindParameter` instance),
        return a SQL expression in its place.
 
        This is typically a SQL function that wraps the existing bound
        parameter within the statement.  It is used for special data types
        that require literals being wrapped in some special database function
        in order to coerce an application-level value into a database-specific
        format.  It is the SQL analogue of the
        :meth:`.TypeEngine.bind_processor` method.
 
        This method is called during the **SQL compilation** phase of a
        statement, when rendering a SQL string. It is **not** called
        against specific values.
 
        Note that this method, when implemented, should always return
        the exact same structure, without any conditional logic, as it
        may be used in an executemany() call against an arbitrary number
        of bound parameter sets.
 
        .. note::
 
            This method is only called relative to a **dialect specific type
            object**, which is often **private to a dialect in use** and is not
            the same type object as the public facing one, which means it's not
            feasible to subclass a :class:`.types.TypeEngine` class in order to
            provide an alternate :meth:`_types.TypeEngine.bind_expression`
            method, unless subclassing the :class:`_types.UserDefinedType`
            class explicitly.
 
            To provide alternate behavior for
            :meth:`_types.TypeEngine.bind_expression`, implement a
            :class:`_types.TypeDecorator` class and provide an implementation
            of :meth:`_types.TypeDecorator.bind_expression`.
 
            .. seealso::
 
                :ref:`types_typedecorator`
 
        .. seealso::
 
            :ref:`types_sql_value_processing`
 
        Nr?)rHrŸr?r?r@Úbind_expression/s.zTypeEngine.bind_expressionz$Optional[_SentinelProcessorType[_T]]cCsdS)zÜReturn an optional callable that will match parameter values
        (post-bind processing) to result values
        (pre-result-processing), for use in the "sentinel" feature.
 
        .. versionadded:: 2.0.10
 
        Nr?rr?r?r@Ú_sentinel_value_resolver_s
z#TypeEngine._sentinel_value_resolvercCst |tj¡S)z¼memoized boolean, check if bind_expression is implemented.
 
        Allows the method to be skipped for the vast majority of expression
        types that don't use this feature.
 
        )rÚmethod_is_overriddenr^r rdr?r?r@Ú_has_bind_expressionks    zTypeEngine._has_bind_expressionúUnion[Type[_TE], _TE]r7)Ú cls_or_selfrEcCst|ƒSrF)Ú to_instance)r¥r?r?r@Ú _to_instancevszTypeEngine._to_instance©ÚxÚyrEcCs||kS)z Compare two values for equality.r?©rHr©rªr?r?r@Úcompare_valueszszTypeEngine.compare_valuesrú Optional[Any]©ÚdbapirEcCsdS)z¤Return the corresponding type object from the underlying DB-API, if
        any.
 
        This can be useful for calling ``setinputsizes()``, for example.
 
        Nr?©rHr¯r?r?r@Úget_dbapi_typeszTypeEngine.get_dbapi_typez    Type[Any]cCs
tƒ‚dS)aReturn the Python type object expected to be returned
        by instances of this type, if known.
 
        Basically, for those types which enforce a return type,
        or are known across the board to do such for all common
        DBAPIs (like ``int`` for example), will return that type.
 
        If a return type is not defined, raises
        ``NotImplementedError``.
 
        Note that any type also accommodates NULL in SQL which
        means you can also get back ``None`` from any type
        in practice.
 
        N©ÚNotImplementedErrorrdr?r?r@Ú python_typeˆszTypeEngine.python_typez_TypeEngineArgument[Any]rB)Útype_Ú dialect_namesrEcsx|st d¡‚|D]$}||jkrt d|›d|›¡‚q| ¡}tˆƒ‰ˆjrXt d¡‚|j ‡fdd„|Dƒ¡|_|S)aÈProduce a copy of this type object that will utilize the given
        type when applied to the dialect of the given name.
 
        e.g.::
 
            from sqlalchemy.types import String
            from sqlalchemy.dialects import mysql
 
            string_type = String()
 
            string_type = string_type.with_variant(
                mysql.VARCHAR(collation='foo'), 'mysql', 'mariadb'
            )
 
        The variant mapping indicates that when this type is
        interpreted by a specific dialect, it will instead be
        transmuted into the given type, rather than using the
        primary type.
 
        .. versionchanged:: 2.0 the :meth:`_types.TypeEngine.with_variant`
           method now works with a :class:`_types.TypeEngine` object "in
           place", returning a copy of the original type rather than returning
           a wrapping object; the ``Variant`` class is no longer used.
 
        :param type\_: a :class:`.TypeEngine` that will be selected
         as a variant from the originating type, when a dialect
         of the given name is in use.
        :param \*dialect_names: one or more base names of the dialect which
         uses this type. (i.e. ``'postgresql'``, ``'mysql'``, etc.)
 
         .. versionchanged:: 2.0 multiple dialect names can be specified
            for one variant.
 
        .. seealso::
 
            :ref:`types_with_variant` - illustrates the use of
            :meth:`_types.TypeEngine.with_variant`.
 
        z%At least one dialect name is requiredzDialect z, is already present in the mapping for this zUcan't pass a type that already has variants as a dialect-level type to with_variant()csi|]
}|ˆ“qSr?r?)Ú.0Ú dialect_name©rµr?r@Ú
<dictcomp>Ùsz+TypeEngine.with_variant.<locals>.<dictcomp>)rÚ ArgumentErrorr€rr¦rm)rHrµr¶r¸Únew_typer?r¹r@Ú with_variant›s"-
 
ÿÿÿzTypeEngine.with_variantcCs|S)aJadjust this type given a literal Python value that will be
        stored in a bound parameter.
 
        Used exclusively by _resolve_value_to_type().
 
        .. versionadded:: 1.4.30 or 2.0
 
        TODO: this should be part of public API
 
        .. seealso::
 
            :meth:`.TypeEngine._resolve_for_python_type`
 
        r?rGr?r?r@Ú_resolve_for_literalÝszTypeEngine._resolve_for_literalÚ_MatchedOnTypezOptional[Self])r´Ú
matched_onÚmatched_on_flattenedrEcCs||k    r dS|S)aágiven a Python type (e.g. ``int``, ``str``, etc. ) return an
        instance of this :class:`.TypeEngine` that's appropriate for this type.
 
        An additional argument ``matched_on`` is passed, which indicates an
        entry from the ``__mro__`` of the given ``python_type`` that more
        specifically matches how the caller located this :class:`.TypeEngine`
        object.   Such as, if a lookup of some kind links the ``int`` Python
        type to the :class:`.Integer` SQL type, and the original object
        was some custom subclass of ``int`` such as ``MyInt(int)``, the
        arguments passed would be ``(MyInt, int)``.
 
        If the given Python type does not correspond to this
        :class:`.TypeEngine`, or the Python type is otherwise ambiguous, the
        method should return None.
 
        For simple cases, the method checks that the ``python_type``
        and ``matched_on`` types are the same (i.e. not a subclass), and
        returns self; for all other cases, it returns ``None``.
 
        The initial use case here is for the ORM to link user-defined
        Python standard library ``enum.Enum`` classes to the SQLAlchemy
        :class:`.Enum` SQL type when constructing ORM Declarative mappings.
 
        :param python_type: the Python type we want to use
        :param matched_on: the Python type that led us to choose this
         particular :class:`.TypeEngine` class, which would be a supertype
         of ``python_type``.   By default, the request is rejected if
         ``python_type`` doesn't match ``matched_on`` (None is returned).
 
        .. versionadded:: 2.0.0b4
 
        TODO: this should be part of public API
 
        .. seealso::
 
            :meth:`.TypeEngine._resolve_for_literal`
 
        Nr?)rHr´rÀrÁr?r?r@Ú_resolve_for_python_typeîs-z#TypeEngine._resolve_for_python_typezOptional[Type[TypeEngine[_T]]]cCs@d}|jjD],}|tks"t|jkr*|St|tƒr |}q |jS)zRReturn a rudimental 'affinity' value expressing the general class
        of type.N)r‡Ú__mro__r^ÚTypeEngineMixinÚ    __bases__Ú
issubclass)rHr‚Útr?r?r@Ú_type_affinity s 
zTypeEngine._type_affinityúType[TypeEngine[_T]]cCs˜d}d}t|tƒs|jS|jjD]b}|jdkr t|tƒr t|jkr |ttfkr |jddkr |j     ¡rp|sp|}q |j     ¡s |s |}q |p–|p–t
dt jƒS)N)zsqlalchemy.sql.sqltypeszsqlalchemy.sql.type_apirÚ_rÉ) Ú
isinstancer^r‡rÃr<rÆrÄrÅr;Úisupperrr*)rHZbest_camelcaseZbest_uppercaserÇr?r?r@Ú_generic_type_affinity.s4
 ÿÿúù
ø     ÷ ÿ
ýz!TypeEngine._generic_type_affinityúTypeEngine[_T])Úallow_nulltyperEcCs<|s.|jtjkr.td |jjd|jj¡ƒ‚t ||j¡S)aù
        Return an instance of the generic type corresponding to this type
        using heuristic rule. The method may be overridden if this
        heuristic rule is not sufficient.
 
        >>> from sqlalchemy.dialects.mysql import INTEGER
        >>> INTEGER(display_width=4).as_generic()
        Integer()
 
        >>> from sqlalchemy.dialects.mysql import NVARCHAR
        >>> NVARCHAR(length=100).as_generic()
        Unicode(length=100)
 
        .. versionadded:: 1.4.0b2
 
 
        .. seealso::
 
            :ref:`metadata_reflection_dbagnostic_types` - describes the
            use of :meth:`_types.TypeEngine.as_generic` in conjunction with
            the :meth:`_sql.DDLEvents.column_reflect` event, which is its
            intended use.
 
        zDefault TypeEngine.as_generic() heuristic method was unsuccessful for {}. A custom as_generic() method must be implemented for this type class.Ú.)    rÍr*r‡r³Úformatr<r;rÚconstructor_copy)rHrÏr?r?r@Ú
as_genericOsÿ
þüÿ    zTypeEngine.as_genericcCs:z|j|}Wntk
r"Yn
X|dS| |¡dS)zYReturn a dialect-specific implementation for this
        :class:`.TypeEngine`.
 
        rP)Ú _type_memosÚKeyErrorÚ _dialect_info)rHr‰Útmr?r?r@Ú dialect_implws zTypeEngine.dialect_implcCs
| |¡S)aµReturn the 'unwrapped' dialect impl for this type.
 
        For a type that applies wrapping logic (e.g. TypeDecorator), give
        us the real, actual dialect-level type that is used.
 
        This is used by TypeDecorator itself as well at least one case where
        dialects need to check that a particular specific dialect-level
        type is in use, within the :meth:`.DefaultDialect.set_input_sizes`
        method.
 
        )rØrr?r?r@Ú_unwrapped_dialect_impl„s z"TypeEngine._unwrapped_dialect_implcCsJz|j|dWStk
r$YnX| |¡}|d |¡|d<}|S)z:Return a dialect-specific literal processor for this type.rUrP)rÔrÕrÖr)rHr‰ÚdÚlpr?r?r@Ú_cached_literal_processor’s
z$TypeEngine._cached_literal_processorcCsJz|j|dWStk
r$YnX| |¡}|d |¡|d<}|S)z7Return a dialect-specific bind processor for this type.rVrP)rÔrÕrÖr’©rHr‰rÚZbpr?r?r@Ú_cached_bind_processor¢s
z!TypeEngine._cached_bind_processorcCsTz|j|d|WStk
r(YnX| |¡}|d ||¡}||d|<|S)z9Return a dialect-specific result processor for this type.rQrP)rÔrÕrÖr—)rHr‰r–rÚÚrpr?r?r@Ú_cached_result_processor²s
 z#TypeEngine._cached_result_processorcCsJz|j|dWStk
r$YnX| |¡}|d |¡|d<}|S)NrWrP)rÔrÕrÖr¡rÝr?r?r@Ú _cached_sentinel_value_processorÆs
z+TypeEngine._cached_sentinel_value_processorzCallable[[TypeEngine[_T]], _O]r6)r‰ÚkeyÚfnrEcCsbztt|j|d|ƒWStk
r.YnX| |¡}|d}| di¡}||ƒ||<}|S)zŠreturn a dialect-specific processing object for
        custom purposes.
 
        The cx_Oracle dialect uses this at the moment.
 
        rXrP)rr6rÔrÕrÖÚ
setdefault)rHr‰rârãrÚrPZ custom_dictrQr?r?r@Ú_cached_custom_processorÓs    
 z#TypeEngine._cached_custom_processorrTcCs\||jkr|j|S| |¡}||kr4| t|ƒ¡}||k    s@t‚|idœ}||j|<|SdS)z©Return a dialect-specific registry which
        caches a dialect-specific implementation, bind processing
        function, and one or more result processing functions.)rPrQN)rÔÚ_gen_dialect_implr†r`ÚAssertionError)rHr‰rPrÚr?r?r@rÖès
 
 
 
 
zTypeEngine._dialect_infocCs,|j|jkr|j|j |¡S| |¡SdSrF)Únamer€ræÚtype_descriptorrr?r?r@ræùs
  ÿzTypeEngine._gen_dialect_implú"Union[CacheConst, Tuple[Any, ...]]cs*t ˆj¡}ˆjft‡fdd„|DƒƒS)Nc3sZ|]R}|ˆjkr| d¡sˆj|dk    r|tˆj|tƒrFˆj|jnˆj|fVqdS)rÊN)Ú__dict__Ú
startswithrËr^Ú_static_cache_key)r·Úkrdr?r@Ú    <genexpr>s
 
øÿüz/TypeEngine._static_cache_key.<locals>.<genexpr>)rZget_cls_kwargsr‡Útuple)rHÚnamesr?rdr@rís ùzTypeEngine._static_cache_keyú    Type[_TE]©Úclsr…rEcKsdSrFr?©rHrôr…r?r?r@r†szTypeEngine.adaptúType[TypeEngineMixin]cKsdSrFr?rõr?r?r@r†sú-Type[Union[TypeEngine[Any], TypeEngineMixin]]cKstj|tttt|ƒf|ŽS)zöProduce an "adapted" form of this type, given an "impl" class
        to work with.
 
        This method is used internally to associate generic
        types with "implementation" types that are specific to a particular
        dialect.
        )rrÒrrr^rrõr?r?r@r†s
ÿÿúOptional[OperatorType]©rhrDrEcCs(t|ƒ}|tks|j|jkr |S|SdS)aoSuggest a type for a 'coerced' Python value in an expression.
 
        Given an operator and value, gives the type a chance
        to return a type which the value should be coerced into.
 
        The default behavior here is conservative; if the right-hand
        side is already coerced into a SQL type based on its
        Python type, it is usually left alone.
 
        End-user functionality extension here should generally be via
        :class:`.TypeDecorator`, which provides more liberal behavior in that
        it defaults to coercing the other side of the expression into this
        type, thus applying special Python conversions above and beyond those
        needed by the DBAPI to both ides. It also provides the public method
        :meth:`.TypeDecorator.coerce_compared_value` which is intended for
        end-user customization of this behavior.
 
        N)r%r*rÈ)rHrhrDZ _coerced_typer?r?r@Úcoerce_compared_value)sÿ
þz TypeEngine.coerce_compared_value)rirEcCs |j|jkSrF)rÈ)rHrir?r?r@Ú_compare_type_affinityGsz!TypeEngine._compare_type_affinityzOptional[Dialect]cCs|dkr| ¡}|j |¡S)zâProduce a string-compiled form of this :class:`.TypeEngine`.
 
        When called with no arguments, uses a "default" dialect
        to produce a string result.
 
        :param dialect: a :class:`.Dialect` instance.
 
        N)Ú_default_dialectZtype_compiler_instanceÚprocessrr?r?r@ÚcompileJs zTypeEngine.compilezsqlalchemy.engine.defaultcCstjj}| ¡SrF)rrlZengine_defaultZStrCompileDialect)rHÚdefaultr?r?r@rü[szTypeEngine._default_dialectcCs t| ¡ƒSrF)rBrþrdr?r?r@Ú__str__eszTypeEngine.__str__cCs
t |¡SrF)rÚ generic_reprrdr?r?r@Ú__repr__hszTypeEngine.__repr__)F)N)Er;r<r=rvZ
_sqla_typeZ_isnullZ_is_tuple_typeZ_is_table_valueZ    _is_arrayÚ_is_type_decoratorZrender_bind_castZrender_literal_castrr    r9ryZhashabler{rSr}rrÚ
EMPTY_DICTr€rƒrr‹rŒrr’r—ršÚmemoized_propertyrr r¡r£Ú staticmethodr§r¬r±Úpropertyr´r½r¾rÂZro_memoized_propertyrÈrÍrÓrØrÙrÜrÞràrárårÖrærír r†rúrûrþrxrürrr?r?r?r@r^wsŒ
 
þN 
þ
2%$%- 0 
    B2  (      r^c@szeZdZdZdZervejddœdd„ƒZe    ddd    d
œd d „ƒZ
e    d ddd
œdd „ƒZ
dddd
œdd „Z
dddœdd„Z dS)rÄzJclasses which subclass this can act as "mixin" classes for
    TypeEngine.r?rêrbcCsdSrFr?rdr?r?r@rítsz!TypeEngineMixin._static_cache_keyròrr7rócKsdSrFr?rõr?r?r@r†zszTypeEngineMixin.adaptrör8cKsdSrFr?rõr?r?r@r†~sr÷cKsdSrFr?rõr?r?r@r†„sr.rŽcCsdSrFr?rr?r?r@r؉szTypeEngineMixin.dialect_implN) r;r<r=rvrwrrrrír r†rØr?r?r?r@rÄlsrÄcs:eZdZUdZdZded<ejddœ‡fdd„ ƒZ‡Z    S)    Ú ExternalTypeaˆmixin that defines attributes and behaviors specific to third-party
    datatypes.
 
    "Third party" refers to datatypes that are defined outside the scope
    of SQLAlchemy within either end-user application code or within
    external extensions to SQLAlchemy.
 
    Subclasses currently include :class:`.TypeDecorator` and
    :class:`.UserDefinedType`.
 
    .. versionadded:: 1.4.28
 
    NrˆÚcache_okrêrbcsn|jj dd¡}|dkrZ|jjD]}t|jkr q@q |jjd}tjd|j|fddn|dkrjt    ƒj
St S)Nr    raZ%s %r will not produce a cache key because the ``cache_ok`` attribute is not set to True.  This can have significant performance implications including some performance degradations in comparison to prior SQLAlchemy versions.  Set this attribute to True if this type object's state is safe to use in a cache key, or False to disable this warning.Zcprf)ÚcodeT) r‡rëÚgetrÃrrÅrÚwarnr;Úsuperrír)rHr    Úsubtype©r‡r?r@rí%s 
 úø
zExternalType._static_cache_key)
r;r<r=rvr    rSrZnon_memoized_propertyríÚ __classcell__r?r?rr@rs
 
 
rc@s*eZdZdZdZdZddddœdd    „Zd
S) ÚUserDefinedTypeaÙBase for user defined types.
 
    This should be the base of new types.  Note that
    for most cases, :class:`.TypeDecorator` is probably
    more appropriate::
 
      import sqlalchemy.types as types
 
      class MyType(types.UserDefinedType):
          cache_ok = True
 
          def __init__(self, precision = 8):
              self.precision = precision
 
          def get_col_spec(self, **kw):
              return "MYTYPE(%s)" % self.precision
 
          def bind_processor(self, dialect):
              def process(value):
                  return value
              return process
 
          def result_processor(self, dialect, coltype):
              def process(value):
                  return value
              return process
 
    Once the type is made, it's immediately usable::
 
      table = Table('foo', metadata_obj,
          Column('id', Integer, primary_key=True),
          Column('data', MyType(16))
          )
 
    The ``get_col_spec()`` method will in most cases receive a keyword
    argument ``type_expression`` which refers to the owning expression
    of the type as being compiled, such as a :class:`_schema.Column` or
    :func:`.cast` construct.  This keyword is only sent if the method
    accepts keyword arguments (e.g. ``**kw``) in its argument signature;
    introspection is used to check for this in order to support legacy
    forms of this function.
 
    The :attr:`.UserDefinedType.cache_ok` class-level flag indicates if this
    custom :class:`.UserDefinedType` is safe to be used as part of a cache key.
    This flag defaults to ``None`` which will initially generate a warning
    when the SQL compiler attempts to generate a cache key for a statement
    that uses this type.  If the :class:`.UserDefinedType` is not guaranteed
    to produce the same bind/result behavior and SQL generation
    every time, this flag should be set to ``False``; otherwise if the
    class produces the same behavior each time, it may be set to ``True``.
    See :attr:`.UserDefinedType.cache_ok` for further notes on how this works.
 
    .. versionadded:: 1.4.28 Generalized the :attr:`.ExternalType.cache_ok`
       flag so that it is available for both :class:`.TypeDecorator` as well
       as :class:`.UserDefinedType`.
 
    Z user_definedZ get_col_specrørr8rùcCs|S)a€Suggest a type for a 'coerced' Python value in an expression.
 
        Default behavior for :class:`.UserDefinedType` is the
        same as that of :class:`.TypeDecorator`; by default it returns
        ``self``, assuming the compared value should be coerced into
        the same type as this one.  See
        :meth:`.TypeDecorator.coerce_compared_value` for more detail.
 
        r?©rHrhrDr?r?r@rúƒs z%UserDefinedType.coerce_compared_valueN)r;r<r=rvÚ__visit_name__Z ensure_kwargrúr?r?r?r@rBs:rcsveZdZUdZded<ddddœ‡fdd    „ Zed
dd d œd d„ƒZedddd œdd„ƒZdddd œ‡fdd„ Z‡ZS)ÚEmulateda±Mixin for base types that emulate the behavior of a DB-native type.
 
    An :class:`.Emulated` type will use an available database type
    in conjunction with Python-side routines and/or database constraints
    in order to approximate the behavior of a database type that is provided
    natively by some backends.  When a native-providing backend is in
    use, the native version of the type is used.  This native version
    should include the :class:`.NativeForEmulated` mixin to allow it to be
    distinguished from :class:`.Emulated`.
 
    Current examples of :class:`.Emulated` are:  :class:`.Interval`,
    :class:`.Enum`, :class:`.Boolean`.
 
    .. versionadded:: 1.2.0b3
 
    r~Únativer÷rr8)Úimpltyper…rEc stƒj|f|ŽS)a Given an impl class, adapt this type to the impl assuming
        "emulated".
 
        The impl should also be an "emulated" version of this type,
        most likely the same class as this type itself.
 
        e.g.: sqltypes.Enum adapts to the Enum class.
 
        )r r†)rHrr…rr?r@Úadapt_to_emulated§szEmulated.adapt_to_emulatedròr7rócKsdSrFr?rõr?r?r@r†·szEmulated.adaptröcKsdSrFr?rõr?r?r@r†»sc sZt|ƒr,|jr|j|f|ŽS|j|f|ŽSn*t||jƒrF|j|f|ŽStƒj|f|ŽSdSrF)    Ú_is_native_for_emulatedrÚadapt_emulated_to_nativeÚadapt_native_to_emulatedrÆr‡rr r†rõrr?r@r†¿s )    r;r<r=rvrSrr r†rr?r?rr@r“s
rr÷z"TypeGuard[Type[NativeForEmulated]])r‚rEcCs
t|dƒS)Nr)Úhasattr)r‚r?r?r@rÓsrc@s<eZdZdZeddddœdd„ƒZeddddœdd    „ƒZd
S) ÚNativeForEmulatedzgIndicates DB-native types supported by an :class:`.Emulated` type.
 
    .. versionadded:: 1.2.0b3
 
    z'Union[TypeEngine[Any], TypeEngineMixin]rr8)rPr…rEcKs|j}|j|f|ŽS)zZGiven an impl, adapt this type's class to the impl assuming
        "emulated".
 
 
        )r‡r†)rôrPr…rr?r?r@ràs z*NativeForEmulated.adapt_native_to_emulatedcKs
|f|ŽS)aGiven an impl, adapt this type's class to the impl assuming
        "native".
 
        The impl will be an :class:`.Emulated` class but not a
        :class:`.NativeForEmulated`.
 
        e.g.: postgresql.ENUM produces a type given an Enum instance.
 
        r?)rôrPr…r?r?r@rîsz*NativeForEmulated.adapt_emulated_to_nativeN)r;r<r=rvÚ classmethodrrr?r?r?r@rÙs
 rcsheZdZUdZdZdZded<ejddœdd    „ƒZ    d
d
d œd d „Z
e dƒfZ ded<Gdd„de jeƒZeddœdd„ƒZdddœdd„Zejddœdd„ƒZdldd d
d!d"œ‡fd#d$„ Zdd
d!d%œ‡fd&d'„ Zdddœd(d)„Zdddœd*d+„Zdddœd,d-„Zd.d
d/œd0d1„Zd2dd.d3œd4d5„Zd2dd
d3œd6d7„Zd8dd2d3œd9d:„Zejd dœd;d<„ƒZejd dœd=d>„ƒZdd?dœd@dA„Z ddBdœdCdD„Z!ejd dœdEdF„ƒZ"dd
dGdHœdIdJ„Z#ejd dœdKdL„ƒZ$dMdNdOœdPdQ„Z%ejd dœdRdS„ƒZ&dTdNdUœdVdW„Z'dXd
d
dYœdZd[„Z(d
d\d]œd^d_„Z)d`d8daœdbdc„Z*d
d
d ddœdedf„Z+edgdœdhdi„ƒZ,d.dœdjdk„Z-‡Z.S)mÚ TypeDecoratora°Allows the creation of types which add additional functionality
    to an existing type.
 
    This method is preferred to direct subclassing of SQLAlchemy's
    built-in types as it ensures that all required functionality of
    the underlying type is kept in place.
 
    Typical usage::
 
      import sqlalchemy.types as types
 
      class MyType(types.TypeDecorator):
          '''Prefixes Unicode values with "PREFIX:" on the way in and
          strips it off on the way out.
          '''
 
          impl = types.Unicode
 
          cache_ok = True
 
          def process_bind_param(self, value, dialect):
              return "PREFIX:" + value
 
          def process_result_value(self, value, dialect):
              return value[7:]
 
          def copy(self, **kw):
              return MyType(self.impl.length)
 
    The class-level ``impl`` attribute is required, and can reference any
    :class:`.TypeEngine` class.  Alternatively, the :meth:`load_dialect_impl`
    method can be used to provide different type classes based on the dialect
    given; in this case, the ``impl`` variable can reference
    ``TypeEngine`` as a placeholder.
 
    The :attr:`.TypeDecorator.cache_ok` class-level flag indicates if this
    custom :class:`.TypeDecorator` is safe to be used as part of a cache key.
    This flag defaults to ``None`` which will initially generate a warning
    when the SQL compiler attempts to generate a cache key for a statement
    that uses this type.  If the :class:`.TypeDecorator` is not guaranteed
    to produce the same bind/result behavior and SQL generation
    every time, this flag should be set to ``False``; otherwise if the
    class produces the same behavior each time, it may be set to ``True``.
    See :attr:`.TypeDecorator.cache_ok` for further notes on how this works.
 
    Types that receive a Python type that isn't similar to the ultimate type
    used may want to define the :meth:`TypeDecorator.coerce_compared_value`
    method. This is used to give the expression system a hint when coercing
    Python objects into bind parameters within expressions. Consider this
    expression::
 
        mytable.c.somecol + datetime.date(2009, 5, 15)
 
    Above, if "somecol" is an ``Integer`` variant, it makes sense that
    we're doing date arithmetic, where above is usually interpreted
    by databases as adding a number of days to the given date.
    The expression system does the right thing by not attempting to
    coerce the "date()" value into an integer-oriented bind parameter.
 
    However, in the case of ``TypeDecorator``, we are usually changing an
    incoming Python type to something new - ``TypeDecorator`` by default will
    "coerce" the non-typed side to be the same type as itself. Such as below,
    we define an "epoch" type that stores a date value as an integer::
 
        class MyEpochType(types.TypeDecorator):
            impl = types.Integer
 
            epoch = datetime.date(1970, 1, 1)
 
            def process_bind_param(self, value, dialect):
                return (value - self.epoch).days
 
            def process_result_value(self, value, dialect):
                return self.epoch + timedelta(days=value)
 
    Our expression of ``somecol + date`` with the above type will coerce the
    "date" on the right side to also be treated as ``MyEpochType``.
 
    This behavior can be overridden via the
    :meth:`~TypeDecorator.coerce_compared_value` method, which returns a type
    that should be used for the value of the expression. Below we set it such
    that an integer value will be treated as an ``Integer``, and any other
    value is assumed to be a date and will be treated as a ``MyEpochType``::
 
        def coerce_compared_value(self, op, value):
            if isinstance(value, int):
                return Integer()
            else:
                return self
 
    .. warning::
 
       Note that the **behavior of coerce_compared_value is not inherited
       by default from that of the base type**.
       If the :class:`.TypeDecorator` is augmenting a
       type that requires special logic for certain types of operators,
       this method **must** be overridden.  A key example is when decorating
       the :class:`_postgresql.JSON` and :class:`_postgresql.JSONB` types;
       the default rules of :meth:`.TypeEngine.coerce_compared_value` should
       be used in order to deal with operators like index operations::
 
            from sqlalchemy import JSON
            from sqlalchemy import TypeDecorator
 
            class MyJsonType(TypeDecorator):
                impl = JSON
 
                cache_ok = True
 
                def coerce_compared_value(self, op, value):
                    return self.impl.coerce_compared_value(op, value)
 
       Without the above step, index operations such as ``mycol['foo']``
       will cause the index value ``'foo'`` to be JSON encoded.
 
       Similarly, when working with the :class:`.ARRAY` datatype, the
       type coercion for index operations (e.g. ``mycol[5]``) is also
       handled by :meth:`.TypeDecorator.coerce_compared_value`, where
       again a simple override is sufficient unless special rules are needed
       for particular operators::
 
            from sqlalchemy import ARRAY
            from sqlalchemy import TypeDecorator
 
            class MyArrayType(TypeDecorator):
                impl = ARRAY
 
                cache_ok = True
 
                def coerce_compared_value(self, op, value):
                    return self.impl.coerce_compared_value(op, value)
 
 
    Ztype_decoratorTz-Union[TypeEngine[Any], Type[TypeEngine[Any]]]rPr8rbcCs|jSrF)rPrdr?r?r@Ú impl_instance¡szTypeDecorator.impl_instancer)ÚargsrjcOs.t|jdƒstdƒ‚t|jjf|ž|Ž|_dS)a Construct a :class:`.TypeDecorator`.
 
        Arguments sent here are passed to the constructor
        of the class assigned to the ``impl`` class level attribute,
        assuming the ``impl`` is a callable, and the resulting
        object is assigned to the ``self.impl`` instance attribute
        (thus overriding the class attribute of the same name).
 
        If the class level ``impl`` is not a callable (the unusual case),
        it will be assigned to the same instance attribute 'as-is',
        ignoring those arguments passed to the constructor.
 
        Subclasses can override this to customize the generation
        of ``self.impl`` entirely.
 
        rPzuTypeDecorator implementations require a class-level variable 'impl' which refers to the class of type being decoratedN)rr‡rçr¦rP)rHr rjr?r?r@rf¥s
 ÿzTypeDecorator.__init__NzSequence[Type[Any]]Úcoerce_to_is_typescsHeZdZdZdZdddddœ‡fdd„ Zdddddœ‡fd    d
„ Z‡ZS) zTypeDecorator.ComparatorzÉA :class:`.TypeEngine.Comparator` that is specific to
        :class:`.TypeDecorator`.
 
        User-defined :class:`.TypeDecorator` classes should not typically
        need to modify this.
 
 
        r?r$rrargcs8trt|jjtƒst‚|jjj|d<tƒj|f|ž|ŽS©NZ_python_is_types)    rrËr\r`rrçr!r ro©rHrhrirjrr?r@roÞsz TypeDecorator.Comparator.operatec s6trt|jjtƒst‚|jjj|d<tƒj||f|ŽSr")    rrËr\r`rrçr!r rqr#rr?r@rqæsz(TypeDecorator.Comparator.reverse_operate)r;r<r=rvrwrorqrr?r?rr@ryÒs    ryrzcCs2tj|jjjkr|jjStdtj|jjfiƒSdS)NZ TDComparator)rryrPr{rÃr`rdr?r?r@r{îs ýz TypeDecorator.comparator_factoryr.rÎrŽcCs||j|jkr | |j|j¡}n
| |¡}||k    r6|S| |¡ |¡}| ¡}t||jƒsltd||jfƒ‚||_    |_
|S)NzaType object %s does not properly implement the copy() method, it must return an object of type %s) rèr€réÚload_dialect_implrØrrËr‡rçrPr)rHr‰ÚadaptedZtypedescÚttr?r?r@ræýs" 
ÿ
 þÿ zTypeDecorator._gen_dialect_implzOptional[Type[TypeEngine[Any]]]cCs|jjSrF)rrÈrdr?r?r@rÈszTypeDecorator._type_affinityFrr~ÚNone)ÚparentÚouterr…rEc s8tƒ |¡|s4t|jtƒr4|jj|fddi|—ŽdS)úSupport SchemaEventTargetr)FN)r Ú _set_parentrËrr)rHr(r)r…rr?r@r+s zTypeDecorator._set_parent)r(r…rEc s4tƒj|fddi|—Žt|jtƒr0|j |¡dS)r*r)TN)r Ú_set_parent_with_dispatchrËrr)rHr(r…rr?r@r,#s z'TypeDecorator._set_parent_with_dispatchcCs*| |¡}t|t|ƒƒs|S| |¡SdS)asReturn a dialect-specific :class:`.TypeEngine` instance
        for this :class:`.TypeDecorator`.
 
        In most cases this returns a dialect-adapted form of
        the :class:`.TypeEngine` type represented by ``self.impl``.
        Makes usage of :meth:`dialect_impl`.
        Behavior can be customized here by overriding
        :meth:`load_dialect_impl`.
 
        N)rérËr`r$)rHr‰r%r?r?r@Ú type_engine-s
zTypeDecorator.type_enginecCs|jS)a¼Return a :class:`.TypeEngine` object corresponding to a dialect.
 
        This is an end-user override hook that can be used to provide
        differing types depending on the given dialect.  It is used
        by the :class:`.TypeDecorator` implementation of :meth:`type_engine`
        to help determine what type should ultimately be returned
        for a given :class:`.TypeDecorator`.
 
        By default returns ``self.impl``.
 
        )rrr?r?r@r$>s zTypeDecorator.load_dialect_implcCs.| |¡}t||jƒr&| |¡ |¡S|SdS)z‘Return the 'unwrapped' dialect impl for this type.
 
        This is used by the :meth:`.DefaultDialect.set_input_sizes`
        method.
 
        N)rØrËr‡r$)rHr‰r‚r?r?r@rÙLs    
 z%TypeDecorator._unwrapped_dialect_implrB)rârEcCs t|j|ƒS)zMProxy all other undefined accessors to the underlying
        implementation.)Úgetattrr)rHrâr?r?r@Ú __getattr__^szTypeDecorator.__getattr__ú Optional[_T])rDr‰rEcCs
tƒ‚dS)a•Receive a literal parameter value to be rendered inline within
        a statement.
 
        .. note::
 
            This method is called during the **SQL compilation** phase of a
            statement, when rendering a SQL string. Unlike other SQL
            compilation methods, it is passed a specific Python value to be
            rendered as a string. However it should not be confused with the
            :meth:`_types.TypeDecorator.process_bind_param` method, which is
            the more typical method that processes the actual value passed to a
            particular parameter at statement execution time.
 
        Custom subclasses of :class:`_types.TypeDecorator` should override
        this method to provide custom behaviors for incoming data values
        that are in the special case of being rendered as literals.
 
        The returned string will be rendered into the output string.
 
        Nr²©rHrDr‰r?r?r@Úprocess_literal_paramcsz#TypeDecorator.process_literal_paramcCs
tƒ‚dS)a|Receive a bound parameter value to be converted.
 
        Custom subclasses of :class:`_types.TypeDecorator` should override
        this method to provide custom behaviors for incoming data values.
        This method is called at **statement execution time** and is passed
        the literal Python data value which is to be associated with a bound
        parameter in the statement.
 
        The operation could be anything desired to perform custom
        behavior, such as transforming or serializing data.
        This could also be used as a hook for validating logic.
 
        :param value: Data to operate upon, of any type expected by
         this method in the subclass.  Can be ``None``.
        :param dialect: the :class:`.Dialect` in use.
 
        .. seealso::
 
            :ref:`types_typedecorator`
 
            :meth:`_types.TypeDecorator.process_result_value`
 
        Nr²r1r?r?r@Úprocess_bind_param|sz TypeDecorator.process_bind_paramr­cCs
tƒ‚dS)a[Receive a result-row column value to be converted.
 
        Custom subclasses of :class:`_types.TypeDecorator` should override
        this method to provide custom behaviors for data values
        being received in result rows coming from the database.
        This method is called at **result fetching time** and is passed
        the literal Python data value that's extracted from a database result
        row.
 
        The operation could be anything desired to perform custom
        behavior, such as transforming or deserializing data.
 
        :param value: Data to operate upon, of any type expected by
         this method in the subclass.  Can be ``None``.
        :param dialect: the :class:`.Dialect` in use.
 
        .. seealso::
 
            :ref:`types_typedecorator`
 
            :meth:`_types.TypeDecorator.process_bind_param`
 
 
        Nr²r1r?r?r@Úprocess_result_value—sz"TypeDecorator.process_result_valuecCst |tj¡S)zÖmemoized boolean, check if process_bind_param is implemented.
 
        Allows the base process_bind_param to raise
        NotImplementedError without needing to test an expensive
        exception throw.
 
        )rr¢rr3rdr?r?r@Ú_has_bind_processorµs
ÿz!TypeDecorator._has_bind_processorcCst |tj¡S)z@memoized boolean, check if process_literal_param is implemented.)rr¢rr2rdr?r?r@Ú_has_literal_processorÃsÿz$TypeDecorator._has_literal_processorrcsÖ|jr|j}d}n|jr$d}|j}nd}d}|dk    r„|j ˆ¡}|rf|‰|‰dddœ‡‡‡fdd„ }n|‰dddœ‡‡fdd„ }|S|dk    rÆ|j ˆ¡}|s dS|‰|‰dddœ‡‡‡fdd„ }|Sn |j ˆ¡SdS)    afProvide a literal processing function for the given
        :class:`.Dialect`.
 
        This is the method that fulfills the :class:`.TypeEngine`
        contract for literal value conversion which normally occurs via
        the :meth:`_types.TypeEngine.literal_processor` method.
 
        .. note::
 
            User-defined subclasses of :class:`_types.TypeDecorator` should
            **not** implement this method, and should instead implement
            :meth:`_types.TypeDecorator.process_literal_param` so that the
            "inner" processing provided by the implementing type is maintained.
 
        NrrBrCcsˆˆ|ˆƒƒSrFr?©rD)r‰Úfixed_impl_processorÚfixed_process_literal_paramr?r@rýñsÿz0TypeDecorator.literal_processor.<locals>.processcs
ˆ|ˆƒSrFr?r7)r‰r9r?r@rýùscsˆˆ|ˆƒƒSrFr?r7)r‰r8Úfixed_process_bind_paramr?r@rýsÿ)r6r2r5r3rr)rHr‰r2r3Úimpl_processorrýr?)r‰r8r:r9r@rËs4  zTypeDecorator.literal_processorr‘csl|jr\|j}|j ˆ¡}|r>|‰|‰dddœ‡‡‡fdd„ }n|‰dddœ‡‡fdd„ }|S|j ˆ¡SdS)a”Provide a bound value processing function for the
        given :class:`.Dialect`.
 
        This is the method that fulfills the :class:`.TypeEngine`
        contract for bound value conversion which normally occurs via
        the :meth:`_types.TypeEngine.bind_processor` method.
 
        .. note::
 
            User-defined subclasses of :class:`_types.TypeDecorator` should
            **not** implement this method, and should instead implement
            :meth:`_types.TypeDecorator.process_bind_param` so that the "inner"
            processing provided by the implementing type is maintained.
 
        :param dialect: Dialect instance in use.
 
        r0rrCcsˆˆ|ˆƒƒSrFr?r7©r‰r8Úfixed_process_paramr?r@rý*sÿz-TypeDecorator.bind_processor.<locals>.processcs
ˆ|ˆƒSrFr?r7)r‰r=r?r@rý2sN)r5r3rr’)rHr‰Z process_paramr;rýr?r<r@r’s zTypeDecorator.bind_processorcCst |tj¡S)zÚmemoized boolean, check if process_result_value is implemented.
 
        Allows the base process_result_value to raise
        NotImplementedError without needing to test an expensive
        exception throw.
 
        )rr¢rr4rdr?r?r@Ú_has_result_processor9s
ÿz#TypeDecorator._has_result_processorr”r•csp|jr^|j}|j ˆ|¡}|r@|‰|‰dddœ‡‡‡fdd„ }n|‰dddœ‡‡fdd„ }|S|j ˆ|¡SdS)aÈProvide a result value processing function for the given
        :class:`.Dialect`.
 
        This is the method that fulfills the :class:`.TypeEngine`
        contract for bound value conversion which normally occurs via
        the :meth:`_types.TypeEngine.result_processor` method.
 
        .. note::
 
            User-defined subclasses of :class:`_types.TypeDecorator` should
            **not** implement this method, and should instead implement
            :meth:`_types.TypeDecorator.process_result_value` so that the
            "inner" processing provided by the implementing type is maintained.
 
        :param dialect: Dialect instance in use.
        :param coltype: A SQLAlchemy data type
 
        rr0rCcsˆˆ|ƒˆƒSrFr?r7©r‰r8Úfixed_process_valuer?r@rýesÿz/TypeDecorator.result_processor.<locals>.processcs
ˆ|ˆƒSrFr?r7)r‰r@r?r@rýmsN)r>r4rr—)rHr‰r–Z process_valuer;rýr?r?r@r—GsÿzTypeDecorator.result_processorcCst |tj¡p|jjSrF)rr¢rr rr£rdr?r?r@r£tsþz"TypeDecorator._has_bind_expressionržr˜)Ú    bindparamrEcCs |j |¡S)a`Given a bind value (i.e. a :class:`.BindParameter` instance),
        return a SQL expression which will typically wrap the given parameter.
 
        .. note::
 
            This method is called during the **SQL compilation** phase of a
            statement, when rendering a SQL string. It is **not** necessarily
            called against specific values, and should not be confused with the
            :meth:`_types.TypeDecorator.process_bind_param` method, which is
            the more typical method that processes the actual value passed to a
            particular parameter at statement execution time.
 
        Subclasses of :class:`_types.TypeDecorator` can override this method
        to provide custom bind expression behavior for the type.  This
        implementation will **replace** that of the underlying implementation
        type.
 
        )rr )rHrAr?r?r@r |szTypeDecorator.bind_expressioncCst |tj¡p|jjSr›)rr¢rršrrrdr?r?r@r“s
þz$TypeDecorator._has_column_expressionr[)ÚcolumnrEcCs |j |¡S)a–Given a SELECT column expression, return a wrapping SQL expression.
 
        .. note::
 
            This method is called during the **SQL compilation** phase of a
            statement, when rendering a SQL string. It is **not** called
            against specific values, and should not be confused with the
            :meth:`_types.TypeDecorator.process_result_value` method, which is
            the more typical method that processes the actual value returned
            in a result row subsequent to statement execution time.
 
        Subclasses of :class:`_types.TypeDecorator` can override this method
        to provide custom column expression behavior for the type.  This
        implementation will **replace** that of the underlying implementation
        type.
 
        See the description of :meth:`_types.TypeEngine.column_expression`
        for a complete description of the method's use.
 
        )rrš)rHrBr?r?r@rš¡szTypeDecorator.column_expressionrørùcCs|S)a}Suggest a type for a 'coerced' Python value in an expression.
 
        By default, returns self.   This method is called by
        the expression system when an object using this type is
        on the left or right side of an expression against a plain Python
        object which does not yet have a SQLAlchemy type assigned::
 
            expr = table.c.somecolumn + 35
 
        Where above, if ``somecolumn`` uses this type, this method will
        be called with the value ``operator.add``
        and ``35``.  The return value is whatever SQLAlchemy type should
        be used for ``35`` for this particular operation.
 
        r?rr?r?r@rú»sz#TypeDecorator.coerce_compared_valuerr„cKs |j |j¡}|j |j¡|S)aGProduce a copy of this :class:`.TypeDecorator` instance.
 
        This is a shallow copy and is provided to fulfill part of
        the :class:`.TypeEngine` contract.  It usually does not
        need to be overridden unless the user-defined :class:`.TypeDecorator`
        has local state that should be deep-copied.
 
        )r‡Ú__new__rëÚupdate)rHr…Úinstancer?r?r@rÏs
zTypeDecorator.copyrr®cCs |j |¡S)zÃReturn the DBAPI type object represented by this
        :class:`.TypeDecorator`.
 
        By default this calls upon :meth:`.TypeEngine.get_dbapi_type` of the
        underlying "impl".
        )rr±r°r?r?r@r±ÝszTypeDecorator.get_dbapi_typer¨cCs|j ||¡S)a›Given two values, compare them for equality.
 
        By default this calls upon :meth:`.TypeEngine.compare_values`
        of the underlying "impl", which in turn usually
        uses the Python equals operator ``==``.
 
        This function is used by the ORM to compare
        an original-loaded value with an intercepted
        "changed" value, to determine if a net change
        has occurred.
 
        )rr¬r«r?r?r@r¬æs zTypeDecorator.compare_valuesr|cCs|jjSrF)rr}rdr?r?r@r}öszTypeDecorator.sort_key_functioncCstj||jdS)N)Z
to_inspect)rrrrdr?r?r@rúszTypeDecorator.__repr__)F)/r;r<r=rvrrrSrrrrfr`r!r^ryr9rr{ræZro_non_memoized_propertyrÈr+r,r-r$rÙr/r2r3r4r5r6rr’r>r—r£r rršrúrr±r¬r}rrr?r?rr@rs^
ÿ
 
 D* -     rc@s eZdZdZdddœdd„ZdS)ÚVariantzŠdeprecated.  symbol is present for backwards-compatibility with
    workaround recipes, however this actual type should not be used.
 
    r)Úargr…cOs tdƒ‚dS)NzbVariant is no longer used in SQLAlchemy; this is a placeholder symbol for backwards compatibility.r²)rHrGr…r?r?r@rf    sÿzVariant.__init__N)r;r<r=rvrfr?r?r?r@rFþsrFr)Ú
expressionrEcCs|jSrF)Z
comparator)rHr?r?r@rt     srtr¤)ÚtypeobjrGr…rEcOsdSrFr?©rIrGr…r?r?r@r¦    sr¦r'zTypeEngine[None]cOsdSrFr?rJr?r?r@r¦    szUnion[Type[_TE], _TE, None]zUnion[_TE, TypeEngine[None]]cOs&|dkr tSt|ƒr|||ŽS|SdSrF)r*ÚcallablerJr?r?r@r¦    s
 
z)Mapping[Type[Any], Type[TypeEngine[Any]]])rIÚcolspecsrEc    Cslt|tƒr|ƒ}|jjdd…D],}z||}WqRWq tk
rJYq Xq |St|j|ƒrb|S| |¡S)Nréÿÿÿÿ)rËr`r‡rÃrÕrÆr†)rIrLrÇrr?r?r@Ú
adapt_type%    s
 
 rN)ZrvÚ
__future__rÚenumrÚtypesrÚtypingrrrrr    r
r r r rrrrrrÚbaserÚ    cache_keyrrÚ    operatorsrZvisitorsrÚrrZ util.typingrrrr Ú_typingr!Úelementsr"r#r$Zsqltypesr%r&r'r(r)r*r+r,r-Zengine.interfacesr.r/r0r2r4r“r6r7r9r¿r:r>Z_NO_VALUE_IN_LISTrArKrLrNrOrTrZr^rÄrZ EnsureKWArgrrrrrrFrtr¦rNr?r?r?r@Ú<module>sÀ                                                |!6
ÿQ@/{