o k`E@sNddlZddlmZedejZddZGdddeZGdd d eZ dS) N)closingzA '(?:[^']+|'')*' | `(?:[^`]+|``)*` | "(?:[^"]+|"")*" cCsdd}t||S)NcSs|dddS)Nr%z%%)groupreplace)matchr./usr/lib/python3/dist-packages/trac/db/util.pyreplsz sql_escape_percent..repl)_sql_escape_percent_resub)sqlr rrrsql_escape_percents r c@sDeZdZdZddgZdddZddZd d Zdd d Zd dZ dS)IterableCursorzWrapper for DB-API cursor objects that makes the cursor iterable and escapes all "%"s used inside literal strings with parameterized queries. Iteration will generate the rows of a SELECT query one by one. cursorlogNcCs||_||_dSN)rr)selfrrrrr__init__*s zIterableCursor.__init__cCs t|j|Sr)getattrrrnamerrr __getattr__.s zIterableCursor.__getattr__ccs |j}|s dS|Vqr)rfetchone)rrowrrr__iter__1s zIterableCursor.__iter__c Cs|jrO|jd|z0|r|jd||jt||}n|j|}t|jdd}|dur8|jdt||WStyN}z|jd|d}~ww|rZ|jt||S|j|S)NzSQL: %sargs: %rrowszprefetch: %d rowszexecute exception: %r)rdebugrexecuter rlen Exception)rr argsrrerrrr8s&  zIterableCursor.executec Cs|jr@|jd||jd||sdSz|dr$|jt||WS|j||WSty?}z|jd|d}~ww|sDdS|drQ|jt||S|j||S)NzSQL: %rrrzexecutemany exception: %r)rrr executemanyr r )rr r!r#rrrr$Ls* zIterableCursor.executemanyr) __name__ __module__ __qualname____doc__ __slots__rrrrr$rrrrr!s   rc@sFeZdZdZdZdddZddZdd d ZeZdd d Z d dZ dS)ConnectionWrappera!Generic wrapper around connection objects. :since 0.12: This wrapper no longer makes cursors produced by the connection iterable using `IterableCursor`. :since 1.0: added a 'readonly' flag preventing the forwarding of `commit` and `rollback` cnxrreadonlyNFcCs||_||_||_dSrr+)rr,rr-rrrrls zConnectionWrapper.__init__cCs|jr |dvr tt|j|S)N)commitrollback)r-AttributeErrorrr,rrrrrqs zConnectionWrapper.__getattr__cCsf||}t|j}|||dur|ng|r|nd}Wd|S1s,wY|S)aExecute an SQL `query` The optional `params` is a tuple containing the parameter values expected by the query. If the query is a SELECT, return all the rows ("fetchall"). When more control is needed, use `cursor()`. N) check_selectrr,rrfetchallrqueryparamsdqlrrrrrrvs  zConnectionWrapper.executecCsZ||}t|j}||||r|nd}Wd|S1s&wY|S)a9Execute an SQL `query`, on a sequence of tuples ("executemany"). The optional `params` is a sequence of tuples containing the parameter values expected by the query. If the query is a SELECT, return all the rows ("fetchall"). When more control is needed, use `cursor()`. N)r1rr,rr$r2r3rrrr$s   zConnectionWrapper.executemanycCs$|d}|jr|std|S)a Verify if the query is compatible according to the readonly nature of the wrapped Connection. :return: `True` if this is a SELECT :raise: `ValueError` if this is not a SELECT and the wrapped Connection is read-only. SELECTz,a 'readonly' connection can only do a SELECT)lstrip startswithr- ValueError)rr4r6rrrr1s zConnectionWrapper.check_select)NFr) r%r&r'r(r)rrr__call__r$r1rrrrr*as    r*) re contextlibrcompileVERBOSEr r objectrr*rrrrs @