5Xc@sXdZyddlmZWn!ek r=ddlmZnXdefdYZdS(spasslib.utils.compat._ordered_dict -- backport of collections.OrderedDict for py26 taken from stdlib-suggested recipe at http://code.activestate.com/recipes/576693/ this should be imported from passlib.utils.compat.OrderedDict, not here. i(t get_identt OrderedDictcBseZdZdZejdZejdZdZdZdZ e dZ dZ d Z d Zd Zd Zd ZdZeZeZedZddZidZdZdZeddZdZdZRS(s)Dictionary that remembers insertion ordercOst|dkr+tdt|ny |jWn7tk rog|_}||dg|(i|_nX|j||dS(sInitialize an ordered dictionary. Signature is the same as for regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary. is$expected at most 1 arguments, got %dN(tlent TypeErrort_OrderedDict__roottAttributeErrortNonet_OrderedDict__mapt_OrderedDict__update(tselftargstkwdstroot((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt__init__s    cCs\||krH|j}|d}|||g|d<|d<|j| od[i]=yiiN(RR(R tkeytvaluet dict_setitemR tlast((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt __setitem__)s    )cCs@||||jj|\}}}||d<||d del od[y]iiN(Rtpop(R Rt dict_delitemt link_prevt link_next((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt __delitem__3s  ccs=|j}|d}x#||k r8|dV|d}qWdS(sod.__iter__() <==> iter(od)iiN(R(R R tcurr((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt__iter__<s    ccs=|j}|d}x#||k r8|dV|d}qWdS(s#od.__reversed__() <==> reversed(od)iiN(R(R R R((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt __reversed__Ds    cCsmyHx|jjD] }|2qW|j}||dg|(|jjWntk r[nXtj|dS(s.od.clear() -> None. Remove all items from od.N(Rt itervaluesRRtclearRtdict(R tnodeR ((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyRLs  cCs|stdn|j}|rO|d}|d}||d<||d (k, v), return and remove a (key, value) pair. Pairs are returned in LIFO order if last is true or FIFO order if false. sdictionary is emptyiii(tKeyErrorRRRR(R RR tlinkRRRR((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pytpopitemXs            cCs t|S(sod.keys() -> list of keys in od(tlist(R ((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pytkeysqscCsg|D]}||^qS(s#od.values() -> list of values in od((R R((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pytvaluesuscCs!g|D]}|||f^qS(s.od.items() -> list of (key, value) pairs in od((R R((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pytitemsyscCs t|S(s0od.iterkeys() -> an iterator over the keys in od(titer(R ((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pytiterkeys}sccsx|D]}||VqWdS(s2od.itervalues -> an iterator over the values in odN((R tk((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyRs ccs$x|D]}|||fVqWdS(s=od.iteritems -> an iterator over the (key, value) items in odN((R R(((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt iteritemss cOs&t|dkr.tdt|fn|sCtdn|d}d}t|dkrr|d}nt|trxw|D]}|||| None. Update od from dict/iterable E and F. If E is a dict instance, does: for k in E: od[k] = E[k] If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] Or if E is an iterable of items, does: for k, v in E: od[k] = v In either case, this is followed by: for k, v in F.items(): od[k] = v is8update() takes at most 2 positional arguments (%d given)s,update() takes at least 1 argument (0 given)iiR#N((RRt isinstanceRthasattrR#R%(R R R totherRR((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pytupdates&    cCsC||kr!||}||=|S||jkr?t|n|S(sod.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised. (t_OrderedDict__markerR(R Rtdefaulttresult((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyRs  cCs"||kr||S|||<|S(sDod.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od((R RR/((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt setdefaults  cCsst|tf}||kr%dSd|| repr(od)s...is%s()s%s(%r)N(tidt _get_identt __class__t__name__R%(R t _repr_runningtcall_key((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt__repr__s  cCsg|D]}|||g^q}t|j}x'ttD]}|j|dqEW|rx|j|f|fS|j|ffS(s%Return state information for picklingN(tvarstcopyRRRR4(R R(R%t inst_dict((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt __reduce__s#cCs |j|S(s!od.copy() -> a shallow copy of od(R4(R ((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyR:scCs(|}x|D]}||| New ordered dictionary with keys from S and values equal to v (which defaults to None). ((tclstiterableRtdR((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pytfromkeyss  cCsMt|tr=t|t|ko<|j|jkStj||S(sod.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive while comparison to a regular mapping is order-insensitive. (R*RRR%Rt__eq__(R R,((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyRAs.cCs ||k S(N((R R,((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyt__ne__sN( R5t __module__t__doc__R RRRRRRtTrueR!R#R$R%R'RR)R-RtobjectR.RRR1R8R<R:t classmethodR@RARB(((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyR s4                N(RDtthreadRR3t ImportErrort dummy_threadRR(((sF/usr/lib/python2.7/site-packages/passlib/utils/compat/_ordered_dict.pyts