o k`8@s@ddlmZmZmZddgZGdddeZGdddeZdS)) datetime_nowutc to_utimestamp SubscriptionWatchc@seZdZdZdZddZddZddZd d Zd d Z e d dZ e d$ddZ e d$ddZ e ddZe ddZe d%ddZe ddZe ddZe ddZd d!Zd"d#ZdS)&renvvalues)idsid authenticated distributorformatpriorityadverbclasscC||_i|_dSNrselfrr9/usr/lib/python3/dist-packages/trac/notification/model.py__init__ zSubscription.__init__cs*dfddjD}djj|fS)N c3s$|] }d|j|fVqdS)z%s=%rN)r get.0namerrr sz(Subscription.__repr__..z<%s %s>)joinfields __class____name__)rr rrr__repr__szSubscription.__repr__cC||jvr t||j|Srr"KeyErrorr rrrrrr __getitem__$  zSubscription.__getitem__cC ||jvr t|||j|<dSrr"r(r rrvaluerrr __setitem__) zSubscription.__setitem__c CsP||d<||d<t||d<||d<|pd|d<t||d<||d<||d<dS) Nr r r r rrrrint) rr r r r rrrclass_rrr_from_database.s    zSubscription._from_databasecCs|jK}t|||d|d|dd}ttt}|}|d|||dt|d|d|dp5dt||d|d f | |d WdS1sQwYdS) zid and priority overwritten.r r r a INSERT INTO notify_subscription (time, changetime, sid, authenticated, distributor, format, priority, adverb, class) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)rNrrnotify_subscription) db_transactionlenfind_by_sid_and_distributorrrrcursorexecuter3 get_last_id)clsr subscriptiondbrnowr;rrradd9s$   $zSubscription.addNc s|je}d|i}|dus|dur||d<|rdnd|d<|j|fi|D]}n WddS|d|df|||d|d|d}tttfdd t|dD} |d | WddS1skwYdS) Nr r r6rr z+DELETE FROM notify_subscription WHERE id=%sr c*g|]\}}||dkr||dfqSrr rr new_prioritysubrArr ]   z'Subscription.delete..w UPDATE notify_subscription SET priority=%s, changetime=%s WHERE id=%s )r8_findr:rrr enumerate executemany) r>rrule_idr r r@kwargsrGsubsr rrHrdeleteNs*   "zSubscription.deletec sJ|j}d|i}|dus|dur||d<|rdnd|d<|j|fi|D]}n WddS|||d|d|d} d|krLt| ksVn WddSt| D] \} }|d|krfn qZ WddS| |d| | ttt fddt| dD} | d | WddS1swYdS) Nr r r6rr r crCrDrrErHrrrI{rJz%Subscription.move..rK) r8rLr:r9rMinsertpoprrrrN) r>rrOrr r r@rPrGrQidxr rrHrmovees<    "zSubscription.movecCst|}|j}i}|d||fD]\}}} ||| fg|q|D]} | jddq&i} ttt} |D]X} | d}| |d| |d7<| |}|| df}| |ry|| }|d| | d| d pmd|| d | d|fq9|d | | ||| d| d pd|| d | df q9g}|D]} | | q|r|d d dt ||WddSWddS1swYdS)Nz SELECT id, distributor, class FROM notify_subscription WHERE sid=%s AND authenticated=%sT)reverser rr6rz UPDATE notify_subscription SET changetime=%s,distributor=%s,format=%s,priority=%s, adverb=%s,class=%s WHERE id=%srrz INSERT INTO notify_subscription ( time,changetime,sid,authenticated,distributor, format,priority,adverb,class) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)z0DELETE FROM notify_subscription WHERE id IN (%s),)z%s)r3r8 setdefaultappendr sortrrrrrTextendr!r9)r>rr r subscriptionsr@ids_mapid_r r4ids prioritiesrArGpriokey delete_idsrrr replace_allsT        ("zSubscription.replace_allcCsF|j}|d|p d||t|fWddS1swYdS)Nz UPDATE notify_subscription SET format=%s WHERE distributor=%s AND sid=%s AND authenticated=%s r8r3)r>rr r r rr@rrr$update_format_by_distributor_and_sids "z1Subscription.update_format_by_distributor_and_sidc +s|j~g}g}t|D]&\}}|dr|dd}|dkr&t|}||d||qd}|rC|dd|7}|r_t|t t fsO|f}|dd fd d |D7} } | ||| D]} t |} | j| | VqkWddS1swYdS) N_r =%szdSELECT id, sid, authenticated, distributor, format, priority, adverb, class FROM notify_subscription WHERE  AND ORDER BY , c3|]}|VqdSrquoterr@rrr z%Subscription._find..)db_querysorteditemsendswithr3rZrqr! isinstancetuplelistr;r<rr5) r>rorderrP conditionsargsrr/queryr;rowrGrrrrrLs8     "zSubscription._findcCt|j||||ddS)Nr)r r r r{rzrL)r>rr r r rrrr: z(Subscription.find_by_sid_and_distributorc Cs0g}|D]\}}||j||||ddq|S)z1uids should be a collection to tuples (sid, auth)r)r4r r r{)r\rL)r>ruidsr4rQr r rrrfind_by_sids_and_classs  z#Subscription.find_by_sids_and_classcCst|j||dS)N)r4r)r>rr4rrr find_by_classszSubscription.find_by_classc CsF|jd|jd|jd|jdd|jdpdt|jd|jdfS)Nrr r r rrr)r r3rrrrsubscription_tuples  zSubscription.subscription_tuplecCsd|jj$}|}ttt}|d|t|jd|jdfWddS1s+wYdS)Nz UPDATE notify_subscription SET changetime=%s, priority=%s WHERE id=%s rr ) rr8r;rrrr<r3r )rr@r;rArrr_update_prioritys  "zSubscription._update_priority)NNr)r$ __module__ __qualname__ __slots__r"rr%r*r0r5 classmethodrBrRrVrergrLr:rrrrrrrrrs8    /      c@seZdZdZdZddZddZddZd d Ze d d Z e d dZ e ddZ e ddZ e dddZe ddZe ddZe ddZe ddZdS)rr)r r r rrealmtargetcCrrrrrrrr rzWatch.__init__cCr&rr'r)rrrr*r+zWatch.__getitem__cCr,rr-r.rrrr0r1zWatch.__setitem__cCs8||d<||d<t||d<||d<||d<||d<dS)Nr r r rrrr2)rr r r r4rrrrrr5s   zWatch._from_databasec CsN|j}|D]}|d|t||||fqWddS1s wYdS)Nz INSERT INTO notify_watch (sid, authenticated, class, realm, target) VALUES (%s, %s, %s, %s, %s) rf) r>rr r r4rtargetsr@rrrrrB!s"z Watch.addcCs8|j}|d|fWddS1swYdS)Nz&DELETE FROM notify_watch WHERE id = %sr8)r>rwatch_idr@rrrrR+s"z Watch.deletecCs@|j}|d|t||fWddS1swYdS)Nz{ DELETE FROM notify_watch WHERE sid = %s AND authenticated = %s AND class = %s rf)r>rr r r4r@rrrdelete_by_sid_and_class0s  "zWatch.delete_by_sid_and_classcCs<|j}|d|||fWddS1swYdS)Nzv DELETE FROM notify_watch WHERE class = %s AND realm = %s AND target = %s r)r>rr4rrr@rrr delete_by_class_realm_and_target8s "z&Watch.delete_by_class_realm_and_targetNc +s(|jg}g}t|D].\}}|dr|dd}|dkr&t|}||d|dkr8t|}||qd}|rK|dd|7}|rgt|t t fsW|f}|dd fd d |D7} } | ||| D]} t |} | j| | VqsWddS1swYdS) Nrhrir rjzESELECT id, sid, authenticated, class, realm, target FROM notify_watchrkrlrmrnc3rorrprrrrrr VrszWatch._find..)rtrurvrwr3rZrqr!rxryrzr;r<rr5) r>rr{rPr|r}rr/r~r;rwatchrrrrrL@s<     "z Watch._findcCr)Nr)r r r4r{r)r>rr r r4rrrfind_by_sid_and_class^rzWatch.find_by_sid_and_classc Cst|j|||||ddS)Nr)r r r4rr{r)r>rr r r4rrrrr"find_by_sid_class_realm_and_targetcs z(Watch.find_by_sid_class_realm_and_targetcCst|j||||dS)N)r4rrr)r>rr4rrrrrfind_by_class_realm_and_targetisz$Watch.find_by_class_realm_and_targetcCst|j|||dS)N)r4rr)r>rr4rrrrfind_by_class_and_realmmszWatch.find_by_class_and_realmr)r$rrrr"rr*r0r5rrBrRrrrLrrrrrrrrrs2        N)trac.util.datefmtrrr__all__objectrrrrrrs r