mò ˜%ÜGc@sˆdZdkZdkZdkZdkZy dkZWndkZnXdklZl Z l Z dkl Z y dk Z WndkZ nXhZd„Zd„Zdefd„ƒYZdefd „ƒYZd efd „ƒYZd efd „ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdS(sprovides a connection pool implementation, which optionally manages connections on a thread local basis. Also provides a DBAPI2 transparency layer so that pools can be managed automatically, based on module type and connect arguments, simply by calling regular DBAPI connect() methods.N(sutils exceptionsslogging(squeuecKs?y t|SWn,tj o ti|t||ƒSnXdS(s¿given a DBAPI2 module and pool management parameters, returns a proxy for the module that will automatically pool connections, creating new connection pools for each distinct set of connection arguments sent to the decorated module's connect() function. Arguments: module : a DBAPI2 database module. poolclass=QueuePool : the class used by the pool module to provide pooling. Options: See Pool for options. N(tproxiestmoduletKeyErrort setdefaultt_DBProxytparams(RR((t3/home/holguin2/public_html/spyce/sqlalchemy/pool.pytmanages  cCs/xtiƒD]}|iƒq WtiƒdS(sMremoves all current DBAPI2 managers. all pools and connections are disposed.N(Rtvaluestmanagertclosetclear(R ((Rtclear_managers/s  tPoolcBsŒtZdZdeeeed„ZeiƒZ d„Z d„Z d„Z d„Z d„Zd„Zd „Zd „Zd „Zd „ZRS( sÈBase Pool class. This is an abstract class, which is implemented by various subclasses including: QueuePool - pools multiple connections using Queue.Queue SingletonThreadPool - stores a single connection per execution thread NullPool - doesnt do any pooling; opens and closes connections AssertionPool - stores only one connection, and asserts that only one connection is checked out at a time. the main argument, "creator", is a callable function that returns a newly connected DBAPI connection object. Options that are understood by Pool are: echo=False : if set to True, connections being pulled and retrieved from/to the pool will be logged to the standard output, as well as pool sizing information. Echoing can also be achieved by enabling logging for the "sqlalchemy.pool" namespace. use_threadlocal=True : if set to True, repeated calls to connect() within the same application thread will be guaranteed to return the same connection object, if one has already been retrieved from the pool and has not been returned yet. This allows code to retrieve a connection from the pool, and then while still holding on to that connection, to call other functions which also ask the pool for a connection of the same arguments; those functions will act upon the same connection that the calling method is using. recycle=-1 : if set to non -1, a number of seconds between connection recycling, which means upon checkout, if this timeout is surpassed the connection will be closed and replaced with a newly opened connection. auto_close_cursors = True : cursors, returned by connection.cursor(), are tracked and are automatically closed when the connection is returned to the pool. some DBAPIs like MySQLDB become unstable if cursors remain open. disallow_open_cursors = False : if auto_close_cursors is False, and disallow_open_cursors is True, will raise an exception if an open cursor is detected upon connection checkin. If auto_close_cursors and disallow_open_cursors are both False, then no cursor processing occurs upon checkin. iÿÿÿÿcCs[ti|ƒ|_tiƒ|_||_||_ ||_ ||_ ||_||_dS(N(tloggingtinstance_loggertselftloggertweakreftWeakValueDictionaryt _threadconnstcreatort_creatortrecyclet_recycletuse_threadlocalt_use_threadlocaltauto_close_cursorstdisallow_open_cursorstecho(RRRRRRR((Rt__init__`s     cCst|ƒiƒS(N(t_ConnectionFairyRtcheckout(R((Rtunique_connectionkscCs t|ƒS(N(t_ConnectionRecordR(R((Rtcreate_connectionnscCs…|ipt|ƒiƒSny!|itiƒiƒiƒSWn?tj o3t|ƒiƒ}|i |itiƒ<|SnXdS(N( RRRR Rtthreadt get_identt connfairyRtagentt _threadfairy(RR'((Rtconnectqs !cCs|i|iƒdS(N(Rtdo_return_connR't_connection_record(RR'((Rt return_conn|scCs |iƒS(N(Rtdo_get(R((RtgetscCs tƒ‚dS(N(tNotImplementedError(R((RR-‚scCs tƒ‚dS(N(R/(Rtconn((RR*…scCs tƒ‚dS(N(R/(R((RtstatusˆscCs|ii|ƒdS(N(RRtinfotmsg(RR3((Rtlog‹scCs tƒ‚dS(N(R/(R((RtdisposeŽs(t__name__t __module__t__doc__tNonetFalsetTrueRRt echo_propertyRR!R#R)R,R.R-R*R1R4R5(((RR 5s *         R"cBs>tZd„Zd„Zd„Zd„Zd„Zd„ZRS(NcCs||_|iƒ|_dS(N(tpoolRt_ConnectionRecord__poolt_ConnectionRecord__connectt connection(RR=((RR“s cCs.|iidt|iƒƒ|iiƒdS(NsClosing connection %s(RR>R4treprR@R (R((RR –scCs4|iidt|iƒƒ|iƒd|_dS(NsInvalidate connection %s(RR>R4RAR@t_ConnectionRecord__closeR9(R((Rt invalidate™s cCs—|idjo|iƒ|_nn|iidjoZtiƒ|i|iijo:|iidt |iƒƒ|i ƒ|iƒ|_n|iS(Niÿÿÿÿs)Connection %s exceeded timeout; recycling( RR@R9R?R>Rttimet starttimeR4RARB(R((Rtget_connections3 cCssy.|iidt|iƒƒ|iiƒWn>tj o2}|iidt|iƒt|ƒfƒnXdS(NsClosing connection %ss)Connection %s threw an error on close: %s( RR>R4RAR@R t Exceptiontetstr(RRH((Rt__close¥s cCsyy@tiƒ|_|iiƒ}|iidt|ƒƒ|SWn2tj o&}|iidt |ƒƒ‚nXdS(NsCreated new connection %ssError on connect(): %s( RDRRER>RR@R4RARGRHRI(RRHR@((Rt __connect«s(R6R7RR RCRFRBR?(((RR"’s      t _ThreadFairycBstZdZd„ZRS(sJmarks a thread identifier as owning a connection, for a thread local pool.cCsti|ƒ|_dS(N(RtrefR&R(RR&((RR·s(R6R7R8R(((RRLµs RcBs_tZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z RS( sLproxies a DBAPI connection object and provides return-on-dereference supportcCs¦t|ƒ|_tiƒ|_||_d|_y%|i ƒ|_ |i i ƒ|_ Wnd|_ d|_ ‚nX|iio!|iidt|i ƒƒndS(Nis#Connection %s checked out from pool(RLRR(RtWeakKeyDictionarytcursorsR=t_ConnectionFairy__poolt_ConnectionFairy__counterR.R+RFR@R9RR4RA(RR=((RR¼s     cCsP|idjotidƒ‚n|iiƒd|_d|_|iƒdS(NsThis connection is closed( RR@R9t exceptionstInvalidRequestErrorR+RCROt_close(R((RRCÊs    cOsIy t||ii||ŽƒSWn"tj o}|iƒ‚nXdS(N( t _CursorFairyRR@tcursortargstkwargsRGRHRC(RRWRXRH((RRVÑs   cCst|i|ƒS(N(tgetattrRR@tkey(RRZ((Rt __getattr__×scCs6|idjotidƒ‚n|id7_|S(NsThis connection is closedi(RR@R9RRRSRQ(R((RR ÙscCs(x!t|iƒD]}|iƒqWdS(N(tlistRROtcR (RR]((Rtclose_open_cursorsÞscCs1|id8_|idjo|iƒndS(Nii(RRQRT(R((RR áscCs|iƒdS(N(RRT(R((Rt__del__åscCs|idj o`|iio|iƒqp|iio4t|iƒo ti dt|iƒƒ‚qlqpn|i dj oy|i i ƒWqŸqŸXn|i dj oB|ii o!|iidt|i ƒƒn|ii|ƒnd|_ d|_dS(Ns)This connection still has %d open cursorss$Connection %s being returned to pool(RROR9RPRR^RtlenRRRSR@trollbackR+RR4RAR,R((R((RRTçs"  ( ! ( R6R7R8RRCRVR[R R^R R_RT(((RRºs         RUcBs#tZd„Zd„Zd„ZRS(NcCs&||_t|ii|<||_dS(N(tparentRt_CursorFairy__parentR;RORV(RRbRV((RRþs cCs5||iijo|ii|=|iiƒndS(N(RRcRORVR (R((RR s cCst|i|ƒS(N(RYRRVRZ(RRZ((RR[s(R6R7RR R[(((RRUýs  tSingletonThreadPoolcBsPtZdZdd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS( s½Maintains one connection per each thread, never moving a connection to a thread other than the one which it was created in. this is used for SQLite, which both does not handle multithreading by default, and also requires a singleton connection if a :memory: database is being used. options are the same as those of Pool, as well as: pool_size=5 - the number of threads in which to maintain connections at once.icKs3t|dy |iitƒ}|iƒWqtij oPqXqWdS(N( R;RRoR.R:R0R RnRw(RR0((RR5lscCs2|iƒ|iƒ|iƒ|iƒf}d|S(Ns_Pool size: %d Connections in pool: %d Current Overflow: %d Current Checked out connections: %d(RRgt checkedinRyt checkedoutttup(RR|((RR1ts*cCs |iiS(N(RRotmaxsize(R((RRgxscCs |iiƒS(N(RRotqsize(R((RRz{scCs|iS(N(RRp(R((RRy~scCs|ii|iiƒ|iS(N(RRoR}R~Rp(R((RR{s( R6R7R8RR*R-R5R1RgRzRyR{(((RRmAs       tNullPoolcBs2tZdZd„Zd„Zd„Zd„ZRS(s a Pool implementation which does not pool connections; instead it literally opens and closes the underlying DBAPI connection per each connection open/close.cCsdS(NR((R((RR1‡scCs|iƒdS(N(R0R (RR0((RR*ŠscCsdS(N((RR0((Rtdo_return_invalidscCs |iƒS(N(RR#(R((RR-s(R6R7R8R1R*R€R-(((RR„s    t AssertionPoolcBsDtZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(sýa Pool implementation which will raise an exception if more than one connection is checked out at a time. Useful for debugging code that is using more connections than desired. TODO: modify this to handle an arbitrary connection count.cKs2ti|||t|ƒ|_|i|_dS(N(R RRRRR"R@t_conn(RRR((RR™scCsdS(NR((R((RR1žscCs d‚dS(NtInvalid((R((RR#¡scCs4||ijo|idjpt‚||_dS(N(R0RR‚R@R9tAssertionError(RR0((RR*¤s'cCs d‚dS(NRƒ((RR0((RR€¨scCs-|idj pt‚|i}d|_|S(N(RR@R9R„R](RR]((RR-«s  ( R6R7R8RR1R#R*R€R-(((RR“s      RcBsYtZdZed„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z RS( sšproxies a DBAPI2 connect() call to a pooled connection keyed to the specific connect parameters. other attributes are proxied through via __getattr__.cKs(||_||_||_h|_dS(s« module is a DBAPI2 module poolclass is a Pool class, defaulting to QueuePool. other parameters are sent to the Pool object's constructor. N(RRRt poolclasstpools(RRR…R((RRµs    cCs(x!|iiƒD]}|i|=qWdS(N(RR†RjRZ(RRZ((RR ÀscCs|iƒdS(N(RR (R((RR_ÄscCst|i|ƒS(N(RYRRRZ(RRZ((RR[ÇscsmˆiˆˆŽ}yˆi|SWnEtj o9ˆi‡‡‡d†ˆi}|ˆi|<|SnXdS(NcsˆiiˆˆŽS(N(RRR)RWR((RRWR(RtÏs( Rt _serializeRWRRZR†RR…R=(RRWRRZR=((RRWRRtget_poolÊs! cOs|i||ŽiƒS(séconnects to a database using this DBProxy's module and the given connect arguments. if the arguments match an existing pool, the connection will be returned from the pool's current thread-local connection instance, or if there is no thread-local connection instance it will be checked out from the set of pooled connections. If the pool has no available connections and allows new connections to be created, a new database connection will be made.N(RR‰RWRR)(RRWR((RR)ÓscOs:|i||Ž}y|i|=Wntj onXdS(sGdisposes the connection pool referenced by the given connect arguments.N(RRˆRWRRZR†R(RRWRRZ((RR5Üs cOsti||gƒS(N(tpickletdumpsRWR(RRWR((RRˆäs( R6R7R8RmRR R_R[R‰R)R5Rˆ(((RR±s     (R8RtstringRDtsystcPickleRŠt sqlalchemytutilRRRtqueueRnR$t dummy_threadRRR tobjectR R"RLRRURdRmRRR(R RRnRRdRURRR RŒRLRR"RRRR$RRDRRRRŠRm((Rt? s0$       ]#C 8C