3 Re(@sddlZddlZddlZddlmZmZmZmZddlm Z m Z m Z ddl m Z mZdZe dk rfe ZGdddeZGdd d eZdS) N)AnsiForeAnsiBack AnsiStyleStyle)WinTermWinColorWinStyle)windll winapi_testc@sLeZdZdZddZddZddZdd Zd d Zd d Z e ddZ dS) StreamWrapperz Wraps a stream (such as stdout), acting as a transparent proxy for all attribute access apart from method 'write()', which is delegated to our Converter instance. cCs||_||_dS)N)_StreamWrapper__wrapped_StreamWrapper__convertor)selfwrapped converterr/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/colorama/ansitowin32.py__init__szStreamWrapper.__init__cCs t|j|S)N)getattrr )rnamerrr __getattr__szStreamWrapper.__getattr__cOs|jj||S)N)r __enter__)rargskwargsrrrrszStreamWrapper.__enter__cOs|jj||S)N)r __exit__)rrrrrrr%szStreamWrapper.__exit__cCs|jj|dS)N)rwrite)rtextrrrr(szStreamWrapper.writec CsZ|j}dtjkr0|dk r0|tjks,|tjkr0dSy |j}Wntk rNdSX|SdS)NPYCHARM_HOSTEDTF)r osenvironsys __stdout__ __stderr__isattyAttributeError)rstream stream_isattyrrrr$+s  zStreamWrapper.isattyc Cs&|j}y|jStk r dSXdS)NT)r closedr%)rr&rrrr(7s zStreamWrapper.closedN) __name__ __module__ __qualname____doc__rrrrrr$propertyr(rrrrr s r c@s~eZdZdZejdZejdZdddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZdS) AnsiToWin32z Implements a 'write()' method which, on Windows, will strip ANSI character sequences from the text, and if outputting to a tty, will convert them into win32 function calls. z?\[((?:\d|;)*)([a-zA-Z])?z?\]((?:.|;)*?)()?NFcCs||_||_t|||_tjdk}|o*t}|dkrN|pL|jj oL|jj }||_ |dkrt|or|jj or|jj}||_ |j |_ |jt jk|_dS)Nnt)r autoresetr r&rrr r(r$stripconvertget_win32_calls win32_callsr!stderr on_stderr)rrr2r1r0 on_windowsconversion_supportedrrrrIs    zAnsiToWin32.__init__cCs|jp|jp|jS)aj True if this class is actually needed. If false, then the output stream will not be affected, nor will win32 calls be issued, so wrapping stdout is not actually required. This will generally be False on non-Windows platforms, unless optional functionality like autoreset has been requested using kwargs to init() )r2r1r0)rrrr should_wrapjszAnsiToWin32.should_wrapcNCs>|jotr8tjtjftjtjtjftjtjtj ftj tjtj ft j tj t j ft jtj t jft jtj t jft jtj t jft jtj t jft jtj t jft jtj t jft jtj t jft jtj ft jtj t j dft jtj t jdft jtj t jdft jtj t jdft jtj t jdft jtj t jdft jtj t jdft jtj t jdftj tj t j ftjtj t jftjtj t jftjtj t jftjtj t jftjtj t jftjtj t jftjtj t jftjtj ftjtj t j dftjtj t jdftjtj t jdftjtj t jdftjtj t jdftjtj t jdftjtj t jdftjtj t jdfi&St!S)NT)"r2wintermr RESET_ALL reset_allBRIGHTstyler DIMNORMALrBLACKforerREDGREENYELLOWBLUEMAGENTACYANWHITEGREYRESET LIGHTBLACK_EX LIGHTRED_EX LIGHTGREEN_EXLIGHTYELLOW_EX LIGHTBLUE_EXLIGHTMAGENTA_EX LIGHTCYAN_EX LIGHTWHITE_EXrbackdict)rrrrr3tsP    zAnsiToWin32.get_win32_callscCs@|js |jr|j|n|jj||jj|jr<|jdS)N)r1r2write_and_convertrrflushr0r<)rrrrrrs     zAnsiToWin32.writecCs8|jr|jddn |j r4|jj r4|jjtjdS)Nmr)r) r2 call_win32r1r&r(rrrr;)rrrrr<szAnsiToWin32.reset_allcCsfd}|j|}x@|jj|D]0}|j\}}|j||||j|j|}qW|j||t|dS)z Write the given text to our wrapped stream, stripping any ANSI sequences from the text, and optionally converting them into win32 calls. rN) convert_osc ANSI_CSI_REfinditerspanwrite_plain_text convert_ansigroupslen)rrcursormatchstartendrrrrVs  zAnsiToWin32.write_and_convertcCs*||kr&|jj||||jjdS)N)rrrW)rrrdrerrrr^szAnsiToWin32.write_plain_textcCs"|jr|j||}|j||dS)N)r2extract_paramsrY)r paramstringcommandparamsrrrr_s zAnsiToWin32.convert_ansicCs~|dkrtdd|jdD}t|dkrz|d krnd }n |d krzd }|S)NHfcss&|]}t|dkrt|ndVqdS)rrN)raint).0prrr sz-AnsiToWin32.extract_params..;rcss"|]}t|dkrt|VqdS)rN)rark)rlrmrrrrnsrJKmABCD)r)r)r)tuplesplitra)rrhrgrirrrrfs zAnsiToWin32.extract_paramsc Cs|dkrVx|D]B}||jkr|j|}|d}|dd}t|jd}|||qWn|dkrttj|d|jdn|dkrtj|d|jdnf|dkrtj||jdnL|dkr|d}d| fd|f|df| dfd |\} } tj| | |jddS) NrXrr)r6JKrjrr)ABCD)r4rUr6r: erase_screen erase_lineset_cursor_position cursor_adjust) rrhriparam func_argsfuncrrnxyrrrrYs$     *zAnsiToWin32.call_win32cCsvxp|jj|D]`}|j\}}|d|||d}|j\}}|dkr|jd}|ddkrtj|dqW|S)Nror02r) ANSI_OSC_REr\r]r`rtr: set_title)rrrcrdrergrhrirrrrZs    zAnsiToWin32.convert_osc)NNF)r)r*r+r,recompiler[rrr9r3rr<rVr^r_rfrYrZrrrrr.@s   ! , r.)rr!ransirrrrr:rrr win32r r objectr r.rrrrs0