_SrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ r SSK J r SSK J r JrJr SSKJr SSKJr SSKJr \ "S 5r\"\S 5(aS \R0;rO\R4S :HrS r\R8"\"\S5S5"SS\R:55r"SS\R:5r\ S:Xa\RB"5 gg)z: Very minimal unittests for parts of the readline module. N)verbose) import_module)unlinktemp_dirTESTFN)run_pty)assert_python_ok)requires_working_threadingreadline_READLINE_LIBRARY_VERSIONzEditLine wrappereditlinecB[(a[[S5(a:[S[RS35 [S[R S35 [[S5(a[S[R <35 [S[35 gg)N_READLINE_VERSIONzreadline version: z#xzreadline runtime version: r zreadline library version: zuse libedit emulation? )rhasattrr printr_READLINE_RUNTIME_VERSIONr is_editline9/opt/alt/python313/lib64/python3.13/test/test_readline.py setUpModulersw 80 1 1 &x'A'A"&EF G .x/Q/QRT.UV W 88 9 9 .x/Q/Q.TU V ' }56r clear_historyzXThe history update test cannot be run because the clear_history method is not available.cj\rSrSrSrSr\R"\"\ S5S5S5r Sr Sr S r g ) TestHistoryManipulation'z These tests were added to check that the libedit emulation on OSX and the "real" readline have the same interface for history manipulation. That's why the tests cover only a small subset of the interface. c[R5 [RS5 [RS5 UR[R S5S5 UR[R S5S5 UR[R S5S5 [R SS5 UR[R S5S5 UR[R S5S5 UR[R S5S5 UR[R 5S5 [RS5 UR[R S5S5 UR[R S5S5 UR[R 5S5 g)N first line second linerz replaced line)r r add_history assertEqualget_history_itemreplace_history_itemget_current_history_lengthremove_history_itemselfs rtestHistoryUpdates*TestHistoryManipulation.testHistoryUpdates1sR \*]+ 2215t< 2215|D 2215}E%%a9 2215t< 2215G 2215}E <<>B$$Q' 2215t< 2215}E <<>Brappend_history_filezappend_history not availablec4[R"SS9nUR5 URnUR [ U5 [ R5 [ RS5 [ RS5 [ RU5 [ R5 UR[ R5S5 [ RU5 UR[ R5S5 UR[ RS5S5 UR[ RS5S5 [ RSU5 [ R5 [ RU5 UR[ R5S5 UR[ RS5S5 UR[ RS5S5 UR[ RS5S5 [R "U5 [ RSU5 [R "U5 [ RU5 UR#[$5 [ RS U5 SSS5 UR#[$5 [ RS U5 SSS5 g![ a Nf=f!,(df  NS=f!,(df  g=f) NF)deleterrrr rii)tempfileNamedTemporaryFileclosename addCleanuprr rr!write_history_filer"r%read_history_filer#r+osFileNotFoundError assertRaises ValueError)r(hfile hfilenames rtest_write_read_append.TestHistoryManipulation.test_write_read_appendHs8++59 JJ   *  \*]+##I.  <<>B""9- <<>B 2215|D 2215}E $$Q 2 ""9- <<>B 2215|D 2215}E 2215}E ) !  ( (I 6 IIi ##I.  z *  ( (i 8+  z *  ( (i @+ *!!   + *+ *s*>K(K8L ( K54K58 L Lc[R5 [RS5 [RS5 [R SS5 [R[5 UR[R[5 [R5 [R[5 [(a[RS5 UR[RS5S5 UR[RS5S5 g![a(nUR S[ U5-5 SnAGN-SnAff=f)Nu entrée 1 Locale cannot encode test data: u entrée 2ru entrée 22dummyr )r rr!UnicodeEncodeErrorskipTestformatr$r4rr3r6remover5rr"r#)r(errs rtest_nonascii_history-TestHistoryManipulation.test_nonascii_history~s  L   - [)%%a6##F+  6* ""6* ;   ) 2215{C 2215|D" L MMB 446:""6* 2215}E 2215|D 2215t< h99;VDrrN)__name__ __module__ __qualname____firstlineno____doc__r)unittest skipUnlessrr r<rFrO__static_attributes__rrrrr'sH C.+@A792A92AhE&Errc6\rSrSr\R "\RS:=(a \(+S5S5r Sr Sr Sr Sr S rS r\R "\RS :S 5\R "\S 5S55r\"5S5rSrSrg) TestReadlineiz%not supported in this library versioncD[SSSS9upnURUS5 g)Nz-czimport readlinezxterm-256color)TERMr)r r")r(rcstdoutstderrs r test_initTestReadline.test_inits, .d4E3CEF %rcDUR[RS5 g)N)r r )rLr backendr's r test_backendTestReadline.test_backends h&&(@Arzvimport readline readline.set_auto_history({}) input() print("History length:", readline.get_current_history_length()) cp[URRS55nURSU5 g)NTsHistory length: 1rauto_history_scriptrCrLr(outputs rtest_auto_history_enabled&TestReadline.test_auto_history_enableds.1188>? *F3rcp[URRS55nURSU5 g)NFsHistory length: 0rhrjs rtest_auto_history_disabled'TestReadline.test_auto_history_disableds.1188?@ *F3rch[R"S5n[USS9nURSU5 g)Na import readline def complete(text, state): if state == 0 and text == "$": return "$complete" return None if readline.backend == "editline": readline.parse_and_bind(r'bind "\t" rl_complete') else: readline.parse_and_bind(r'"\t": complete') readline.set_completer_delims(" \t\n") readline.set_completer(complete) print(input()) s$ inputs $completetextwrapdedentrrLr(scriptrks rtest_set_complete_delims%TestReadline.test_set_complete_delimss1 "  x0 lF+rc[R"[RS5nUS;aURSU<35 [R R (aP[R"5n[R"U5RnUS:waURSU<35 [RS5 SnSnUS [S 5-- nUS - nUS - nUS - n[!XE5nUR#SU5 UR#SU5 [R$S:Xd [&(dUR#SU5 [&(d9[)[S5(a$UR#SU5 UR#SU5 SnUR#SU-S-U5 UR#SU-U5 g![a(nURS[U5-5 SnAGN%SnAff=f)N)CPOSIXzthe LC_CTYPE locale is zutf-8zthe LC_CTYPE encoding is uëïr?aimport readline is_editline = readline.backend == "editline" inserted = "[\xEFnserted]" macro = "|t\xEB[after]" set_pre_input_hook = getattr(readline, "set_pre_input_hook", None) if is_editline or not set_pre_input_hook: # The insert_line() call via pre_input_hook() does nothing with Editline, # so include the extra text that would have been inserted here macro = inserted + macro if is_editline: readline.parse_and_bind(r'bind ^B ed-prev-char') readline.parse_and_bind(r'bind "\t" rl_complete') readline.parse_and_bind(r'bind -s ^A "{}"'.format(macro)) else: readline.parse_and_bind(r'Control-b: backward-char') readline.parse_and_bind(r'"\t": complete') readline.parse_and_bind(r'set disable-completion off') readline.parse_and_bind(r'set show-all-if-ambiguous off') readline.parse_and_bind(r'set show-all-if-unmodified off') readline.parse_and_bind(r'Control-a: "{}"'.format(macro)) def pre_input_hook(): readline.insert_text(inserted) readline.redisplay() if set_pre_input_hook: set_pre_input_hook(pre_input_hook) def completer(text, state): if text == "t\xEB": if state == 0: print("text", ascii(text)) print("line", ascii(readline.get_line_buffer())) print("indexes", readline.get_begidx(), readline.get_endidx()) return "t\xEBnt" if state == 1: return "t\xEBxt" if text == "t\xEBx" and state == 0: return "t\xEBxt" return None readline.set_completer(completer) def display(substitution, matches, longest_match_length): print("substitution", ascii(substitution)) print("matches", ascii(matches)) readline.set_completion_display_matches_hook(display) print("result", ascii(input())) print("history", ascii(readline.get_history_item(1))) z[after]s sx  stext 't\xeb' s#line '[\xefnserted]|t\xeb[after]' darwinsindexes 11 13 set_pre_input_hookssubstitution 't\xeb' s matches ['t\xebnt', 't\xebxt'] s'[\xefnserted]|t\xebxt[after]'sresult s shistory )locale setlocaleLC_CTYPErBsysflags utf8_mode getencodingcodecslookupr2r r!rArClenrrLplatformrr)r(locencodingrErxrsrkexpecteds r test_nonasciiTestReadline.test_nonasciisv5 .  MM3C7; < 99  ))+H}}X.33H7" 9(FG L   ,2h 3y>))   ' *F3 @&I <<8 #;; MM. 7{wx1EFF MM6 ? MMA6 J5 j8+g5v> kH,f5c" L MM> G0G++G0iz3this readline version does not support history-sizez-editline history size configuration is brokenc @Sn[5n[RRUS5n[ US5nUR SU-5 SSS5 [RRUS5n[ US5nSRS[ US-555nUR U5 SSS5 S n[[R5nX8S 'XXS '[US US 9 [ US5nUR5n SSS5 UR[W 5U5 URU SR5S5 SSS5 g!,(df  GN=f!,(df  N=f!,(df  Nx=f!,(df  g=f)N inputrcwbsset history-size %d historyrc3,# UH nSU-v M g7f)sitem %d Nr).0is r 1TestReadline.test_history_size..Xs B)@A!-q 0)@sr z import os import readline history_file = os.environ["HISTORY_FILE"] readline.read_history_file(history_file) input() readline.write_history_file(history_file) INPUTRC HISTORY_FILEs last input )rsenvrbs last input)rr6pathjoinopenwriterangedictenvironr readlinesr"rstrip) r( history_sizetest_dirrf history_filedatarxrliness rtest_history_sizeTestReadline.test_history_sizeJsF  Z8ggll8Y7Ggt$0<?@%77<<)?Z$$*),*)9ZsT-FE4F6E-9AF;E> AF E* %F- E; 7F> F F Fch[R"S5n[USS9nURSU5 g)z7gh-123321: readline should be thread-safe and not crasha import threading from test.support.threading_helper import join_thread def func(): input() thread1 = threading.Thread(target=func) thread2 = threading.Thread(target=func) thread1.start() thread2.start() join_thread(thread1) join_thread(thread2) print("done") sinput1 input2 rrsdoneNrtrws rtest_gh123321_threadsafe%TestReadline.test_gh123321_threadsafeqs4"   ':; gv&rc[R5nUR[RU5 [R S5 [R S5 [R S5 [RS5 UR [R5S5 [R [5 UR[R[5 [R[5 g)NrrrIr ) r rJr3rKr!r"r4rr6rDr5rMs rrO,TestReadline.test_write_read_limited_historys"557 33_E\*]+\*##A& 446:##F+  6*""6*rrN)rQrRrSrTrVskipIfr rrrarerirlroryrrr rrOrXrrrrZrZs __X//&8L_<>&>&B4 4 ,&b6R__X//%7JL __[DF!?FL!?F !'"'. +rrZ__main__)"rUrrr6rr/rurV test.supportrtest.support.import_helperrtest.support.os_helperrrrtest.support.pty_helperrtest.support.script_helperr test.support.threading_helperr r rr rrdrrWTestCaserrZrQmainrrrrs  4;;+7D  $ 8011%)K)KKK""j0K 7 WX7>?Ex00E?EDj+8$$j+d z MMOr