55ok

Mini

Direktori : /proc/thread-self/root/lib/python2.7/site-packages/pymysql/
Upload File :
Current File : //proc/thread-self/root/lib/python2.7/site-packages/pymysql/cursors.pyc

�
�-:Zc@@sddlmZmZddlmZddlZddlZddlmZm	Z	m
Z
ddlmZej
ddd	ejejB�Zd
efd��YZdefd
��YZdeefd��YZdefd��YZdeefd��YZdS(i(tprint_functiontabsolute_import(tpartialNi(t
range_typet	text_typetPY2(terrs'\s*((?:INSERT|REPLACE)\b.+\bVALUES?\s*)s6(\(\s*(?:%s|%\(.+\)s)\s*(?:,\s*(?:%s|%\(.+\)s)\s*)*\))s(\s*(?:ON DUPLICATE.*)?);?\s*\ZtCursorcB@sseZdZdZeZd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zed�Zd�Zdd
�Zd�Zdd�Zdd�Zd�Zd�Zdd�Zd�Zdd�Zd�Zdd�Zd�Zd�Zd�Zd�Z e!j"Z"e!j#Z#e!j$Z$e!j%Z%e!j&Z&e!j'Z'e!j(Z(e!j)Z)e!j*Z*e!j+Z+RS(s�
    This is the object you use to interact with the database.

    Do not create an instance of a Cursor yourself. Call
    connections.Connection.cursor().
    i�cC@sU||_d|_d|_d|_d|_d|_d|_d|_t	|_
dS(Nii����i(t
connectiontNonetdescriptiont	rownumbertrowcountt	arraysizet	_executedt_resultt_rowstFalset_warnings_handled(tselfR((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt__init__%s								cC@sA|j}|dkrdSzx|j�r.qWWdd|_XdS(sD
        Closing a cursor just exhausts all remaining data.
        N(RR	tnextset(Rtconn((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pytclose0s	cC@s|S(N((R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt	__enter__=scG@s~|j�dS(N(R(Rtexc_info((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt__exit__@scC@s"|jstjd��n|jS(Ns
Cursor closed(RRtProgrammingError(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt_get_dbDs	cC@s|jstjd��ndS(Nsexecute() first(RRR(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt_check_executedIs	cC@s|S(N((Rtrow((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt	_conv_rowMscG@sdS(s!Does nothing, required by DB API.N((Rtargs((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt
setinputsizesPtcG@sdS(s!Does nothing, required by DB API.N((RR ((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pytsetoutputsizesSR"cC@sr|j�}|j}|r(|j�n|dksC||jk	rGdS|jsTdS|jd|�|j�tS(sGet the next query sett
unbufferedN(RRt_show_warningsR	thas_nexttnext_resultt_do_get_resulttTrue(RR$Rtcurrent_result((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt_nextsetVs	
	
cC@s
|jt�S(N(R+R(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyResc@sbt|t�r!|j��}n=t|ttf�r^t|���fd�|D��}n|S(Nc3@s$|]}�j|d��VqdS(tencodingN(t
_ensure_bytes(t.0tv(R,R(s3/usr/lib/python2.7/site-packages/pymysql/cursors.pys	<genexpr>ls(t
isinstanceRtencodettupletlistttype(RtxR,((R,Rs3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR-hs
(c@s�t|jd�j��t|ttf�retrKtt�|��}nt�fd�|D��St|t�r�tr�t�fd�|j	�D��}nt�fd�|j	�D��Str��|�}n�j
|�SdS(NR,c3@s|]}�j|�VqdS(N(tliteral(R.targ(R(s3/usr/lib/python2.7/site-packages/pymysql/cursors.pys	<genexpr>usc3@s-|]#\}}�|��|�fVqdS(N((R.tkeytval(tensure_bytes(s3/usr/lib/python2.7/site-packages/pymysql/cursors.pys	<genexpr>xsc3@s*|] \}}|�j|�fVqdS(N(R6(R.R8R9(R(s3/usr/lib/python2.7/site-packages/pymysql/cursors.pys	<genexpr>zs(RR-R,R0R2R3Rtmaptdicttitemstescape(RR R((RR:s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt_escape_argsos cC@sV|j�}tr-|j|d|j�}n|dk	rR||j||�}n|S(s�
        Returns the exact string that is sent to the database by calling the
        execute() method.

        This method follows the extension to the DB API 2.0 followed by Psycopg.
        R,N(RRR-R,R	R?(RtqueryR R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pytmogrify�scC@sAx|j�rqW|j||�}|j|�}||_|S(s�Execute a query

        :param str query: Query to execute.

        :param args: parameters used with query. (optional)
        :type args: tuple, list or dict

        :return: Number of affected rows
        :rtype: int

        If args is a list or tuple, %s can be used as a placeholder in the query.
        If args is a dict, %(name)s can be used as a placeholder in the query.
        (RRAt_queryR(RR@R tresult((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pytexecute�s	c@s�|s
dStj��}|r�|jd�d}|jd�j�}|jd�pYd}|ddkr||dd	ks�t��j||||�j�j�j�St	��fd
�|D���_
�j
S(s�Run several data against one query

        :param query: query to execute on server
        :param args:  Sequence of sequences or mappings.  It is used as parameter.
        :return: Number of rows affected, if any.

        This method improves performance on multiple-row INSERT and
        REPLACE. Otherwise it is equivalent to looping over args with
        execute().
        NiiiR"it(i����t)c3@s!|]}�j�|�VqdS(N(RD(R.R7(R@R(s3/usr/lib/python2.7/site-packages/pymysql/cursors.pys	<genexpr>�s((tRE_INSERT_VALUEStmatchtgrouptrstriptAssertionErrort_do_execute_manytmax_stmt_lengthRR,tsumR(RR@R tmtq_prefixtq_valuest	q_postfix((R@Rs3/usr/lib/python2.7/site-packages/pymysql/cursors.pytexecutemany�s&"c
C@s�|j�}|j}t|t�r6|j|�}ntr]t|t�r]|j|�}nt|t�r~|j|�}nt|�}	t|�}||t|�|�}
t|
t�r�tr�|
j|�}
q�|
j|d�}
n|	|
7}	d}x�|D]�}||||�}
t|
t�rWtrB|
j|�}
qW|
j|d�}
nt	|	�t	|
�t	|�d|kr�||j
|	|�7}t|�}	n
|	d7}	|	|
7}	qW||j
|	|�7}||_|S(Ntsurrogateescapeiit,(RR?R0RR1Rt	bytearraytitertnexttlenRDR(
RtprefixtvaluestpostfixR RMR,RR>tsqlR/trowsR7((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyRL�s>	

*
	cC@s�|j�}xMt|�D]?\}}d|||j|�f}|j|�|j�qWd|djgtt|��D]}d||f^q{�f}|j|�||_|S(sExecute stored procedure procname with args

        procname -- string, name of procedure to execute on server

        args -- Sequence of parameters to use with procedure

        Returns the original args.

        Compatibility warning: PEP-249 specifies that any modified
        parameters must be returned. This is currently impossible
        as they are only available by storing them in a server
        variable and then retrieved by a query. Since stored
        procedures return zero or more result sets, there is no
        reliable way to get at OUT or INOUT parameters via callproc.
        The server variables are named @_procname_n, where procname
        is the parameter above and n is the position of the parameter
        (from zero). Once all result sets generated by the procedure
        have been fetched, you can issue a SELECT @_procname_0, ...
        query using .execute() to get any OUT or INOUT values.

        Compatibility warning: The act of calling a stored procedure
        itself creates an empty result set. This appears after any
        result sets generated by the procedure. This is non-standard
        behavior with respect to the DB-API. Be sure to use nextset()
        to advance through all result sets; otherwise you may get
        disconnected.
        sSET @_%s_%d=%ssCALL %s(%s)RUs@_%s_%d(	Rt	enumerateR>RBRtjoinRRYR(RtprocnameR RtindexR7tqti((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pytcallproc�s
	3
	cC@sX|j�|jdks1|jt|j�kr5dS|j|j}|jd7_|S(sFetch the next rowiN(RRR	RRY(RRC((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pytfetchones
'cC@se|j�|jdkrdS|j|p/|j}|j|j|!}t|t|j��|_|S(sFetch several rowsN((RRR	RR
tminRY(RtsizetendRC((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt	fetchmanys
cC@sX|j�|jdkrdS|jr9|j|j}n	|j}t|j�|_|S(sFetch all the rowsN((RRR	RRY(RRC((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pytfetchall%s
		trelativecC@s�|j�|dkr&|j|}n(|dkr;|}ntjd|��d|kont|j�kns�td��n||_dS(NRltabsolutesunknown scroll mode %sisout of range(RRRRRYRt
IndexError(Rtvaluetmodetr((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pytscroll1s
	%cC@s3|j�}||_|j|�|j�|jS(N(Rt_last_executedR@R(R(RRcR((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyRB>s
	

cC@sx|j�}d|_|j|_}|j|_|j|_|j|_|j|_	t
|_|jst|j
�ndS(Ni(RRRt
affected_rowsRR
t	insert_idt	lastrowidR^RRRt_defer_warningsR%(RRRC((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR(Es			cC@s�|jr
dSt|_|jr<|jjs8|jjr<dS|j�j�}|dkr^dSxh|D]`}|d}tr�t	|t
�r�|jdd�}q�ntj
tj|dd!�dd�qeWdS(Ni����sutf-8treplaceiit
stackleveli(RR)RR&t
warning_countRt
show_warningsR	RR0tunicodeR1twarningstwarnRtWarning(Rtwstwtmsg((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR%Ts		"

cC@st|jd�S(N(RWRfR	(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt__iter__dsN((,t__name__t
__module__t__doc__RMRRwRRRRRRRR!R#R+RR	R-R?RARDRSRLReRfRjRkRrRBR(R%R�RRtErrortInterfaceErrort
DatabaseErrort	DataErrortOperationalErrortIntegrityErrort
InternalErrorRtNotSupportedError(((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyRsN		
											$)		
	
													tDictCursorMixincB@s eZeZd�Zd�ZRS(cC@s�tt|�j�g}|jr{xJ|jjD]<}|j}||kr^|jd|}n|j|�q/W||_	n|r�|j
r�g|j
D]}|j|�^q�|_
ndS(Nt.(tsuperR�R(R
Rtfieldstnamet
table_nametappendt_fieldsRR(RR�tfR�Rq((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR(ws		cC@s)|dkrdS|jt|j|��S(N(R	t	dict_typetzipR�(RR((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR�s(R�R�R<R�R(R(((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR�ss	t
DictCursorcB@seZdZRS(s.A cursor which returns results as a dictionary(R�R�R�(((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR��stSSCursorcB@s}eZdZeZd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
d
�Zdd�ZRS(s�
    Unbuffered Cursor, mainly useful for queries that return a lot of data,
    or for connections to remote servers over a slow network.

    Instead of copying every row of data into a buffer, this will fetch
    rows as needed. The upside of this is the client uses much less memory,
    and rows are returned much faster when traveling over a slow network
    or if the result set is very big.

    There are limitations, though. The MySQL protocol doesn't support
    returning the total number of rows, so the only way to tell how many rows
    there are is to iterate over every row returned. Also, it currently isn't
    possible to scroll backwards, as only the current row is held in memory.
    cC@s|S(N((RR((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR�scC@sr|j}|dkrdS|jdk	rJ|j|jkrJ|jj�nzx|j�r_qPWWdd|_XdS(N(RR	Rt_finish_unbuffered_queryR(RR((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR�s	!cC@s9|j�}||_|j|dt�|j�|jS(NR$(RRsR@R)R(R(RRcR((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyRB�s
	
cC@s|jdt�S(NR$(R+R)(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR�scC@s|j|jj��S(s
Read next row(RRt_read_rowdata_packet_unbuffered(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt	read_next�scC@sC|j�|j�}|dkr0|j�dS|jd7_|S(sFetch next rowiN(RR�R	R%R(RR((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyRf�s

cC@st|j��S(s�
        Fetch all, as per MySQLdb. Pretty useless for large queries, as
        it is buffered. See fetchall_unbuffered(), if you want an unbuffered
        generator version of this method.
        (R3tfetchall_unbuffered(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyRk�scC@st|jd�S(s�
        Fetch all, implemented as a generator, which isn't to standard,
        however, it doesn't make sense to return everything in a list, as that
        would use ridiculous memory for large result sets.
        N(RWRfR	(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR��scC@s
|j�S(N(R�(R((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR��scC@s�|j�|dkr"|j}ng}xVt|�D]H}|j�}|dkra|j�Pn|j|�|jd7_q5W|S(s
Fetch manyiN(RR	R
RR�R%R�R(RRhR^RdR((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyRj�s


RlcC@s�|j�|dkrg|dkr4tjd��nxt|�D]}|j�qAW|j|7_nz|dkr�||jkr�tjd��n||j}xt|�D]}|j�q�W||_ntjd|��dS(NRlis0Backwards scrolling not supported by this cursorRmsunknown scroll mode %s(RRR�RR�RR(RRoRpt_Ri((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyRr�s"

N(R�R�R�R)RwRRRBRR�RfRkR�R�R	RjRr(((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR��s						
			tSSDictCursorcB@seZdZRS(s;An unbuffered cursor, which returns results as a dictionary(R�R�R�(((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyR�s(t
__future__RRt	functoolsRtreR}t_compatRRRR"Rtcompilet
IGNORECASEtDOTALLRGtobjectRR�R�R�R�(((s3/usr/lib/python2.7/site-packages/pymysql/cursors.pyt<module>s�_v

Zerion Mini 1.0