Ñò žÅŠKc@sGdZddkZddkZddkZyddkZWn dZnXddklZl Z ddkl Z ddk l Zddk lZddk lZdefd „ƒYZd efd „ƒYZd efd „ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZy5ddk Z de!fd„ƒYZ"ddd „Z#Wn!e$j oZ%dd!„Z#nXd"e!fd#„ƒYZ&ddd$„Z'd%„Z(ddd&„Z)e*d'„e+ƒi,ƒƒZ-dS((s¨Miscellaneous goodies for psycopg2 This module is a generic place used to hold little helper functions and classes untill a better place in the distribution is found. iÿÿÿÿN(tDATETIMEt DataError(t extensions(tcursor(t connection(tadapttDictCursorBasecBs>eZdZd„Zd„Zdd„Zd„Zd„ZRS(s%Base class for all dict-like cursors.cOsc|idƒo|d}|d=n tdƒ‚ti|||Žd|_d|_||_dS(Nt row_factorys;DictCursorBase can't be instantiated without a row factory.i(thas_keytNotImplementedErrort_cursort__init__t_query_executedt _prefetchR(tselftargstkwargsR((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR /s     cCsV|ioti|ƒ}n|io|iƒn|ipti|ƒ}n|S(N(R R tfetchoneR t _build_index(Rtres((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR;s   cCs\|ioti||ƒ}n|io|iƒn|ipti||ƒ}n|S(N(R R t fetchmanyR R(RtsizeR((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRDs   cCsV|ioti|ƒ}n|io|iƒn|ipti|ƒ}n|S(N(R R tfetchallR R(RR((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRMs   cCsŠ|io-ti|ƒ}|djo tƒ‚q7n|io|iƒn|ip-ti|ƒ}|djo tƒ‚q†n|S(N(R R RtNonet StopIterationR R(RR((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pytnextVs     N( t__name__t __module__t__doc__R RRRRR(((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR,s  tDictConnectioncBseZdZdd„ZRS(s2A connection that uses `DictCursor` automatically.cCs;|djoti|dtƒSti||dtƒSdS(Ntcursor_factory(Rt _connectionRt DictCursor(Rtname((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRes N(RRRRR(((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRcsR cBs;eZdZd„Zddd„Zdd„Zd„ZRS(s<A cursor that keeps a list of column name -> index mappings.cOs*t|dªscCs ti|ƒS(N(R1t__iter__(R((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyt itervalues­scCst|iƒƒS(N(tdictR4(R((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pytcopy°scCs|ii|ƒS(N(R.t __contains__(RR3((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRC³s(s_indexN(RRRt __slots__R R2R4R8R:RRR<R=R>R@RBRC(((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR"ƒs           tRealDictConnectioncBseZdZdd„ZRS(s6A connection that uses `RealDictCursor` automatically.cCs;|djoti|dtƒSti||dtƒSdS(NR(RRRtRealDictCursor(RR!((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR¸s N(RRRRR(((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRE¶sRFcBs;eZdZd„Zddd„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`. cOs*t|ds  N(RRRRURXRR(((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRa*s   RgcBs)eZdZddd„Zdd„ZRS(s=The cursor sub-class companion to `MinTimeLoggingConnection`.icCs%tiƒ|_ti||||ƒS(N(RdReR`R$(RR%R&R'((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR$HscCs"tiƒ|_ti|||ƒS(N(RdReR`R$(RR)R&((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR(LsN(RRRRR$R((((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRgEst UUID_adaptercBs/eZdZd„Zd„Zd„ZeZRS(sÅAdapt Python's uuid.UUID__ type to PostgreSQL's uuid__. .. __: http://docs.python.org/library/uuid.html .. __: http://www.postgresql.org/docs/8.4/static/datatype-uuid.html cCs ||_dS(N(t_uuid(Rtuuid((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR ]scCsdS(N((Rtconn((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pytprepare`scCsdt|iƒdS(Nt's'::uuid(tstrRi(R((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyt getquotedcs(RRRR RlRot__str__(((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRhVs    cCsÈ|pd}d}n0t|ƒtjo|\}}n |}d}d„}ti|fdd„ƒt_ti|fd|ƒt_titi|ƒtiti|ƒtitit ƒtiS(s.Create the UUID type and an uuid.UUID adapter.i† i‡ cSs‡|djodS|djogSg}|dd!idƒD]=}|t|ƒdjo|djoti|ƒpdq?~SdS(Ns{}iiÿÿÿÿt,itNULL(RtsplitR,RjtUUID(tdataRt_[1]R3((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pytparseUUIDARRAYss   RtcSs|oti|ƒpdS(N(RjRtR(RuR((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyt}ssUUID[]( R/R1t_exttnew_typeRtt UUIDARRAYt register_typetregister_adapterRjRh(toidst conn_or_curstoid1toid2Rw((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyt register_uuidhs  cCs t‚dS(s®Create the UUID type and an uuid.UUID adapter. This is a fake function that will always raise an error because the import of the uuid module failed. N(te(toid((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR‚‡stInetcBs;eZdZd„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(RR†((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR šscCsd|ii|ifS(Ns%s(%r)(t __class__RR†(R((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyt__repr__scCs ||_dS(N(t_conn(RRk((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRl scCsAt|iƒ}t|dƒo|i|iƒn|iƒdS(NRls::inet(t_AR†R]RlR‰Ro(Rtobj((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRo£scCs t|iƒS(N(RnR†(R((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRp©s(RRRR RˆRlRoRp(((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyR…’s     cCs\|p d}nti|fdd„ƒt_titi|ƒtitd„ƒtiS(s)Create the INET type and an Inet adapter.ietINETcSs|o t|ƒpdS(N(R…R(RuR((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRx°scSs|S(((R3((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRx²s(RyRzRŒR|R}R…(R„R((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyt register_inet¬s cCsyyt||ƒSWnatfj oR}|idjo‚ntid|dƒdjo‚nt|d |ƒSXdS(Nsunable to parse times(\+|-)\d\d:\d\d:\d\di÷ÿÿÿiýÿÿÿ(RRtmessagetregextmatchR(tsRtexc((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyt_convert_tstz_w_secs¸scCsI|djo d}nti|dtƒt_titi|ƒtiS(sàRegister alternate type caster for :sql:`TIMESTAMP WITH TIME ZONE`. The Python datetime module cannot handle time zones with seconds in the UTC offset. There are, however, historical "time zones" which contain such offsets, eg. "Asia/Calcutta". In many cases those offsets represent true local time. If you encounter "unable to parse time" on a perfectly valid timestamp you likely want to try this type caster. It truncates the seconds from the time zone data and retries casting the timestamp. Note that this will generate timestamps which are **inaccurate** by the number of seconds truncated (unless the seconds were 00). :param oids: which OIDs to use this type caster for, defaults to :sql:`TIMESTAMP WITH TIME ZONE` :param conn_or_curs: a cursor or connection if you want to attach this type caster to that only, defaults to ``None`` meaning all connections and cursors i t TSTZ_W_SECSN(i (RRyRzR“R”R|(R~R((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pytregister_tstz_w_secsÇs   cCs|idƒ S(t_(t startswith(tk((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pyRxçs(.RRZRdtreRRNRtpsycopg2RRRRytpsycopg2.extensionsRR RRRRŠRRR R1R"RERFRARGRLR`RaRgRjtobjectRhR‚t ImportErrorRƒR…RR“R•RXtlocalsR8t__all__(((s5/usr/lib64/python2.6/site-packages/psycopg2/extras.pytsD    73/