ok

Mini Shell

Direktori : /opt/alt/python38/lib64/python3.8/site-packages/playhouse/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/site-packages/playhouse/__pycache__/reflection.cpython-38.pyc

U

S��WUU� @s�zddlmZWnek
r(eZYnXddlmZddlZddlTzddlmZWn>ek
r�zddl	mZWnek
r�dZYnXYnXzddl
mZWnek
r�dZYnXeddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%g�Z
Gd&d'�d'e�ZGd(d)�d)e�ZGd*d+�d+e�ZGd,d-�d-e�ZGd.d/�d/e�ZGd0d1�d1e�Zed2d3�ZGd4d5�d5e�ZGd6d7�d7e�Zd:d8d9�ZdS);�)�OrderedDict)�
namedtupleN)�*)�
FIELD_TYPE)�postgres_ext�and�as�assert�break�class�continue�def�del�elif�else�except�exec�finally�for�from�global�if�import�in�is�lambda�not�or�pass�print�raise�return�try�while�with�yieldc@seZdZdS)�UnknownFieldN)�__name__�
__module__�__qualname__�r*r*�/reflection.pyr&sr&c@s\eZdZdZeefZddd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zddd�Z
dd�ZdS)�Columnz1
    Store metadata about a database column.
    FNc		CsF||_||_||_||_||_||_||_||_d|_d|_	d|_
dS�N)�name�field_class�raw_column_type�nullable�primary_key�	db_column�index�unique�	rel_model�related_name�to_field)	�selfr.r/r0r1r2r3r4r5r*r*r+�__init__'szColumn.__init__cs4dddddg}d��fdd�|D��}d	�j|fS)
Nr/r0r1r2r3�, c3s |]}d|t�|�fVqdS�z%s=%sN)�getattr)�.0�attr�r9r*r+�	<genexpr>>s�z"Column.__repr__.<locals>.<genexpr>zColumn(%s, %s))�joinr.)r9�attrsZkeyword_argsr*r@r+�__repr__7s��zColumn.__repr__cCs�i}|jrd|d<|jtks(|j|jkr6d|j|d<|jrN|jtk	rNd|d<|��r�|j|d<|j	rtd|j	|d<|j
r�d|j
|d<|��s�|jr�d	|d
<n|j
r�|��s�d	|d<|S)NT�nullz'%s'r3r2r6r8r7�Truer5r4)r1r/�ForeignKeyFieldr.r3r2�PrimaryKeyField�is_foreign_keyr6r8r7�is_primary_keyr5r4)r9�paramsr*r*r+�get_field_parametersCs&

zColumn.get_field_parameterscCs|jtkp|jSr-)r/rHr2r@r*r*r+rJ_szColumn.is_primary_keycCs
|jtkSr-)r/rGr@r*r*r+rIbszColumn.is_foreign_keycCs|jtko|jdkS�Nz'self')r/rGr6r@r*r*r+�is_self_referential_fkes
�zColumn.is_self_referential_fkcCsJ||_t|_|j|jkr d|_n||j|_|r6|jp8d|_|pBd|_dSrM)	�foreign_keyrGr/�
dest_table�tabler6r.r8r7)r9rO�model_names�destr7r*r*r+�set_foreign_keyiszColumn.set_foreign_keycCsT|��}d�dd�t|���D��}d|j|jj|f}|jtkrPd||jf}|S)Nr;css|]\}}d||fVqdSr<r*)r>�k�vr*r*r+rAws�z#Column.get_field.<locals>.<genexpr>z%s = %s(%s)z%s  # %s)	rLrB�sorted�itemsr.r/r'r&r0)r9Zfield_paramsZ	param_str�fieldr*r*r+�	get_fieldts

��
zColumn.get_field)FNFF)NN)r'r(r)�__doc__�IntegerFieldrHZprimary_key_typesr:rDrLrJrIrNrTrZr*r*r*r+r,!s �
�
r,c@sVeZdZiZdZdd�Zdd�Zddd�Zdd	d
�Zddd�Z	dd
d�Z
ddd�ZdS)�Metadata�cCs||_d|_dS)NF)�database�requires_extension)r9r_r*r*r+r:�szMetadata.__init__cGs|j�||�Sr-)r_Zexecute_sql)r9ZsqlrKr*r*r+�execute�szMetadata.executeNc
	Cs�tdd�|j�||�D��}|�||�}|�||�}t|�dkr\|d}||tkr\t||<t�}|��D]*\}}	t	||||	j
|	j|	j|d�||<qj|S)Ncss|]}|j|fVqdSr-�r.)r>�metadatar*r*r+rA�s�z'Metadata.get_columns.<locals>.<genexpr>�r)r/r0r1r2r3)
rr_�get_columns�get_column_types�get_primary_keys�lenr\rHrXr,�	data_typerEr2)
r9rQ�schemarc�column_typesZpk_namesZpk�columnsr.Zcolumn_datar*r*r+re�s(��zMetadata.get_columnscCst�dSr-)�NotImplementedError�r9rQrjr*r*r+rf�szMetadata.get_column_typescCs|j�||�Sr-)r_�get_foreign_keysrnr*r*r+ro�szMetadata.get_foreign_keyscCs|j�||�Sr-)r_rgrnr*r*r+rg�szMetadata.get_primary_keyscCs|j�||�Sr-)r_�get_indexesrnr*r*r+rp�szMetadata.get_indexes)N)N)N)N)N)r'r(r)�
column_map�extension_importr:rarerfrorgrpr*r*r*r+r]�s



r]cs�eZdZeeeeeeeee	e	e
eeeee
ed�ZdZ�fdd�Zdd�Zd�fdd	�	Zd�fd
d�	Zd�fdd
�	Zd�fdd�	Z�ZS)�PostgresqlMetadata)������i�i�iii:iZi�i;i�i�i�z$from playhouse.postgres_ext import *cs|tt|��|�tdk	rx|�d�}|��}|D]H\}}d|krLtj|j|<q.d|krbtj|j|<q.d|kr.tj	|j|<q.dS)Nz!select oid, typname from pg_type;ZjsonZhstoreZtsvector)
�superrsr:rraZfetchall�	JSONFieldrq�HStoreField�
TSVectorField)r9r_�cursor�resultsZoidZtypname��	__class__r*r+r:�s
zPostgresqlMetadata.__init__cCszi}tdk	r ttjtjtjf�nt�}d||f}|�d|�}|jD].}|j�|j	t
�||j<||j|krFd|_qF|S)Nz	"%s"."%s"zSELECT * FROM %s LIMIT 1T)
r�setr{r}r|ra�descriptionrq�get�	type_coder&r.r`)r9rQrjrkZextension_typesZ
identifierr~�column_descriptionr*r*r+rf�s&���
�
z#PostgresqlMetadata.get_column_typesNcs|pd}tt|��||�S�NZpublic)rzrsrernr�r*r+re�szPostgresqlMetadata.get_columnscs|pd}tt|��||�Sr�)rzrsrornr�r*r+ro�sz#PostgresqlMetadata.get_foreign_keyscs|pd}tt|��||�Sr�)rzrsrgrnr�r*r+rg�sz#PostgresqlMetadata.get_primary_keyscs|pd}tt|��||�Sr�)rzrsrprnr�r*r+rp�szPostgresqlMetadata.get_indexes)N)N)N)N)r'r(r)�BooleanField�	BlobField�BigIntegerFieldr\�	TextField�
FloatField�	CharField�	DateField�
DateTimeField�	TimeField�DecimalFieldrqrrr:rfrerorgrp�
__classcell__r*r*r�r+rs�s2�rsc(s�eZdZedkriZn|ejeejeej	e
ejeej
eejeejeejeejeejeejeejeejeejeejeejeejeejeej eej!eiZ�fdd�Z"ddd�Z#�Z$S)�
MySQLMetadataNcs.d|kr|�d�|d<tt|�j|f|�dS)NZpasswordZpasswd)�poprzr�r:)r9r_�kwargsr�r*r+r:szMySQLMetadata.__init__cCsDi}|�d|�}|jD]&}|dd�\}}|j�|t�||<q|S)NzSELECT * FROM `%s` LIMIT 1�)rar�rqr�r&)r9rQrjrkr~r�r.r�r*r*r+rf#s
zMySQLMetadata.get_column_types)N)%r'r(r)rrqZBLOBr�ZCHARr�ZDATEr�ZDATETIMEr�ZDECIMALr�ZDOUBLEr�ZFLOATZINT24r\Z	LONG_BLOBZLONGZLONGLONGr�ZMEDIUM_BLOBZ
NEWDECIMALZSHORT�STRING�	TIMESTAMPZTIMEr�Z	TINY_BLOBZTINYZ
VAR_STRINGr:rfr�r*r*r�r+r�sZ�r�c@sbeZdZeeeeeeee	e
e
e
eee
e
e
ee
d�ZdZdZdjeed�ZdZdd�Zdd
d�Zd	S)
�SqliteMetadata)ZbigintZblob�boolZboolean�char�dateZdatetimeZdecimalZintegerzinteger unsigned�intZlong�realZsmallintegerZsmallintzsmallint unsigned�text�timez
(?:["\[\(]+)?z
(?:["\]\)]+)?zi(?:FOREIGN KEY\s*)?{begin}(.+?){end}\s+(?:.+\s+)?references\s+{begin}(.+?){end}\s*\(["|\[]?(.+?)["|\]]?\))�begin�endz&^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$cCsR|��}||jkr|j|}n0t�|j|�r2t}nt�dd|�}|j�|t�}|S)Nz\(.+\)r^)	�lowerrq�re�search�
re_varcharr��subr�r&)r9Zcolumn_typer0r/r*r*r+�_map_colPs
zSqliteMetadata._map_colNcCs0i}|j�|�}|D]}|�|j�||j<q|Sr-)r_rer�rir.)r9rQrjrkrl�columnr*r*r+rf[s
zSqliteMetadata.get_column_types)N)r'r(r)r�r�r�r�r�r�r�r\r�r�r�rqr�r��formatZre_foreign_keyr�r�rfr*r*r*r+r�1s:���r��_DatabaseMetadata)rl�primary_keys�foreign_keysrR�indexesc@seZdZdd�Zdd�ZdS)�DatabaseMetadatacsLg}�j�D]8}t|j�dkr��fdd�|jD�}|�||jf�q|S)Nrdcs*g|]"}|�j�kr�j�|j�qSr*)rlr.)r>r��r9rQr*r+�
<listcomp>rs�z9DatabaseMetadata.multi_column_indexes.<locals>.<listcomp>)r�rhrl�appendr5)r9rQ�accumr4�field_namesr*r�r+�multi_column_indexesns�z%DatabaseMetadata.multi_column_indexescCs6i}|j|D]"}t|j�dkr|j||jd<q|S)Nrdr)r�rhrlr5)r9rQr�r4r*r*r+�column_indexesxs
zDatabaseMetadata.column_indexesN)r'r(r)r�r�r*r*r*r+r�ms
r�c@sxeZdZeegZddd�Zdd�Zeddd��Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zddd�Zddd�ZdS)�IntrospectorNcCs||_||_dSr-)rcrj)r9rcrjr*r*r+r:�szIntrospector.__init__cCsd|jjS)Nz<Introspector: %s>�rcr_r@r*r*r+rD�szIntrospector.__repr__cCs<t|t�rt|�}nt|t�r(t|�}nt|�}|||d�S�N�rj)�
isinstanceZPostgresqlDatabasersZ
MySQLDatabaser�r�)�clsr_rjrcr*r*r+�
from_database�s



zIntrospector.from_databasecCst|jj�Sr-)�typercr_r@r*r*r+�get_database_class�szIntrospector.get_database_classcCs
|jjjSr-r�r@r*r*r+�get_database_name�szIntrospector.get_database_namecCs
|jjjSr-)rcr_Zconnect_kwargsr@r*r*r+�get_database_kwargs�sz Introspector.get_database_kwargscCs|jjrd|jjSdS)N�
r^)rcr`rrr@r*r*r+�get_additional_imports�sz#Introspector.get_additional_importscCs@t�dd|�}d�dd�|�d�D��}|d��s<d|}|S)N�[^\w]+r^css|]}|��VqdSr-)�title)r>r�r*r*r+rA�sz/Introspector.make_model_name.<locals>.<genexpr>�_r�T)r�r�rB�split�isalpha)r9rQ�modelZ
model_namer*r*r+�make_model_name�s
zIntrospector.make_model_namecCs@t�dd|�����p|��}t�dd|�}|tkr<|d7}|S)Nz_id$r^r�r�)r�r�r��strip�RESERVED_WORDS)r9r�r*r*r+�make_column_name�s
zIntrospector.make_column_namecs�|jr|jjj|jd�}n|jj��}�dk	r@�fdd�|D�}i}i}i}i}i}|D�]D}|j�||j�}	|j�||j�}
z|j�||j�||<Wn4tk
r�}zt|j	�g||<W5d}~XYnX|�
|�||<tdd�|
D��}|
��D]>\}
}|�
|
�}|
��}|�d��r,||k�r,|
��}||_q�|	D]@}t|j�dk�r8|jd}||
k�r8|j|
|_d	|
|_�q8|j�||j�||<|
||<|	||<qXi}d
d�}|D]�}t�}t|||d�D]d}z|||j}Wntk
�r�Y�q�YnX|j}||k�r"d
||jf||<n
|�|��qʐq�|D]n}||D]^}||j|j}z||j|j}Wntk
�r�d}YnX|j||||�|�d��qD�q8t|||||�S)Nr�csg|]}|�kr|�qSr*r*)r>rQ��table_namesr*r+r��sz+Introspector.introspect.<locals>.<listcomp>css|]}|��VqdSr-)r�)r>Zcolumn_namer*r*r+rA�s�z*Introspector.introspect.<locals>.<genexpr>Z_idrdrTcSs|jSr-)r�)rOr*r*r+�<lambda>��z)Introspector.introspect.<locals>.<lambda>)�keyz	%s_%s_set)rOrRrSr7) rjrcr_Z
get_tablesrprero�
ValueError�err�argsr�r�rXr�r��endswithr.rhrlr5r4rgrWr��KeyErrorrP�addrQZdest_columnrTr�r�)r9r�Ztablesrlr�r�rRr�rQZ
table_indexesZ
table_columns�excZlower_col_namesZcol_namer��new_nameZ
lower_namer4Z
related_namesZsort_fnZmodels_referencedrOrP�srcrSr*r�r+�
introspect�s�
�
�


�

��
��zIntrospector.introspectFcsd�j|d��i}G�fdd�dt������fdd��t�j���D]\}}||krD�||�qD|S)Nr�cseZdZG�fdd�d�ZdS)z/Introspector.generate_models.<locals>.BaseModelcseZdZ�jjZdS)z4Introspector.generate_models.<locals>.BaseModel.MetaN)r'r(r)rcr_r*r@r*r+�Meta!sr�N)r'r(r)r�r*r@r*r+�	BaseModel sr�cs"�j|D]$}|j}||kr
||kr
�||�q
g��j|}|��D]\}}|jrF��|j�qF��|����|�}G�fdd�d�}d}	t	��dkr�|�
��t	��dkr�t�fdd�|��D��|_d}	d|i}
|��D�]\}}|j}|t
kr�t}||jd	�}|j�r*|	�r*|tk�r t}d|d
<n|j�rD|tk	�rDd|d
<|���r�|���rbd|d<n|jj}
||
|d<|j�r�|j|d
<d||f|d<||k�r�|���s�||�r�d|d<n|���s�d|d<|f|�|
|j<q�ztt|��f|
�||<Wntk
�r��s�YnXdS)NcseZdZ�ZdS)zAIntrospector.generate_models.<locals>._create_model.<locals>.MetaN)r'r(r)r�r*)r�r*r+r�4sr�Frrdcsg|]\}}|�kr|j�qSr*rb)r>�colrY)r�r*r+r�<s�zGIntrospector.generate_models.<locals>._create_model.<locals>.<listcomp>T)r3rEr2r9r6r8z	%s_%s_relr7r5r4)r�rPrlrXr2r�r.r�r�rh�keysZCompositeKeyr/r&Z	BareFieldr1rHr\rIrNrOr8rJr��strr�)rQ�modelsrOrSrlr3r�r�r�Z
composite_keyrCZ
FieldClassrKrP)r��
_create_modelr_�skip_invalid)r�r�r+r�$sj


�
�








z3Introspector.generate_models.<locals>._create_model)r�ZModelrWrRrX)r9r�r�r�rQr�r*)r�r�r_r9r�r+�generate_modelssFzIntrospector.generate_models)N)N)N)FN)r'r(r)rHr\Z
pk_classesr:rD�classmethodr�r�r�r�r�r�r�r�r�r*r*r*r+r��s
	
lr�cCstj||d�}|��Sr�)r�r�r�)r_rjZintrospectorr*r*r+r�qsr�)N)�collectionsr�ImportError�dictrr�ZpeeweeZMySQLdb.constantsrZpymysql.constantsZ	playhouserr�r��objectr&r,r]rsr�r�r�r�r�r�r*r*r*r+�<module>sz

�c3L.4
r

Zerion Mini Shell 1.0