Files
ServerSync/lib/prompt_toolkit/__pycache__/patch_stdout.cpython-314.pyc

119 lines
14 KiB
Plaintext
Raw Normal View History

2026-02-12 02:28:23 +02:00
+
9<><39>i%<00><01><><00>Rt^RIHt^RIt^RIt^RIt^RIt^RIt^RIH t ^RI
H t H t H t ^RIHtHt^RIHtRR.t] RR R
ll4t!R R 4t!R R4tR#)a<>
patch_stdout
============
This implements a context manager that ensures that print statements within
it won't destroy the user interface. The context manager will replace
`sys.stdout` by something that draws the output above the current prompt,
rather than overwriting the UI.
Usage::
with patch_stdout(application):
...
application.run()
...
Multiple applications can run in the body of the context manager, one after the
other.
)<01> annotationsN)<01>contextmanager)<03> Generator<6F>TextIO<49>cast)<02>get_app_session<6F>run_in_terminal)<01>Output<75> patch_stdout<75> StdoutProxyc<01> <00>V^8<>dQhRRRR/#)<05><00>raw<61>bool<6F>returnzGenerator[None, None, None]<5D>)<01>formats"<22>B/tmp/pip-target-wqrk2shd/lib/python/prompt_toolkit/patch_stdout.py<70> __annotate__r)s<00><00>)<29>)<29>d<EFBFBD>)<29>'B<>)<29>c#<05><>"<00>\VR7;_uu_4p\Pp\Pp\ \
V4\n\ \
V4\nRx<00>V\nV\nRRR4R# T\nT\ni;i +'giR#;i5i)a<>
Replace `sys.stdout` by an :class:`_StdoutProxy` instance.
Writing to this proxy will make sure that the text appears above the
prompt, and that it doesn't destroy the output from the renderer. If no
application is curring, the behavior should be identical to writing to
`sys.stdout` directly.
Warning: If a new event loop is installed using `asyncio.set_event_loop()`,
then make sure that the context manager is applied after the event loop
is changed. Printing to stdout will be scheduled in the event loop
that's active when the context manager is created.
:param raw: (`bool`) When True, vt100 terminal escape sequences are not
removed/escaped.
)rN)r <00>sys<79>stdout<75>stderrrr)r<00>proxy<78>original_stdout<75>original_stderrs& rr
r
(s<00><00><00>$
<15><13> <1D> <1D><15><1D>*<2A>*<2A><0F><1D>*<2A>*<2A><0F><1A>&<26>%<25>(<28><03>
<EFBFBD><19>&<26>%<25>(<28><03>
<EFBFBD> )<29> <11>(<28>C<EFBFBD>J<EFBFBD>(<28>C<EFBFBD>J<EFBFBD>
<1E> <1D><>)<29>C<EFBFBD>J<EFBFBD>(<28>C<EFBFBD>J<EFBFBD><4A>
<1E> <1D> <1D>s5<00>B?<01>AB+<05>+B<04>/B+<05>
B?<01>B(<07>(B+<05>+ B< <09>6 B?c<01><00>]tRt^ItRtRtR#)<04>_Donez-Sentinel value for stopping the stdout proxy.rN)<06>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__firstlineno__<5F>__doc__<5F>__static_attributes__rrrrrIs<00><00>3rrc<01><00>]tRt^MtRtR&RRlltRRltRRltRR ltR
R lt R R lt
RRlt RRlt RRlt RRltRRltRRlt]RRl4tRRltRRlt]R R!l4t]R"R#l4tR$tR%#)'r a<>
File-like object, which prints everything written to it, output above the
current application/prompt. This class is compatible with other file
objects and can be used as a drop-in replacement for `sys.stdout` or can
for instance be passed to `logging.StreamHandler`.
The current application, above which we print, is determined by looking
what application currently runs in the `AppSession` that is active during
the creation of this instance.
This class can be used as a context manager.
In order to avoid having to repaint the prompt continuously for every
little write, a short delay of `sleep_between_writes` seconds will be added
between writes in order to bundle many smaller writes in a short timespan.
c<01>$<00>V^8<>dQhRRRRRR/#)r <00>sleep_between_writes<65>floatrrr<00>Noner)rs"rr<00>StdoutProxy.__annotate___s(<00><00><1C><1C>#<23><1C><12><1C>
<0E> rc <09> <00>WnW n\P!4Vn.Vn\ 4VnVPPVn \P!4Vn VP4VnRVnR#)FN)r'r<00> threading<6E>RLock<63>_lock<63>_bufferr<00> app_session<6F>output<75>_output<75>queue<75>Queue<75> _flush_queue<75>_start_write_thread<61> _flush_thread<61>closed)<03>selfr'rs&&&r<00>__init__<5F>StdoutProxy.__init___sn<00><00>
%9<>!<21><16><08><1E>_<EFBFBD>_<EFBFBD>&<26><04>
<EFBFBD>"$<24><04> <0C>+<2B>,<2C><04><18> $<24>/<2F>/<2F>6<>6<><04> <0C>7<<3C>k<EFBFBD>k<EFBFBD>m<EFBFBD><04><19>!<21>5<>5<>7<><04><1A><1B><04> rc<01><00>V^8<>dQhRR/#)r rr r)rs"rrr*zs<00><00><14><14>;<3B>rc <09><00>V#<00>Nr<00>r9s&r<00> __enter__<5F>StdoutProxy.__enter__zs<00><00><13> rc<01> <00>V^8<>dQhRRRR/#)r <00>args<67>objectrr)r)rs"rrr*}s<00><00><15><15>f<EFBFBD><15><14>rc <09>&<00>VP4R#r>)<01>close)r9rCs&*r<00>__exit__<5F>StdoutProxy.__exit__}s <00><00> <0C>
<EFBFBD>
<EFBFBD> rc<01><00>V^8<>dQhRR/#<00>r rr)r)rs"rrr*<00>s<00><00>
<1F>
<1F>t<EFBFBD>
rc <0A><><00>VP'gGVPP\44VPP 4RVnR#R#)z<>
Stop `StdoutProxy` proxy.
This will terminate the write thread, make sure everything is flushed
and wait for the write thread to finish.
TN)r8r5<00>putrr7<00>joinr?s&rrF<00>StdoutProxy.close<73>sA<00><00><14>{<7B>{<7B>{<7B> <10> <1D> <1D> !<21> !<21>%<25>'<27> *<2A> <10> <1E> <1E> #<23> #<23> %<25><1E>D<EFBFBD>K<EFBFBD>rc<01><00>V^8<>dQhRR/#)r rzthreading.Threadr)rs"rrr*<00>s<00><00><16><16>%5<>rc <09>l<00>\P!VPRRR7pVP4V#)zpatch-stdout-flush-threadT)<03>target<65>name<6D>daemon)r,<00>Thread<61> _write_thread<61>start)r9<00>threads& rr6<00>StdoutProxy._start_write_thread<61>s1<00><00><1A>!<21>!<21><17>%<25>%<25>,<2C><17>
<EFBFBD><06>
<0F> <0C> <0C><0E><15> rc<01><00>V^8<>dQhRR/#rJr)rs"rrr*<00>s<00><00>#6<>#6<>t<EFBFBD>#6rc <09>4<00>RpV'g<>VPP4p\V\4'dR#V'gKD.pVP V4VPP 4p\V\4'dRpK6VP V4KIR# \ PdMi;iTP4pTPTRPT44TfK<>\P!TP4EK)FT<46>N)r5<00>get<65>
isinstancer<00>append<6E>
get_nowaitr3<00>Empty<74> _get_app_loop<6F>_write_and_flushrM<00>time<6D>sleepr')r9<00>done<6E>item<65>text<78>app_loops& rrU<00>StdoutProxy._write_thread<61>s<><00><00><14><04><16><17>$<24>$<24>(<28>(<28>*<2A>D<EFBFBD><19>$<24><05>&<26>&<26><15><18><18><15>D<EFBFBD> <10>K<EFBFBD>K<EFBFBD><04> <1D><17>*<2A><1F>,<2C>,<2C>7<>7<>9<>D<EFBFBD>"<22>$<24><05>.<2E>.<2E>#<23><04><1C> <0B> <0B>D<EFBFBD>)<29>/<17><>"<1D>{<7B>{<7B><1A><19><1A><><1C>)<29>)<29>+<2B>H<EFBFBD> <10> !<21> !<21>(<28>B<EFBFBD>G<EFBFBD>G<EFBFBD>D<EFBFBD>M<EFBFBD> :<3A>
<18>#<23><14>
<EFBFBD>
<EFBFBD>4<EFBFBD>4<>4<>5s<00>B%<00>%B=<03><B=c<01><00>V^8<>dQhRR/#)r r<00> asyncio.AbstractEventLoop | Noner)rs"rrr*<00>s<00><00>
<18>
<18>?<3F>
rc <0A>R<00>VPPpVfR#VP#)zR
Return the event loop for the application currently running in our
`AppSession`.
N)r0<00>app<70>loop)r9rms& rra<00>StdoutProxy._get_app_loop<6F>s&<00><00>
<13><1E><1E>"<22>"<22><03> <0E>;<3B><17><12>x<EFBFBD>x<EFBFBD>rc<01>$<00>V^8<>dQhRRRRRR/#)r rnrkrg<00>strrr)r)rs"rrr*<00>s$<00><00>"?<3F>"?<3F>4<>"?<3F><?<3F>"?<3F> <0A>"?rc <0A>naaa<04>RVV3RlloRV3RllpVf
S!4R#VPV4R#)z`
Write the given text to stdout and flush.
If an application is running, use `run_in_terminal`.
c<01><00>V^8<>dQhRR/#rJr)rs"rr<00>2StdoutProxy._write_and_flush.<locals>.__annotate__<5F>s<00><00> !<21> !<21><14> !rc<01><<02>SPP4SP'dSPPS4MSPP S4SPP 4R#r>)r2<00>enable_autowrapr<00> write_raw<61>write<74>flush<73>r9rgs<00><>r<00>write_and_flush<73>5StdoutProxy._write_and_flush.<locals>.write_and_flush<73>sR<00><><00> <11>L<EFBFBD>L<EFBFBD> (<28> (<28> *<2A><13>x<EFBFBD>x<EFBFBD>x<EFBFBD><14> <0C> <0C>&<26>&<26>t<EFBFBD>,<2C><14> <0C> <0C>"<22>"<22>4<EFBFBD>(<28> <10>L<EFBFBD>L<EFBFBD> <1E> <1E> rc<01><00>V^8<>dQhRR/#rJr)rs"rrrt<00>s<00><00> @<01> @<01><14> @rc<01>"<<01>\SRR7R#)F)<01> in_executorN)r)r{s<00>r<00>write_and_flush_in_loop<6F>=StdoutProxy._write_and_flush.<locals>.write_and_flush_in_loop<6F>s<00><><00> <1C>O<EFBFBD><15> ?rN)<01>call_soon_threadsafe)r9rnrgr<>r{sf&f @rrb<00>StdoutProxy._write_and_flush<73>s7<00><><00> !<21> !<21> @<01> @<01>
<10><<3C> <1B> <1D> <11> %<25> %<25>&=<3D> >rc<01> <00>V^8<>dQhRRRR/#)r <00>datarqrr)r)rs"rrr*<00>s<00><00>&<26>&<26>3<EFBFBD>&<26>4<EFBFBD>&rc <0A><00>RV9d`VPR^4wr#VPVR.,pV.VnRPV4pVPP V4R#VPP V4R#)a
Note: print()-statements cause to multiple write calls.
(write('line') and write('
')). Of course we don't want to call
`run_in_terminal` for every individual call, because that's too
expensive, and as long as the newline hasn't been written, the
text itself is again overwritten by the rendering of the input
command line. Therefor, we have a little buffer which holds the
text until a newline is written to stdout.
<20>
r[N)<06>rsplitr/rMr5rLr^)r9r<><00>before<72>after<65>to_writergs&& r<00>_write<74>StdoutProxy._write<74>sp<00><00> <10>4<EFBFBD><<3C>!<21>K<EFBFBD>K<EFBFBD><04>a<EFBFBD>0<>M<EFBFBD>F<EFBFBD><1B>|<7C>|<7C>v<EFBFBD>t<EFBFBD>n<EFBFBD>4<>H<EFBFBD>!<21>7<EFBFBD>D<EFBFBD>L<EFBFBD><15>7<EFBFBD>7<EFBFBD>8<EFBFBD>$<24>D<EFBFBD> <10> <1D> <1D> !<21> !<21>$<24> '<27> <11>L<EFBFBD>L<EFBFBD> <1F> <1F><04> %rc<01><00>V^8<>dQhRR/#rJr)rs"rrr*s<00><00>$<24>$<24><04>$rc <09><><00>RPVP4p.VnVPPV4R#)r[N)rMr/r5rLrzs& r<00>_flush<73>StdoutProxy._flushs/<00><00><11>w<EFBFBD>w<EFBFBD>t<EFBFBD>|<7C>|<7C>$<24><04><19><04> <0C> <0C><19><19><1D><1D>d<EFBFBD>#rc<01> <00>V^8<>dQhRRRR/#)r r<>rqr<00>intr)rs"rrr*s<00><00><19><19>#<23><19>#<23>rc <09><><00>VP;_uu_4VPV4RRR4\V4# +'giL;ir>)r.r<><00>len)r9r<>s&&rrx<00>StdoutProxy.writes0<00><00> <11>Z<EFBFBD>Z<EFBFBD>Z<EFBFBD> <10>K<EFBFBD>K<EFBFBD><04> <1D><18><13>4<EFBFBD>y<EFBFBD><18><18>Z<EFBFBD>s <00>:<05> A
c<01><00>V^8<>dQhRR/#rJr)rs"rrr* s<00><00><1A><1A>t<EFBFBD>rc <0A><><00>VP;_uu_4VP4RRR4R# +'giR#;i)z
Flush buffered output.
N)r.r<>r?s&rry<00>StdoutProxy.flush s"<00><00><12>Z<EFBFBD>Z<EFBFBD>Z<EFBFBD> <10>K<EFBFBD>K<EFBFBD>M<EFBFBD><18>Z<EFBFBD>Z<EFBFBD>Z<EFBFBD>s <00>0<05> A c<01><00>V^8<>dQhRR/#)r rz TextIO | Noner)rs"rrr*s<00><00>5<>5<><1D>5rc <09>^<00>VPP;'g\P#r>)r2rr<00>
__stdout__r?s&rr<00>StdoutProxy.original_stdouts<00><00><13>|<7C>|<7C>"<22>"<22>4<>4<>c<EFBFBD>n<EFBFBD>n<EFBFBD>4rc<01><00>V^8<>dQhRR/#)r rr<>r)rs"rrr*s<00><00>%<25>%<25><03>%rc <09>6<00>VPP4#r>)r2<00>filenor?s&rr<><00>StdoutProxy.filenos<00><00><13>|<7C>|<7C>"<22>"<22>$<24>$rc<01><00>V^8<>dQhRR/#)r rrr)rs"rrr*s<00><00><1F><1F><04>rc <09>Z<00>VPPpVfR#VP4#)NF)r2r<00>isatty)r9rs& rr<><00>StdoutProxy.isattys%<00><00><15><1C><1C>$<24>$<24><06> <11>><3E><18><15>}<7D>}<7D><EFBFBD>rc<01><00>V^8<>dQhRR/#<00>r rrqr)rs"rrr*$s<00><00>'<27>'<27>#<23>'rc <09>6<00>VPP4#r>)r2<00>encodingr?s&rr<><00>StdoutProxy.encoding#s<00><00><13>|<7C>|<7C>$<24>$<24>&<26>&rc<01><00>V^8<>dQhRR/#r<>r)rs"rrr*(s<00><00><18><18><03>rc <09><00>R#)<01>strictrr?s&r<00>errors<72>StdoutProxy.errors's<00><00>r) r/r5r7r.r2r0r8rr'N)g<><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?F)rr r!r"r#r:r@rGrFr6rUrarbr<>r<>rxry<00>propertyrr<>r<>r<>r<>r$rrrr r Ms<><00><00><08>"<1C>6<14><15>
<1F><16>#6<>J
<18>"?<3F>H&<26>.$<24>
<19> <1A><0E>5<><0E>5<>
%<25><1F><0E>'<27><0E>'<27><0E><18><0E>r)F)r#<00>
__future__r<00>asyncior3rr,rc<00>
contextlibr<00>typingrrr<00> applicationrrr1r <00>__all__r
rr rrr<00><module>r<>sg<00><01><04>(#<23><0E> <0C>
<EFBFBD><10> <0B>%<25>*<2A>*<2A>9<><1A><13><11> <02><07> <10>)<29><10>)<29>@4<>4<>\<18>\r