mf,ddlZddlTddlmZddlmZddlmZddlmZddlmZdZ dd Zdd Z dd Z ddZ Gdde Z ddZGddeZdS)N)*)Alias)CompoundSelectQuery)Metadata) callable_)__deprecated__c@|rt|n tSN)set)ss J/opt/imunify360/venv/lib64/python3.11/site-packages/playhouse/shortcuts.pyr s-s1vvvTFc |dn|}|dkrd}tt|}fd} |d|jD]\} t| tr| -t| t r|| j]i} tt|}|zt|} | r|jj D]\}}| |r ||j jj |j f|jjjD]}|g}t!||D]-}|t%||||dz .|| |<|jjD]}| |r|j|j}t|t.rJ|rH|D||t!||j}t%|||||dz }nd}|| |j<|r7|D]4}t!||}t1|r|| |</|| |<5|r|r|jj D]\}}|j d krt!| |j }|vs|vr/r |vr|vr:g}|t!||j }|D]-}|t%||||dz .|| |j <| S) a8 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. :param bool manytomany: Process many-to-many fields. NrFc|vpo|vSr )nexcludeonlys r rzmodel_to_dict..'sQ'\Ht/G$r)recursebackrefsrr max_depth)rrrrseenr+) _clone_set _returning isinstanceFieldaddr_aliastype_meta manytomanyitemsupdate rel_modelbackref through_modelrefsgetattrappend model_to_dict sorted_fields__data__getnameForeignKeyFieldrr)modelrrrrr extra_attrsfields_from_queryrr% should_skipitemdata model_classr2m2mfkfaccumrel_objfield field_data attr_nameattr foreign_keyr( descriptor related_querys `` r r.r.s& 'YIA~~ d  D[))KHHHHHK$%0 - -D$&& -D%(( - ,,, D!!G d  D tOGu++K/5577  ID#{4    NNC!4!? !LM N N N(.3 ! ! C    E"5$// . . ]#%#'!m ---....DJJ*&& ;u    ^'' 33 e_ - - "' "%!%44*#%#'!m--- " %UZ'$ ' 'I5),,D '"&$&&Y"&Y.G.&+k&:&@&@&B&B . . "K"c))8 k.ABBJW$$ w(>(> 4//k6M6ME KK $ $ $#E;+>??M( . . ]#%#'!m ---....).D$ % % Krc N |j}td|jD}|D]g\}}||jvr|j| d}nF||vr || d}n7rt |||Bt d|dt|dt t}|su|rst|tr^ |j j } n$#t$r } YnwxYwt | j t| ||r^t|tt frB fd|D} | D]} t | j |t | j| Qt | j |i|S)Nc g|] }|j|f Sr)r)).0fks r z*update_model_from_dict..s>>>"bj"%>>>rFTzUnrecognized attribute "z" for model class .c<g|]}tj|Sr) dict_to_modelr4)rHrow_datar?ignore_unknowns r rJz*update_model_from_dict..s7'''ek8^DD'''r)r$dictrr&combinedsetattrAttributeErrorr#rr3__rel__r2KeyErrorr(update_model_from_dictlisttupler)) instancer9rOmetarkeyvalue is_backrefis_foreign_key rel_instance instancesr?s ` @r rVrVs >D>> >>>??Hjjll!1!1 U $-  M#&EJJ H__SMEJJ  F Hc5 ) ) )  .03T(^^^^"EFF F$E?;; 1n 1E41H1H 1 1'/ ;  1 1 1$00  1  &|UNKK M M M M 1JutUm<< 1''''' %'''I!* < <  ej(;;;; HemY 7 7 7 7 Hej% 0 0 0 0 OsC##DDc4t|||Sr )rV)r:r9rOs r rMrMs !++--~ F FFrcx|jjD]3\}}|j|vs||vrt |r |n|}|||<4t |\}}t ||}||| S)a Helper for generating conditional INSERT queries. For example, prevent INSERTing a new tweet if the user has tweeted within the last hour:: INSERT INTO "tweet" ("user_id", "content", "timestamp") SELECT 234, 'some content', now() WHERE NOT EXISTS ( SELECT 1 FROM "tweet" WHERE user_id = 234 AND timestamp > now() - interval '1 hour') Using this helper: cond = ~fn.EXISTS(Tweet.select().where( Tweet.user == user_obj, Tweet.timestamp > one_hour_ago)) iq = insert_where(Tweet, { Tweet.user: user_obj, Tweet.content: 'some content'}, where=cond) res = iq.execute() )columns) r$defaultsr&r2rzipSelectwhere insert_from as_rowcount) clsr9rgr?defaultr\fieldsvaluessqs r insert_whereros2),2244w :  $&w//< WU $**,,'NFF     % %e , ,B ??2v & & 2 2 4 44rcPeZdZdZedfedfedfedfedffZfdZd fd ZxZS) ReconnectMixina Mixin class that attempts to automatically reconnect to the database under certain error conditions. For example, MySQL servers will typically close connections that are idle for 28800 seconds ("wait_timeout" setting). If your application makes use of long-lived connections, you may find your connections are closed after a period of no activity. This mixin will attempt to reconnect automatically when these errors occur. This mixin class probably should not be used with Postgres (unless you REALLY know what you are doing) and definitely has no business being used with Sqlite. If you wish to use with Postgres, you will need to adapt the `reconnect_errors` attribute to something appropriate for Postgres. 2006201320144031zMySQL Connection not available.c tt|j|i|i|_|jD]R\}}|j|g|j||SdSr )superrq__init___reconnect_errorsreconnect_errors setdefaultr-lower)selfargskwargs exc_class err_fragment __class__s r rxzReconnectMixin.__init__s,nd##,d=f==="$'+'< K K #I|  " - -i < < <  "9 - 4 4\5G5G5I5I J J J J K KrNcD|td tt|||S#t$r}|r|t |}||jvr|t| }|j|D]}||vrn || s(| | tt|||cYd}~Sd}~wwxYw)Nz,"commit" has been deprecated and is a no-op.) rrwrq execute_sql Exceptionin_transactionr#rystrr| is_closedcloseconnect) r}sqlparamscommitexcrexc_reprrrs r rzReconnectMixin.execute_sqls=   I J J J H..::3GG G H H H""$$  S I 666 3xx~~''H $ 6y A   8++E, >>##   ..::3GG G G G G G G+ Hs(= DC DDD)NN) __name__ __module__ __qualname____doc__OperationalErrorrzrxr __classcell__rs@r rqrqs" 6" 6" 6" 6" <= KKKKKHHHHHHHHHHrrq_model_identifiercvig}|r|}t|tr"||j|jfM|j}|jj}||<|j t| |fd}|S)Nc3KD])}|}|}|di|V*dS)Nr)dictsiteratorpop)row identifierr4r[mappingquerys r wrapped_iteratorz2resolve_multimodel_query..wrapped_iterator'sh;;==))++  CJJ'E%,,#,,      r) rrrextendlhsrhsr4r$ table_namerr-Valuealias)rr[r=currr:r2rrs`` @r resolve_multimodel_queryrsG GE  7yy{{ d/ 0 0  LL$(DH- . . . j  +#  uT{{0055666  7    rcFeZdZdZfdZdZdZeeeZxZ S)ThreadSafeDatabaseMetadataz Metadata class to allow swapping database at run-time in a multi-threaded application. To use: class Base(Model): class Meta: model_metadata_class = ThreadSafeDatabaseMetadata cd|_tj|_t t |j|i|dSr ) _database threadinglocal_localrwrrx)r}r~rrs r rxz#ThreadSafeDatabaseMetadata.__init__9sBo'' 8($//8$I&IIIIIrc8t|jd|jS)Ndatabase)r,rr)r}s r _get_dbz"ThreadSafeDatabaseMetadata._get_db?st{J???rc:|j||_||j_dSr )rrr)r}dbs r _set_dbz"ThreadSafeDatabaseMetadata._set_dbAs! > !DN! r) rrrrrxrrpropertyrrrs@r rr0soJJJJJ @@@"""x))HHHHHrr) TFNNNNNNF)Fr )r)rpeeweerrrrrrr.rVrMroobjectrqrrrrr rsk&&&&&&!!!!!!. - =A7;EJrrrrj''''TGGGG5555DCHCHCHCHCHVCHCHCHL.**********r