o 3a @sddlZddlZddlZddlZddlZddlZddlmZddlm Z e dZ GdddZ Gddde Z d d Zd d Zd dZddZdddZddZddZddZdS)N)contextmanager)NotSupportedErrorzdjango.db.backendsc@steZdZddZegdZddZddZdd Zd d Z dd dZ dddZ ddZ ddZ ddZddZd S) CursorWrappercCs||_||_dSN)cursordb)selfrrr :/usr/lib/python3/dist-packages/django/db/backends/utils.py__init__s zCursorWrapper.__init__)fetchone fetchmanyfetchallnextsetcCs&t|j|}|tjvr|j|S|Sr)getattrrrWRAP_ERROR_ATTRSrwrap_database_errors)rattr cursor_attrr r r __getattr__s   zCursorWrapper.__getattr__ccs<|jj|jEdHWddS1swYdSr)rrrrr r r __iter__s "zCursorWrapper.__iter__cCs|Srr rr r r __enter__ szCursorWrapper.__enter__cCs*z|WdS|jjjyYdSwr)closerDatabaseError)rtypevalue tracebackr r r __exit__#s zCursorWrapper.__exit__NcCs|dur |jjjs td|j|jj;|dur,|dur,|j|WdS|dur>|j||WdS|pAd}|j|||WdS1sTwYdS)NzKKeyword parameters for callproc are not supported on this database backend.r )rfeaturessupports_callproc_kwargsrvalidate_no_broken_transactionrrcallproc)rprocnameparamskparamsr r r r#/s    $zCursorWrapper.callproccC|j||d|jdS)NFmanyexecutor)_execute_with_wrappers_executersqlr%r r r executeAzCursorWrapper.executecCr')NTr()r+ _executemanyrr. param_listr r r executemanyDr0zCursorWrapper.executemanycCs8|j|d}t|jjD]}t||}q |||||S)N) connectionr)rreversedexecute_wrappers functoolspartial)rr.r%r)r*contextwrapperr r r r+Gs z$CursorWrapper._execute_with_wrapperscGsf|j|jj |dur|j|WdS|j||WdS1s,wYdSr)rr"rrr/)rr.r%ignored_wrapper_argsr r r r,Ms    $zCursorWrapper._executecGsD|j|jj|j||WdS1swYdSr)rr"rrr4)rr.r3r<r r r r1Vs   $zCursorWrapper._executemany)NNr)__name__ __module__ __qualname__r frozensetrrrrrr#r/r4r+r,r1r r r r rs   rcs8eZdZd fdd ZfddZed ddZZS) CursorDebugWrapperNcB|j||ddt||WdS1swYdS)NT)use_last_executed_query) debug_sqlsuperr/r- __class__r r r/` $zCursorDebugWrapper.executecrB)NT)r))rDrEr4r2rFr r r4drHzCursorDebugWrapper.executemanyFc csJt}zRdVWt}||}|r|jj|j||}z |r%t|nd}Wn ty3d}Ynw|jj |r@d||fn|d|dt j d||||||dddSt}||}|rl|jj|j||}z |rst|nd}Wn tyd}Ynw|jj |rd||fn|d|dt j d||||||ddw) N?z %s times: %sz%.3f)r.timez(%.3f) %s; args=%s)durationr.r%)extra) rK monotonicropslast_executed_queryrlen TypeError queries_logappendloggerdebug) rr.r%rCr)startstoprLtimesr r r rDhsX     zCursorDebugWrapper.debug_sqlr)NNFF)r=r>r?r/r4rrD __classcell__r r rFr rA\s  rAcCs|r tjtt|dSdS)N-)datetimedatemapintsplit)sr r r typecast_datesrbc Cs`|sdS|d\}}}d|vr|d\}}nd}tt|t|t|t|dddS)N:.0000000)r`r\rKr_)rahourminutesseconds microsecondsr r r typecast_times,rlc Cs|sdSd|vr t|S|\}}d|vr|dd\}}n d|vr+|dd\}}|d}|d}|d}d|vrE|d\}}nd}tt|d t|dt|dt|d t|dt|t|d dd S) N r[+rcrdrerrfrg)rbr`r\r_)radt_datesrYrjrkr r r typecast_timestamps(   rucCsDz |d\}}Wntyd|}}Ynw|d|dfS)z Split an SQL identifier into a two element tuple of (namespace, name). The identifier could be a table, column, or sequence name might be prefixed by a namespace. z"."rI")r` ValueErrorstrip) identifier namespacenamer r r split_identifiers  r|cCsVt|\}}|dust||kr|St||d}d|rd|nd|d|||fS)z Shorten an SQL identifier to a repeatable mangled version with the given length. If a quote stripped name contains a namespace, e.g. USERNAME"."TABLE, truncate the table portion only. N)lengthz%s%s%sz%s"."rI)r|rQ names_digest)ryr~hash_lenrzr{digestr r r truncate_names  &rcGs0t}|D] }||q|d|S)zk Generate a 32-bit digest of a set of arguments that can be used to shorten identifying names. N)hashlibmd5updateencode hexdigest)r~argshargr r r rsrcCsl|durdSt}|dur||_|dur&|jtd| |d}n d|jtj<| |}d |S)zc Format a number into a string with the requisite number of digits and decimal places. Nrn)r:z{:f}) decimal getcontextcopyprecquantizeDecimalscalebtrapsRoundedcreate_decimalformat)r max_digitsdecimal_placesr:r r r format_numbers    rcCs(|do |d}|r|ddS|S)z Strip quotes off of quoted table names to make them safe for use in index names, sequence names, etc. For example '"USER"."TABLE"' (an Oracle naming scheme) becomes 'USER"."TABLE'. rvrn) startswithendswith) table_name has_quotesr r r strip_quotessr)Nr})r\rr8rloggingrK contextlibr django.dbr getLoggerrUrrArbrlrur|rrrrr r r r s&   N,