%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/227033/root/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/
Upload File :
Create Path :
Current File : //proc/227033/root/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyc

�
Tc@sdZddlZddlZddlZddlZyddl	Z
Wn
dZ
nXddlZddlm
ZddlmZddlmZddlmZddlmZdefd	��YZd
efd��YZdefd
��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZ defd��YZ!defd��YZ"defd��YZ#de"fd��YZ$d e#fd!��YZ%d"e&fd#��YZ'ddd$�Z(d%e&fd&��YZ)ddd'�Z*ddd(�Z+d)�Z,d*�Z-d+e&fd,��YZ.e/e/ddd-�Z0d.e&fd/��YZ1e/dd0�Z2dd1l3m4Z4m5Z5m6Z6dd2l3m7Z7m8Z8dd3l9m:Z:m;Z;dd4l9m<Z<m=Z=m>Z>dd5l9m?Z?m@Z@mAZAdS(6s�Miscellaneous goodies for psycopg2

This module is a generic place used to hold little helper functions
and classes until a better place in the distribution is found.
i����N(t
extensions(tcursor(t
connection(tadapt(tbtDictCursorBasecBs>eZdZd�Zd�Zdd�Zd�Zd�ZRS(s%Base class for all dict-like cursors.cOsdd|kr |d}|d=ntd��tt|�j||�d|_d|_||_dS(Ntrow_factorys;DictCursorBase can't be instantiated without a row factory.i(tNotImplementedErrortsuperRt__init__t_query_executedt	_prefetchR(tselftargstkwargsR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	1s

			cCs\|jr!tt|�j�}n|jr7|j�n|jsXtt|�j�}n|S(N(RRRtfetchoneR
t_build_index(Rtres((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR=s		
	cCsb|jr$tt|�j|�}n|jr:|j�n|js^tt|�j|�}n|S(N(RRRt	fetchmanyR
R(RtsizeR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRFs		
	cCs\|jr!tt|�j�}n|jr7|j�n|jsXtt|�j�}n|S(N(RRRtfetchallR
R(RR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyROs		
	ccs�|jr-tt|�j�}|j�}n|jrC|j�n|jsptt|�j�}|j�}n|Vx|j�VqxdS(N(RRRt__iter__tnextR
R(RRtfirst((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRXs		
	N(	t__name__t
__module__t__doc__R	RtNoneRRR(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR.s						tDictConnectioncBseZdZd�ZRS(s2A connection that uses `DictCursor` automatically.cOs)|jdt�tt|�j||�S(Ntcursor_factory(t
setdefaultt
DictCursorRRR(RR
R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRis(RRRR(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRgsRcBs8eZdZd�Zdd�Zdd�Zd�ZRS(s<A cursor that keeps a list of column name -> index mappings.cOs0t|d<tt|�j||�d|_dS(NRi(tDictRowRRR	R(RR
R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	ps
cCs+i|_d|_tt|�j||�S(Ni(tindexR
RRtexecute(Rtquerytvars((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR"us		cCs+i|_d|_tt|�j||�S(Ni(R!R
RRtcallproc(RtprocnameR$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR%zs		cCs`|jdkr\|jr\x5tt|j��D]}||j|j|d<q.Wd|_ndS(Nii(R
tdescriptiontrangetlenR!(Rti((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRsN(RRRR	RR"R%R(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRms
	R cBs�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zejddkr�e
Z[
eZ[eZ	[[
nRS(s6A row object that allow by-column-name access to data.t_indexcCs'|j|_dgt|j�|(dS(N(R!R+RR)R'(RR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	�scCs5t|ttf�s%|j|}ntj||�S(N(t
isinstancetinttsliceR+tlistt__getitem__(Rtx((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR0�scCs<t|ttf�s%|j|}ntj|||�dS(N(R,R-R.R+R/t__setitem__(RR1tv((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR2�scCst|j��S(N(R/t	iteritems(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytitems�scCs
|jj�S(N(R+tkeys(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR6�scCst|�S(N(ttuple(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytvalues�scCs
||jkS(N(R+(RR1((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pythas_key�scCsy||SWn|SXdS(N((RR1tdefault((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytget�sccs;x4|jj�D]#\}}|tj||�fVqWdS(N(R+R4R/R0(RtnR3((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR4�scCs
|jj�S(N(R+titerkeys(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR=�scCs
tj|�S(N(R/R(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt
itervalues�scCst|j��S(N(tdictR4(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytcopy�scCs
||jkS(N(R+(RR1((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt__contains__�scCs||jj�fS(N(R+R@(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt__getstate__�scCs|d|(|d|_dS(Nii(R+(Rtdata((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt__setstate__�sii(s_indexN(RRRt	__slots__R	R0R2R5R6R8R9RR;R4R=R>R@RARBRDt_systversion_info(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR �s2														tRealDictConnectioncBseZdZd�ZRS(s6A connection that uses `RealDictCursor` automatically.cOs)|jdt�tt|�j||�S(NR(RtRealDictCursorRRHR(RR
R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�s(RRRR(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRH�sRIcBs8eZdZd�Zdd�Zdd�Zd�ZRS(sQA cursor that uses a real dict as the base type for rows.

    Note that this cursor is extremely specialized and does not allow
    the normal access (using integer indices) to fetched data. If you need
    to access database rows both as a dictionary and a list, then use
    the generic `DictCursor` instead of `!RealDictCursor`.
    cOs0t|d<tt|�j||�d|_dS(NRi(tRealDictRowRRIR	R(RR
R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	�s
cCs+g|_d|_tt|�j||�S(Ni(tcolumn_mappingR
RRIR"(RR#R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR"�s		cCs+g|_d|_tt|�j||�S(Ni(RKR
RRIR%(RR&R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR%�s		cCsc|jdkr_|jr_x8tt|j��D]!}|jj|j|d�q.Wd|_ndS(Nii(R
R'R(R)RKtappend(RR*((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�sN(RRRR	RR"R%R(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRI�s
	RJcBs8eZdZdZd�Zd�Zd�Zd�ZRS(s.A `!dict` subclass representing a data record.t_column_mappingcCs=tj|�|jr-|jr-|j�n|j|_dS(N(R?R	R'RKRRM(RR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	�s

cCs5t|�tkr"|j|}ntj|||�S(N(ttypeR-RMR?R2(Rtnametvalue((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR2�scCs|j�|jfS(N(R@RM(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRB�scCs"|j|d�|d|_dS(Nii(tupdateRM(RRC((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRDs(RRRRER	R2RBRD(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRJ�s			tNamedTupleConnectioncBseZdZd�ZRS(s8A connection that uses `NamedTupleCursor` automatically.cOs)|jdt�tt|�j||�S(NR(RtNamedTupleCursorRRRR(RR
R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRs(RRRR(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRRsRScBs�eZdZdZdd�Zd�Zdd�Zd�Zdd�Z	d�Z
d�Zydd	lm
Z
Wnek
r�Zd
�Zn
Xe
d�ZRS(
s�A cursor that generates results as `~collections.namedtuple`.

    `!fetch*()` methods will return named tuples instead of regular tuples, so
    their elements can be accessed both as regular numeric items as well as
    attributes.

        >>> nt_cur = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
        >>> rec = nt_cur.fetchone()
        >>> rec
        Record(id=1, num=100, data="abc'def")
        >>> rec[1]
        100
        >>> rec.data
        "abc'def"
    cCs"d|_tt|�j||�S(N(RtRecordRRSR"(RR#R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR"s	cCs"d|_tt|�j||�S(N(RRTRRStexecutemany(RR#R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRU"s	cCs"d|_tt|�j||�S(N(RRTRRSR%(RR&R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR%&s	cCs]tt|�j�}|dk	rY|j}|dkrL|j�}|_n|j|�SdS(N(RRSRRRTt_make_ntt_make(Rtttnt((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR*s	cCsStt|�j|�}|j}|dkrC|j�}|_nt|j|�S(N(RRSRRTRRVtmapRW(RRttsRY((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR2s
	cCsPtt|�j�}|j}|dkr@|j�}|_nt|j|�S(N(RRSRRTRRVRZRW(RR[RY((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR9s
	ccsxtt|�j�}|j�}|j}|dkrL|j�}|_n|j|�Vx|j|j��Vq]dS(N(RRSRRRTRRVRW(RtitRXRY((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR@s	i����(t
namedtuplecCs
|j�dS(N(t_exc(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRVPscCs-|dg|jpdD]}|d^q�S(NRTi((R'(RR]td((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRVSsN(RRRRRTR"RUR%RRRRtcollectionsR]tImportErrorR^RV(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRSs				

tLoggingConnectioncBsDeZdZd�Zd�Zd�Zd�Zd�Zd�ZRS(s}A connection that logs all queries to a file or logger__ object.

    .. __: http://docs.python.org/library/logging.html
    cCs@||_tr0t|tj�r0|j|_n|j|_dS(s�Initialize the connection to log to `!logobj`.

        The `!logobj` parameter can be an open file object or a Logger
        instance from the standard logging module.
        N(t_logobjt_loggingR,tLoggert_logtologgertlogt
_logtofile(Rtlogobj((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt
initialize]s	cCs|S(s�Filter the query before logging it.

        This is the method to overwrite to filter unwanted queries out of the
        log or to add some extra data to the output. The default implementation
        just does nothing.
        ((Rtmsgtcurs((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytfilteriscCs6|j||�}|r2|jj|tj�ndS(N(RmRctwritet_ostlinesep(RRkRl((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRhrscCs/|j||�}|r+|jj|�ndS(N(RmRctdebug(RRkRl((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRfvscCs%t|d�s!|jd��ndS(NRcs3LoggingConnection object has not been initialize()d(thasattrtProgrammingError(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt_checkzscOs3|j�|jdt�tt|�j||�S(NR(RtRt
LoggingCursorRRbR(RR
R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRs
(	RRRRjRmRhRfRtR(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRbWs						RucBs&eZdZdd�Zdd�ZRS(sCA cursor that logs queries using its connection logging facilities.cCs;ztt|�j||�SWd|jj|j|�XdS(N(RRuR"RRgR#(RR#R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR"�scCs;ztt|�j||�SWd|jj|j|�XdS(N(RRuR%RRgR#(RR&R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR%�sN(RRRRR"R%(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRu�stMinTimeLoggingConnectioncBs,eZdZdd�Zd�Zd�ZRS(s�A connection that logs queries based on execution time.

    This is just an example of how to sub-class `LoggingConnection` to
    provide some extra filtering for the logged queries. Both the
    `initialize()` and `filter()` methods are overwritten to make sure
    that only queries executing for more than ``mintime`` ms are logged.

    Note that this connection uses the specialized cursor
    `MinTimeLoggingCursor`.
    icCstj||�||_dS(N(RbRjt_mintime(RRitmintime((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRj�scCs=tj�|jd}||jkr9|tjd|SdS(Ni�s  (execution time: %d ms)(t_timettimet	timestampRwRoRp(RRkRlRX((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRm�scOs#|jdt�tj|||�S(NR(RtMinTimeLoggingCursorRbR(RR
R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�s(RRRRjRmR(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyRv�s
	R|cBs&eZdZdd�Zdd�ZRS(s=The cursor sub-class companion to `MinTimeLoggingConnection`.cCs"tj�|_tj|||�S(N(RyRzR{RuR"(RR#R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR"�scCs"tj�|_tj|||�S(N(RyRzR{RuR"(RR&R$((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR%�sN(RRRRR"R%(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR|�stUUID_adaptercBs2eZdZd�Zd�Zd�Zd�ZRS(s�Adapt Python's uuid.UUID__ type to PostgreSQL's uuid__.

    .. __: http://docs.python.org/library/uuid.html
    .. __: http://www.postgresql.org/docs/current/static/datatype-uuid.html
    cCs
||_dS(N(t_uuid(Rtuuid((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	�scCs|tjkr|SdS(N(t_extt	ISQLQuote(Rtproto((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt__conform__�scCstd|j�S(Ns
'%s'::uuid(RR~(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt	getquoted�scCsd|jS(Ns
'%s'::uuid(R~(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt__str__�s(RRRR	R�R�R�(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR}�s
			cs�ddl�|s!d}d}n0t|ttf�rE|\}}n|}d}tj|fd�fd��t_tj|fdtj�t_tj	tj|�tj	tj|�tj
�jt�tjS(sRCreate the UUID type and an uuid.UUID adapter.

    :param oids: oid for the PostgreSQL :sql:`uuid` type, or 2-items sequence
        with oids of the type and the array. If not specified, use PostgreSQL
        standard oids.
    :param conn_or_curs: where to register the typecaster. If not specified,
        register it globally.
    i����Ni�i�tUUIDcs|r�j|�pdS(N(R�R(RCR(R(sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt<lambda>�ssUUID[](RR,R/R7R�tnew_typeR�tnew_array_typet	UUIDARRAYt
register_typetregister_adapterR}(toidstconn_or_curstoid1toid2((RsB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt
register_uuid�s
	tInetcBsDeZdZd�Zd�Zd�Zd�Zd�Zd�ZRS(sCWrap a string to allow for correct SQL-quoting of inet values.

    Note that this adapter does NOT check the passed value to make
    sure it really is an inet-compatible address but DOES call adapt()
    on it to make sure it is impossible to execute an SQL-injection
    by passing an evil value to the initializer.
    cCs
||_dS(N(taddr(RR�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	�scCsd|jj|jfS(Ns%s(%r)(t	__class__RR�(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt__repr__�scCs
||_dS(N(t_conn(Rtconn((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytprepare�scCsEt|j�}t|d�r1|j|j�n|j�td�S(NR�s::inet(t_AR�RrR�R�R�R(Rtobj((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�scCs|tjkr|SdS(N(R�R�(RR�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�scCs
t|j�S(N(tstrR�(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�s(	RRRR	R�R�R�R�R�(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR��s					cCs�|sd}d}n0t|ttf�r9|\}}n|}d}tj|fdd��t_tj|fdtj�t_tjtj|�tjtj|�tjS(sLCreate the INET type and an Inet adapter.

    :param oid: oid for the PostgreSQL :sql:`inet` type, or 2-items sequence
        with oids of the type and the array. If not specified, use PostgreSQL
        standard oids.
    :param conn_or_curs: where to register the typecaster. If not specified,
        register it globally.
    ieitINETcSs|rt|�pdS(N(R�R(RCR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�!st	INETARRAY(	R,R/R7R�R�R�R�R�R�(toidR�R�R�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt
register_inets		cCs ddl}|jdt�dS(sThe function used to register an alternate type caster for
    :sql:`TIMESTAMP WITH TIME ZONE` to deal with historical time zones with
    seconds in the UTC offset.

    These are now correctly handled by the default type caster, so currently
    the function doesn't do anything.
    i����Nt
deprecated(twarningstwarntDeprecationWarning(R�R�R�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytregister_tstz_w_secs*scCs�ddl}ddlm}m}m}x�|j�}||krGPq+||krr|j|j�ggg�q+||kr�|jg|j�gg�q+|jd|��q+dS(sWait until a connection or cursor has data available.

    The function is an example of a wait callback to be registered with
    `~psycopg2.extensions.set_wait_callback()`. This function uses
    :py:func:`~select.select()` to wait for data available.

    i����N(tPOLL_OKt	POLL_READt
POLL_WRITEsbad state from poll: %s(tselecttpsycopg2.extensionsR�R�R�tpolltfilenotOperationalError(R�R�R�R�R�tstate((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytwait_select6scCsm|dkrtjd��nt|d�rK|j}|jdt�}n|}|jdt�}||fS(sEReturn the connection and a DBAPI cursor from a connection or cursor.s no connection or cursor providedR"RN(Rtpsycopg2RsRrRRt_cursor(R�R�Rl((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt_solve_conn_cursMs	t
HstoreAdaptercBs�eZdZd�Zd�Zd�Zd�ZeZej	dej
�Zeej	d�d��Z
ed��Zed	��ZRS(
s)Adapt a Python dict to the hstore syntax.cCs
||_dS(N(twrapped(RR�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	^scCs+||_|jdkr'|j|_ndS(Ni�_(R�tserver_versiont_getquoted_8R�(RR�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�as	cCs|jstd�Stj}g}x�|jj�D]�\}}||�}|j|j�|j�}|dk	r�||�}|j|j�|j�}ntd�}|j	td�|td�|td��q2Wtd�td�j
|�td�S(s*Use the operators available in PG pre-9.0.s
''::hstoretNULLt(s => t)s||N(R�RR�RR4R�R�R�RRLtjoin(RRtrvtkR3((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�hs	
	3cCs�|jstd�Stj|jj��}|j|j�tj|jj��}|j|j�td�|j�td�|j�td�S(s(Use the hstore(text[], text[]) function.s
''::hstoreshstore(s, R�(	R�RR�RR6R�R�R8R�(RR�R3((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt_getquoted_9�s	
sm
        # hstore key:
        # a string of normal or escaped chars
        "((?: [^"\\] | \\. )*)"
        \s*=>\s* # hstore value
        (?:
            NULL # the value can be null - not catched
            # or a quoted string like the key
            | "((?: [^"\\] | \\. )*)"
        )
        (?:\s*,\s*|$) # pairs separated by comma or end of string.
    s\\(.)c	Cs�|dkrdSi}d}x�|jj|�D]�}|dksS|j�|kritjd|��n|jd|jd��}|jd�}|dk	r�|jd|�}n|||<|j�}q/W|t	|�kr�tjd|��n|S(s�Parse an hstore representation in a Python string.

        The hstore is represented as something like::

            "a"=>"1", "b"=>"2"

        with backslash-escaped strings.
        is$error parsing hstore pair at char %ds\1iis1error parsing hstore: unparsed data after char %dN(
Rt
_re_hstoretfinditertstartR�tInterfaceErrortsubtgrouptendR)(	Rtstcurt_bsdecR�R�tmR�R3((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytparse�s$

cCs<|dkrdS|jtj|jj�}|j||�S(s2Parse an hstore returning unicode keys and values.N(RtdecodeR�t	encodingsRtencodingR�(RR�R�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt
parse_unicode�sc	Cs�t|�\}}|j}|jdkr0dp3d}gg}}|jd|�x0|D](}|j|d�|j|d�q[W|tjkr�|jr�|j�nt	|�t	|�fS(sBReturn the lists of OID of the hstore and hstore[] types.
        i�9ttyparrayR�slSELECT t.oid, %s
FROM pg_type t JOIN pg_namespace ns
    ON typnamespace = ns.oid
WHERE typname = 'hstore';
ii(
R�tstatusR�R"RLR�tSTATUS_IN_TRANSACTIONt
autocommittrollbackR7(	RR�R�Rltconn_statusR�trv0trv1R�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytget_oids�s	



(RRRR	R�R�R�R�t_retcompiletVERBOSER�tclassmethodR�R�R�(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�\s				 	c		Cst|dkr[tj|�}|dks2|drDtjd��q[|d}|d}nt|t�rv|f}n|dk	r�t|t�r�|f}q�tg|D]}|r�|^q��}ntj	ddkr�|r�tj
}n	tj}tj
|d|�}tj||r|p!d�tjtt�|rptj|d|�}tj||rf|pid�ndS(sRegister adapter and typecaster for `!dict`\-\ |hstore| conversions.

    :param conn_or_curs: a connection or cursor: the typecaster will be
        registered only on this object unless *globally* is set to `!True`
    :param globally: register the adapter globally, not only on *conn_or_curs*
    :param unicode: if `!True`, keys and values returned from the database
        will be `!unicode` instead of `!str`. The option is not available on
        Python 3
    :param oid: the OID of the |hstore| type if known. If not, it will be
        queried on *conn_or_curs*.
    :param array_oid: the OID of the |hstore| array type if known. If not, it
        will be queried on *conn_or_curs*.

    The connection or cursor passed to the function will be used to query the
    database and look for the OID of the |hstore| type (which may be different
    across databases). If querying is not desirable (e.g. with
    :ref:`asynchronous connections <async-support>`) you may specify it in the
    *oid* parameter, which can be found using a query such as :sql:`SELECT
    'hstore'::regtype::oid`. Analogously you can obtain a value for *array_oid*
    using a query such as :sql:`SELECT 'hstore[]'::regtype::oid`.

    Note that, when passing a dictionary from Python to the database, both
    strings and unicode keys and values are supported. Dictionaries returned
    from the database have keys/values according to the *unicode* parameter.

    The |hstore| contrib module must be already installed in the database
    (executing the ``hstore.sql`` script in your ``contrib`` directory).
    Raise `~psycopg2.ProgrammingError` if the type is not found.
    is\hstore type not found in the database. please install it from your 'contrib/hstore.sql' fileiitHSTOREtHSTOREARRAYN(RR�R�R�RsR,R-R7RFRGR�R�R�R�R�R�R?R�(	R�tgloballytunicodeR�t	array_oidR1tcastR�R�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytregister_hstore�s,

(	tCompositeCastercBszeZdZd	d	d�Zd�Zd�Zejdej	�Z
ejd�Zed��Z
d�Zed��ZRS(
smHelps conversion of a PostgreSQL composite type into a Python object.

    The class is usually created by the `register_composite()` function.
    You may want to create and register manually instances of the class if
    querying the database at registration time is not desirable (such as when
    using an :ref:`asynchronous connections <async-support>`).

    cCs�||_||_||_||_g|D]}|d^q+|_g|D]}|d^qK|_|j||j�tj|f||j	�|_
|r�tj|fd||j
�|_n	d|_dS(Niis%sARRAY(ROtschemaR�R�tattnamestatttypest_create_typeR�R�R�t
typecasterR�tarray_typecasterR(RROR�tattrsR�R�ta((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR	.s				  cCs�|dkrdS|j|�}t|�t|j�krktjdt|j�|jt|�f��ngt|j|�D]\}}|j||�^q~}|j	|�S(Ns9expecting %d components for the type %s, %d found instead(
RttokenizeR)R�R�t	DataErrorROtzipR�tmake(RR�RlttokensR�ttokenR8((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�>s(4cCs
|j|�S(sReturn a new Python object representing the data being casted.

        *values* is the list of attributes, already casted into their Python
        representation.

        You can subclass this method to :ref:`customize the composite cast
        <custom-composite>`.
        (t_ctor(RR8((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�Ms
s�
  \(? ([,)])                        # an empty token, representing NULL
| \(? " ((?: [^"] | "")*) " [,)]    # or a quoted string
| \(? ([^",)]+) [,)]                # or an unquoted string
    s	(["\\])\1cCs�g}x�|jj|�D]�}|dkrAtjd|��n|jd�dk	rf|jd�q|jd�dk	r�|j|jjd|jd���q|j|jd��qW|S(Nscan't parse type: %riis\1i(	t_re_tokenizeR�RR�R�R�RLt_re_undoubleR�(RR�R�R�((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�as(cCsbyddlm}Wn&tk
r<t|_|j|_n"X|||�|_|jj|_dS(Ni����(R](R`R]RaR7RNR�RW(RROR�R]((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�ps
	cCs0t|�\}}|j}d|krB|jdd�\}}n|}d}|jdkrcdpfd}|jd|||f�|j�}	|tjkr�|jr�|j	�n|	s�t
jd|��n|	d	d	}
|	d	d}g|	D]}|d
|df^q�}
|||
|
d|d
|�S(s}Return a `CompositeCaster` instance for the type *name*.

        Raise `ProgrammingError` if the type is not found.
        t.itpublici�9R�R�s�SELECT t.oid, %s, attname, atttypid
FROM pg_type t
JOIN pg_namespace ns ON typnamespace = ns.oid
JOIN pg_attribute a ON attrelid = typrelid
WHERE typname = %%s AND nspname = %%s
    AND attnum > 0 AND NOT attisdropped
ORDER BY attnum;
sPostgreSQL type '%s' not foundiiiR�R�(R�R�tsplitR�R"RR�R�R�R�R�Rs(RROR�R�RlR�R�ttnameR�trecsttype_oidR�trt
type_attrs((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt_from_dbzs*	

'N(RRRRR	R�R�R�R�R�R�R�R�R�R�R�(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyR�%s			
cCs}|dkrt}n|j||�}tj|j|r@|pCd�|jdk	rytj|j|ro|prd�n|S(sRegister a typecaster to convert a composite type into a tuple.

    :param name: the name of a PostgreSQL composite type, e.g. created using
        the |CREATE TYPE|_ command
    :param conn_or_curs: a connection or cursor used to find the type oid and
        components; the typecaster is registered in a scope limited to this
        object, unless *globally* is set to `!True`
    :param globally: if `!False` (default) register the typecaster only on
        *conn_or_curs*, otherwise register it globally
    :param factory: if specified it should be a `CompositeCaster` subclass: use
        it to :ref:`customize how to cast composite types <custom-composite>`
    :return: the registered `CompositeCaster` or *factory* instance
        responsible for the conversion
    N(RR�R�R�R�R�R�(ROR�R�tfactorytcaster((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pytregister_composite�s	 #(tjsontJsont
register_json(tregister_default_jsontregister_default_jsonb(tRangetNumericRange(t	DateRanget
DateTimeRangetDateTimeTZRange(tregister_rangetRangeAdaptertRangeCaster(BRtosRotsysRFRzRytreR�tloggingRdRR�RR�R�RR�Rt_connectionRR�RRRRR/R RHRIR?RJRRRSRbRuRvR|tobjectR}R�R�R�R�R�R�R�tFalseR�R�R�tpsycopg2._jsonR�RRRRtpsycopg2._rangeRRRRRR	R
R(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/extras.pyt<module>sX
9DK-"		�@�

Zerion Mini Shell 1.0