ó Tc @s5dZddlZddlmZmZddlmZmZmZm Z ddlm Z m Z m Z de fd„ƒYZed„Zd e fd „ƒYZd e fd „ƒYZd efd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZeeeƒeeeddddddƒZejƒeeeddddddƒZejƒeeedd dd!dd"ƒZejƒed#edd$dd%dd&ƒZejƒed'edd(dd)dd*ƒZejƒed+edd,dd-dd.ƒZejƒdS(/s1Implementation of the Range type and adaptation iÿÿÿÿN(tProgrammingErrortInterfaceError(t ISQLQuotetadapttregister_adaptertb(tnew_typetnew_array_typet register_typetRangecBsìeZdZdZddded„Zd„Zed„ƒZ ed„ƒZ ed „ƒZ ed „ƒZ ed „ƒZ ed „ƒZed „ƒZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s…Python representation for a PostgreSQL |range|_ type. :param lower: lower bound for the range. `!None` means unbound :param upper: upper bound for the range. `!None` means unbound :param bounds: one of the literal strings ``()``, ``[)``, ``(]``, ``[]``, representing whether the lower or upper bounds are included :param empty: if `!True`, the range is empty t_lowert_uppert_boundss[)cCs^|sC|dkr%td|ƒ‚n||_||_||_nd|_|_|_dS(Ns[)s(]s()s[]sbound flags not valid: %r(s[)s(]s()s[](t ValueErrorR R R tNone(tselftlowertuppertboundstempty((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__init__-s    cCsD|jdkrd|jjSd|jj|j|j|jfSdS(Ns%s(empty=True)s%s(%r, %r, %r)(R Rt __class__t__name__R R (R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__repr__8s cCs|jS(s:The lower bound of the range. `!None` if empty or unbound.(R (R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR?scCs|jS(s:The upper bound of the range. `!None` if empty or unbound.(R (R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyRDscCs |jdkS(s`!True` if the range is empty.N(R R(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pytisemptyIscCs |jdkrtS|jdkS(s0`!True` if the range doesn't have a lower bound.N(R RtFalseR (R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt lower_infNscCs |jdkrtS|jdkS(s1`!True` if the range doesn't have an upper bound.N(R RRR (R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt upper_infTscCs7|jdkrtS|jdkr&tS|jddkS(s4`!True` if the lower bound is included in the range.it[N(R RRR (R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt lower_incZs cCs7|jdkrtS|jdkr&tS|jddkS(s4`!True` if the upper bound is included in the range.it]N(R RRR (R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt upper_incas cCs³|jdkrtS|jdk ra|jddkrK||jkr^tSqa||jkratSn|jdk r¯|jddkr™||jkr¬tSq¯||jkr¯tSntS(NiRiR(R RRR R tTrue(Rtx((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt __contains__hscCs |jdk S(N(R R(R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt __nonzero__xscCsGt|tƒstS|j|jkoF|j|jkoF|j|jkS(N(t isinstanceR RR R R (Rtother((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__eq__{s cCs|j|ƒ S(N(R&(RR%((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__ne__‚scCst|j|j|jfƒS(N(thashR R R (R((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__hash__…scCst|tƒstSxedD]]}t||ƒ}t||ƒ}||krMq|dkr]tS|dkrmtS||kSqWtS(NR R R (s_lowers_uppers_bounds(R$R tNotImplementedtgetattrRR R(RR%tattrt self_valuet other_value((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__lt__Œs    cCs!||krtS|j|ƒSdS(N(R R/(RR%((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__le__œs cCs$t|tƒr|j|ƒStSdS(N(R$R R/R*(RR%((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__gt__¢s cCs!||krtS|j|ƒSdS(N(R R1(RR%((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt__ge__¨s (s_lowers_uppers_boundsN(Rt __module__t__doc__t __slots__RRRRtpropertyRRRRRRRR"R#R&R'R)R/R0R1R2(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR !s(          cCs3tj|||ƒ}|j| r(|p+dƒ|S(séCreate and register an adapter and the typecasters to convert between a PostgreSQL |range|_ type and a PostgreSQL `Range` subclass. :param pgrange: the name of the PostgreSQL |range| type. Can be schema-qualified :param pyrange: a `Range` strict subclass, or just a name to give to a new class :param conn_or_curs: a connection or cursor used to find the oid of the range and its subtype; 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 :return: `RangeCaster` instance responsible for the conversion If a string is passed to *pyrange*, a new `Range` subclass is created with such name and will be available as the `~RangeCaster.range` attribute of the returned `RangeCaster` object. The function queries the database on *conn_or_curs* to inspect the *pgrange* type and raises `~psycopg2.ProgrammingError` if the type is not found. If querying the database is not advisable, use directly the `RangeCaster` class and register the adapter and typecasters using the provided functions. N(t RangeCastert_from_dbt _registerR(tpgrangetpyranget conn_or_curstgloballytcaster((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pytregister_range¯st RangeAdaptercBs8eZdZdZd„Zd„Zd„Zd„ZRS(s¢`ISQLQuote` adapter for `Range` subclasses. This is an abstract class: concrete classes must set a `name` class attribute or override `getquoted()`. cCs ||_dS(N(tadapted(RRA((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyRÖscCs|jtkr|SdS(N(t_protoR(Rtproto((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyt __conform__ÙscCs ||_dS(N(t_conn(Rtconn((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pytprepareÝscCs+|jdkrtdƒ‚n|j}|jrAtd|jƒS|jdk rt|jƒ}t|dƒr|j |j ƒn|j ƒ}n tdƒ}|j dk rët|j ƒ}t|dƒrÜ|j |j ƒn|j ƒ}n tdƒ}t|jdƒ|tdƒ|td|j ƒS(NsMRangeAdapter must be subclassed overriding its name or the getquoted() methods 'empty'::RGtNULLt(s, s, '%s')(tnameRtNotImplementedErrorRARRRRthasattrRGREt getquotedRR (RtrtaRR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyRMàs&     N( RR3R4RRJRRDRGRM(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR@Îs    R7cBsneZdZdd„Zd„Zed„ƒZej dej ƒZ ej dƒZ dd„Z dd„ZRS( s Helper class to convert between `Range` and PostgreSQL range types. Objects of this class are usually created by `register_range()`. Manual creation could be useful if querying the database is not advisable: in this case the oids must be provided. cCsŠ||_|j||ƒ|jjp1|jjj}t|f||jƒ|_|dk r}t |f|d|jƒ|_ n d|_ dS(NtARRAY( t subtype_oidt_create_rangestadapterRJRRRtparset typecasterRRtarray_typecaster(RR:R;toidRQt array_oidRJ((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyRs  cCs0d|_t|tƒr?t|tfiƒ|_||j_n?y+t|tƒri|tk ri||_nWntk r}nX|jdkrœtdƒ‚nd|_ yUt|tƒrÒt|t fiƒ|_ nt|t ƒrù|t k rù||_ nWntk r nX|j dkr,tdƒ‚ndS(s0Create Range and RangeAdapter classes if needed.s:pgrange must be a string or a RangeAdapter strict subclasss1pyrange must be a type or a Range strict subclassN( RRSR$t basestringttypeR@RJt issubclasst TypeErrortrangeR (RR:R;((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyRRs.     c CsPddlm}ddlm}||ƒ\}}|jdkrWtd|jƒ‚n|j}d|kr‡|jddƒ\} } n |} d} y|jd | | fƒWn*tk rÙ|j sÓ|j ƒn‚n0X|j ƒ} ||kr |j r |j ƒn| s"td |ƒ‚n| \} } }t ||d | d | d |ƒS(s|Return a `RangeCaster` instance for the type *pgrange*. Raise `ProgrammingError` if the type is not found. iÿÿÿÿ(tSTATUS_IN_TRANSACTION(t_solve_conn_cursiX`s'range types not available in version %st.itpublicsÞselect rngtypid, rngsubtype, (select typarray from pg_type where oid = rngtypid) from pg_range r join pg_type t on t.oid = rngtypid join pg_namespace ns on ns.oid = typnamespace where typname = %s and ns.nspname = %s; sPostgreSQL type '%s' not foundRWRQRX( tpsycopg2.extensionsR^tpsycopg2.extrasR_tserver_versionRtstatustsplittexecutet autocommittrollbacktfetchoneR7(RRJR;R<R^R_RFtcurst conn_statustschemattnametrecRZtsubtypetarray((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR85s8          s] ( \(|\[ ) # lower bound flag (?: # lower bound: " ( (?: [^"] | "")* ) " # - a quoted string | ( [^",]+ ) # - or an unquoted string )? # - or empty (not catched) , (?: # upper bound: " ( (?: [^"] | "")* ) " # - a quoted string | ( [^"\)\]]+ ) # - or an unquoted string )? # - or empty (not catched) ( \)|\] ) # upper bound flag s (["\\])\1cCsg|dkrdS|dkr,|jdtƒS|jj|ƒ}|dkr]td|ƒ‚n|jdƒ}|dkr®|jdƒ}|dk r®|jjd|ƒ}q®n|jdƒ}|dkrÿ|jdƒ}|dk rÿ|jjd|ƒ}qÿn|dk r8|j |j |ƒ}|j |j |ƒ}n|jdƒ|jd ƒ}|j|||ƒS( NRsfailed to parse range: '%s'iis\1iiii( RR]R t _re_rangetmatchRtgroupt _re_undoubletsubtcastRQ(RtstcurtmRRR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyRT}s,        cCsIt|j|ƒ|jdk r2t|j|ƒnt|j|jƒdS(N(RRURVRRR]RS(Rtscope((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR9œsN(RR3R4RRRRt classmethodR8tretcompiletVERBOSERrRuRTR9(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR7þs  "8  t NumericRangecBseZdZRS(sÄA `Range` suitable to pass Python numeric types to a PostgreSQL range. PostgreSQL types :sql:`int4range`, :sql:`int8range`, :sql:`numrange` are casted into `!NumericRange` instances. (RR3R4(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR€¤st DateRangecBseZdZRS(s#Represents :sql:`daterange` values.(RR3R4(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR¬st DateTimeRangecBseZdZRS(s!Represents :sql:`tsrange` values.(RR3R4(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR‚°stDateTimeTZRangecBseZdZRS(s#Represents :sql:`tstzrange` values.(RR3R4(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyRƒ´stNumberRangeAdaptercBseZdZd„ZRS(s1Adapt a range if the subtype doesn't need quotes.cCs§|j}|jrtdƒS|jsFt|jƒjƒjdƒ}nd}|jsvt|j ƒjƒjdƒ}nd}d|j d|||j dfj dƒS(Ns'empty'tasciits '%s%s,%s%s'ii( RARRRRRRMtdecodeRRR tencode(RRNRR((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyRMÀs    ! !(RR3R4RM(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyR„¾sRWi@RQiRXiAiViiWiBi¤iCt daterangeiHi:iIttsrangeiDiZiEt tstzrangeiFi iG(R4R}tpsycopg2._psycopgRRRbRRRRRRRtobjectR RR?R@R7R€RR‚RƒR„tint4range_casterR9tint8range_castertnumrange_castertdaterange_casterttsrange_casterttstzrange_caster(((sB/opt/alt/python27/lib64/python2.7/site-packages/psycopg2/_range.pyts@ "Ž 0¦