
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
U
    SW#                     @   s   d dl Z d dlT d dlmZ e jd  dkr>d dlmZ dd Zddd	Zd
d Zdd Z	dddZ
dddZG dd deZdS )    N)*)Node   )Callablec                 C   s
   t | tS N)
isinstancer   )c r	   F/opt/alt/python38/lib64/python3.8/site-packages/playhouse/shortcuts.py<lambda>       r   c                 C   sx   t dg}| dk	}|r ||  |D ]"\}}|t d|t d|f q$|dk	rb|t d|f |t d t| 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")), "?"))
    ZCASENZWHENZTHENELSEZEND)SQLappendextendClause)	predicateZexpression_tuplesdefaultclausesZsimple_caseexprvaluer	   r	   r
   case   s    "

r   c                 C   s   t t| td| S )NzAS %s)fnZCASTr   r   )nodeZas_typer	   r	   r
   cast<   s    r   c                 C   s   | rt | S t  S r   )set)sr	   r	   r
   
_clone_set@   s    r   TFc	                 C   s  |dkrdn|}|dkrd}t |}t |}|dk	rr|jD ]6}	t|	trT||	 q:t|	tr:|	jr:||	j q:i }
t |}t |}||O }t| }| jj	D ]}||ks|r||krq| j
|j}t|tr|r|r|| t| |j}t|||||||d d}ni }||
|j< q|rZ|D ].}t| |}t|rN| |
|< n||
|< q*|r|r| jj D ]\}}t||}||ksr||krqr|r||kr||krqrg }|| t| |d t| |}|D ]$}|t||||||d d q||
|< 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.
    Nr   F   )recursebackrefsonlyexcludeseen	max_depthZ	_prefetch)r    r!   r"   r#   r%   )r   _selectr   Fieldaddr   _aliastype_metadeclared_fields_datagetnameForeignKeyFieldgetattrmodel_to_dictcallablereverse_relitemsr   )modelr    r!   r"   r#   r$   Zextra_attrsZfields_from_queryr%   itemdatamodel_classfieldZ
field_dataZrel_obj	attr_nameattrrelated_nameforeign_keyZ
descriptoraccumZrelated_queryr	   r	   r
   r2   E   s    


	



r2   c                    s  |  }| j }| D ]\}}||jkr6|j|  d}n@|| j jkrR|j|  d}n$rft||| qntd|| f t t}|s|rt|trt| j	t
 j| q|rt|ttfr fdd|D }	|	D ]}
t|
 j	| qt| j|	 qt| j	| q|S )NFTz/Unrecognized attribute "%s" for model class %s.c                    s   g | ]}t  j|qS r	   )dict_to_modelr9   ).0Zrow_datar:   ignore_unknownr	   r
   
<listcomp>   s   z!dict_to_model.<locals>.<listcomp>)r+   r5   fieldsr4   setattrAttributeErrorr   r0   dictr/   r@   	rel_modellisttupler=   )r9   r8   rC   instancemetakeyr   
is_backrefZis_foreign_key	instancesZrel_instancer	   rB   r
   r@      s>    



r@   c                       s   e Zd Zd fdd	Z  ZS )RetryOperationalErrorNTc                    s   zt t| |||}W nd tk
r|   |  s8|   |  2 |  }|||pVd |rn| 	 rn| 
  W 5 Q R X Y nX |S )Nr	   )superrQ   execute_sqlOperationalError	is_closedcloseexception_wrapper
get_cursorexecuteget_autocommitcommit)selfsqlparamsrequire_commitcursor	__class__r	   r
   rS      s    
  
z!RetryOperationalError.execute_sql)NT)__name__
__module____qualname__rS   __classcell__r	   r	   ra   r
   rQ      s   rQ   )N)TFNNNNNN)F)syspeeweer   version_infocollectionsr   r3   r   r   r   r2   r@   objectrQ   r	   r	   r	   r
   <module>   s"   
1         
a
(