Viewing File: /opt/alt/python35/lib64/python3.5/site-packages/playhouse/__pycache__/shortcuts.cpython-35.pyc



R6W#
@sddlZddlTddlmZejddkrUddlmZddZddd	Zd
dZdd
Z	ddddddddddZ
dddZGdddeZ
dS)N)*)Node)CallablecCs
t|tS)N)
isinstancer)cr
/shortcuts.py<lambda>sr
cCstdg}|dk	}|r.|j|x9|D]1\}}|jtd|td|fq5W|dk	r|jtd|f|jtdt|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)	predicateZexpression_tuplesdefaultZclausesZsimple_caseexprvaluerrr	cases"
)rcCs tjt|td|S)NzAS %s)fnZCASTrr)ZnodeZas_typerrr	cast<srcCs|rt|StS)N)set)srrr	
_clone_set@s
rTFc	Cs|dkrdn|}|dkr*d}t|}t|}|dk	rxX|jD]M}	t|	tr}|j|	qXt|	trX|	jrX|j|	jqXWi}
t|}t|}||O}t|}x|jj	D]}||ks|r||krq|j
j|j}
t|t
r|r|
r|j|t||j}t|d|d|d|d|d	|d
|d}
ni}
|
|
|j<qW|rxC|D];}t||}t|r||
|<q||
|<qW|r|rx|jjjD]\}}t||}||ks||krOq|rp||krp||krpqg}|j|t||dt||}xC|D];}|jt|d|d|d|d|d
|dqW||
|<qW|
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.
    NrFrecursebackrefsonlyexcludeseen	max_depthZ	_prefetch)r_selectrZFieldaddrZ_aliastype_metaZdeclared_fields_datagetnameForeignKeyFieldgetattr
model_to_dictcallablereverse_relitemsr
)ZmodelrrrrrZextra_attrsZfields_from_queryr itemdatamodel_classfieldZ
field_dataZrel_objZ	attr_nameattrrelated_nameZforeign_keyZ
descriptorZaccumZ
related_queryrrr	r+Es~




	r+cs|}|j}xm|jD]_\}}||jkrP|j|d}nZ||jjkrx|j|d}n2rt|||qntd||ftt}|r|rt|trt|j	t
j|q|rkt|tt
frkfdd|D}	x!|	D]}
t|
j	|q8Wt|j|	qt|j	|qW|S)NFTz/Unrecognized attribute "%s" for model class %s.cs%g|]}tj|qSr)
dict_to_modelr1).0Zrow_data)r2ignore_unknownrr	
<listcomp>s	z!dict_to_model.<locals>.<listcomp>)r%r.Zfieldsr-setattrAttributeErrorrr)dictr(r5Z	rel_modellisttupler4)r1r0r7instancemetakeyrZ
is_backrefZis_foreign_keyZ	instancesZrel_instancer)r2r7r	r5s8		
	
	

r5cs(eZdZddfddZS)RetryOperationalErrorNTcsy"tt|j|||}Wnztk
r|jsH|j|jC|j}|j||psf|r|j	r|j
WdQRXYnX|S)N)superrAexecute_sqlZOperationalErrorZ	is_closedcloseZexception_wrapperZ
get_cursorZexecuteZget_autocommitZcommit)selfZsqlZparamsZrequire_commitZcursor)	__class__rr	rCs


z!RetryOperationalError.execute_sql)__name__
__module____qualname__rCrr)rFr	rAsrA)sysZpeeweerversion_infocollectionsrr,rrrr+r5objectrArrrr	<module>s
1		_(
Back to Directory File Manager