ó {fc@sbdZddlmZdd d„ƒYZedkr^ddlmZeddd d eƒnd S( s9Implement Idle Shell history mechanism with History classi˙˙˙˙(tidleConftHistorycBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s@ Implement Idle Shell history mechanism. store - Store source statement (called from PyShell.resetoutput). fetch - Fetch stored statement matching prefix already entered. history_next - Bound to <> event (default Alt-N). history_prev - Bound to <> event (default Alt-P). cCsl||_g|_d|_d|_tjdddddƒ|_|jd|j ƒ|jd|j ƒdS( sdInitialize data attributes and bind event methods. .text - Idle wrapper of tk Text widget, with .bell(). .history - source statements, possibly with multiple lines. .prefix - source already entered at prompt; filters history list. .pointer - index into history. .cyclic - wrap around history list (or not). tmainRtcyclicitbools<>s<>N( ttextthistorytNonetprefixtpointerRt GetOptionRtbindt history_prevt history_next(tselfR((s+/usr/lib64/python2.7/idlelib/IdleHistory.pyt__init__ s    cCs|jdtƒdS(s4Fetch later statement; start with ealiest if cyclic.treversetbreak(tfetchtFalse(Rtevent((s+/usr/lib64/python2.7/idlelib/IdleHistory.pyR scCs|jdtƒdS(s0Fetch earlier statement; start with most recent.RR(RtTrue(RR((s+/usr/lib64/python2.7/idlelib/IdleHistory.pyR #scCsGt|jƒ}|j}|j}|dk r–|dk r–|jjdddƒss|jjddƒ|j|kr–d}}|jjddƒq–n|dksŽ|dkrř|jjddƒ}|rŇ|}qř|j räd}qř|jj ƒdSnt|ƒ}x||rdnd7}|dks5||krŽ|jj ƒ|j r\|dkr\dS|jjddƒ|kr |jj ddƒ|jj d|ƒnd}}Pn|j|}|| |krt|ƒ|kr|jj ddƒ|jj d|ƒPqqW|jj dƒ|jjd d d ƒ||_||_dS( s+Fetch statememt and replace current line in text widget. Set prefix and pointer as needed for successive fetches. Reset them to None, None when returning to the start line. Sound bell when return to start line or cannot leave a line because cyclic is False. tinserts!=send-1ctiomarki˙˙˙˙Niitsels1.0tend(tlenRR RRRtcomparetgettmark_setRtbelltdeleteRtseet tag_remove(RRtnhistR Rtnprefixtitem((s+/usr/lib64/python2.7/idlelib/IdleHistory.pyR(sJ  "         " cCso|jƒ}t|ƒdkrYy|jj|ƒWntk rEnX|jj|ƒnd|_d|_dS(s.Store Shell input statement into history list.iN( tstripRRtremovet ValueErrortappendRR R(Rtsource((s+/usr/lib64/python2.7/idlelib/IdleHistory.pytstoreYs   (t__name__t __module__t__doc__RR R RR*(((s+/usr/lib64/python2.7/idlelib/IdleHistory.pyRs     1t__main__(Rs"idlelib.idle_test.test_idlehistoryt verbosityitexitN((R-tidlelib.configHandlerRRR+tunittestRR(((s+/usr/lib64/python2.7/idlelib/IdleHistory.pyts a