Viewing File: /opt/alt/python38/lib64/python3.8/site-packages/playhouse/__pycache__/shortcuts.cpython-38.pyc

U

SW#@sddlZddlTddlmZejddkr>ddlmZddZddd	Zd
dZdd
Z	dddZ
dddZGdddeZ
dS)N)*)Node)CallablecCs
t|tSN)
isinstancer)cr	
/shortcuts.py<lambda>rcCsxtdg}|dk	}|r |||D]"\}}|td|td|fq$|dk	rb|td|f|tdt|S)a&
    CASE statement builder.

    Example CASE statements:

        SELECT foo,
            CASE
                WHEN foo = 1 THEN "one"
                WHEN foo = 2 THEN "two"
                ELSE "?"
            END -- will be in column named "case" in postgres --
        FROM bar;

        -- equivalent to above --
        SELECT foo,
            CASE foo
                WHEN 1 THEN "one"
                WHEN 2 THEN "two"
                ELSE "?"
            END

    Corresponding peewee:

        # No predicate, use expressions.
        Bar.select(Bar.foo, case(None, (
            (Bar.foo == 1, "one"),
            (Bar.foo == 2, "two")), "?"))

        # Predicate, will test for equality.
        Bar.select(Bar.foo, case(Bar.foo, (
            (1, "one"),
            (2, "two")), "?"))
    ZCASENZWHENZTHENELSEZEND)SQLappendextendClause)Z	predicateZexpression_tuplesdefaultZclausesZsimple_caseexprvaluer	r	r
cases"

rcCstt|td|S)NzAS %s)fnZCASTrr)ZnodeZas_typer	r	r
cast<srcCs|rt|StSr)set)sr	r	r

_clone_set@srTFc	Cs|dkrdn|}|dkrd}t|}t|}|dk	rr|jD]6}	t|	trT||	q:t|	tr:|	jr:||	jq:i}
t|}t|}||O}t|}|jj	D]}||ks|r||krq|j
|j}
t|t
r|r|
r||t||j}t|||||||dd}
ni}
|
|
|j<q|rZ|D].}t||}t|rN||
|<n||
|<q*|r|r|jjD]\}}t||}||ksr||krqr|r||kr||krqrg}||t||dt||}|D]$}|t||||||ddq||
|<qr|
S)	a
    Convert a model instance (and any related objects) to a dictionary.

    :param bool recurse: Whether foreign-keys should be recursed.
    :param bool backrefs: Whether lists of related objects should be recursed.
    :param only: A list (or set) of field instances indicating which fields
        should be included.
    :param exclude: A list (or set) of field instances that should be
        excluded from the dictionary.
    :param list extra_attrs: Names of model instance attributes or methods
        that should be included.
    :param SelectQuery fields_from_query: Query that was source of model. Take
        fields explicitly selected by the query and serialize them.
    :param int max_depth: Maximum depth to recurse, value <= 0 means no max.
    NrF)recursebackrefsonlyexcludeseen	max_depthZ	_prefetch)rrrr r")rZ_selectrZFieldaddrZ_aliastype_metaZdeclared_fields_datagetnameForeignKeyFieldgetattr
model_to_dictcallablereverse_relitemsr)Zmodelrrrr r!Zextra_attrsZfields_from_queryr"itemdatamodel_classfieldZ
field_dataZrel_objZ	attr_nameattrrelated_nameZforeign_keyZ
descriptorZaccumZ
related_queryr	r	r
r+Es


	



r+cs|}|j}|D]\}}||jkr6|j|d}n@||jjkrR|j|d}n$rft|||qntd||ftt}|s|rt|trt|j	t
j|q|rt|tt
frfdd|D}	|	D]}
t|
j	|qt|j|	qt|j	|q|S)NFTz/Unrecognized attribute "%s" for model class %s.csg|]}tj|qSr	)
dict_to_modelr1).0Zrow_datar2ignore_unknownr	r

<listcomp>sz!dict_to_model.<locals>.<listcomp>)r%r.Zfieldsr-setattrAttributeErrorrr)dictr(r5Z	rel_modellisttupler4)r1r0r8instancemetakeyrZ
is_backrefZis_foreign_keyZ	instancesZrel_instancer	r7r
r5s>



r5cseZdZdfdd	ZZS)RetryOperationalErrorNTcsztt||||}Wndtk
r||s8||2|}|||pVd|rn|	rn|
W5QRXYnX|S)Nr	)superrBexecute_sqlZOperationalErrorZ	is_closedcloseZexception_wrapperZ
get_cursorZexecuteZget_autocommitZcommit)selfZsqlZparamsZrequire_commitZcursor	__class__r	r
rDs

z!RetryOperationalError.execute_sql)NT)__name__
__module____qualname__rD
__classcell__r	r	rGr
rBsrB)N)TFNNNNNN)F)sysZpeeweerversion_infocollectionsrr,rrrr+r5objectrBr	r	r	r
<module>s"
1
a
(
Back to Directory File Manager