3 ”ReÞ(ã@sŠddlZddlZddlZddlmZmZmZmZddlm Z m Z m Z ddl m Z mZdZe dk rfe ƒZGdd„deƒZGdd „d eƒZdS) éNé)ÚAnsiForeÚAnsiBackÚ AnsiStyleÚStyle)ÚWinTermÚWinColorÚWinStyle)ÚwindllÚ winapi_testc@sLeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z e dd„ƒZ 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)ÚselfÚwrappedÚ converter©rú�/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 )rÚnamerrrÚ __getattr__szStreamWrapper.__getattr__cOs|jj||ŽS)N)r Ú __enter__)rÚargsÚkwargsrrrrszStreamWrapper.__enter__cOs|jj||ŽS)N)r Ú__exit__)rrrrrrr%szStreamWrapper.__exit__cCs|jj|ƒdS)N)rÚwrite)rÚtextrrrr(szStreamWrapper.writec CsZ|j}dtjkr0|dk r0|tjks,|tjkr0dSy |j}Wntk rNdSX|ƒSdS)NÚPYCHARM_HOSTEDTF)r ÚosÚenvironÚsysÚ __stdout__Ú __stderr__ÚisattyÚAttributeError)rÚstreamÚ 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~eZdZdZejdƒZejdƒZddd„Zdd „Z d d „Z d d „Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„ZdS)Ú 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)NÚnt)rÚ autoresetr r&rrr r(r$ÚstripÚconvertÚget_win32_callsÚ win32_callsr!ÚstderrÚ on_stderr)rrr2r1r0Ú on_windowsÚconversion_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>|jot�r8tjtjftjtjtjftjtjtj 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)"r2ÚwintermrÚ RESET_ALLÚ reset_allÚBRIGHTÚstyler ÚDIMÚNORMALrÚBLACKÚforerÚREDÚGREENÚYELLOWÚBLUEÚMAGENTAÚCYANÚWHITEÚGREYÚRESETÚ LIGHTBLACK_EXÚ LIGHTRED_EXÚ LIGHTGREEN_EXÚLIGHTYELLOW_EXÚ LIGHTBLUE_EXÚLIGHTMAGENTA_EXÚ LIGHTCYAN_EXÚ LIGHTWHITE_EXrÚbackÚdict)rrrrr3tsP    zAnsiToWin32.get_win32_callscCs@|js |jr|j|ƒn|jj|ƒ|jjƒ|jr<|jƒdS)N)r1r2Úwrite_and_convertrrÚflushr0r<)rrrrrr s     zAnsiToWin32.writecCs8|jr|jddƒn |j r4|jj r4|jjtjƒdS)NÚmr)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_REÚfinditerÚspanÚwrite_plain_textÚ convert_ansiÚgroupsÚlen)rrÚcursorÚmatchÚstartÚendrrrrV±s  zAnsiToWin32.write_and_convertcCs*||kr&|jj|||…ƒ|jjƒdS)N)rrrW)rrrdrerrrr^ÁszAnsiToWin32.write_plain_textcCs"|jr|j||ƒ}|j||ƒdS)N)r2Úextract_paramsrY)rÚ paramstringÚcommandÚparamsrrrr_Çs zAnsiToWin32.convert_ansicCs~|dkrtdd„|jdƒDƒƒ}t|ƒdkrz|d krnd }n |d krzd }|S)NÚHfcss&|]}t|ƒdkrt|ƒndVqdS)rrN)raÚint)Ú.0Úprrrú Ïsz-AnsiToWin32.extract_params..ú;ércss"|]}t|ƒdkrt|ƒVqdS)rN)rark)rlrmrrrrnÔsrÚJKmÚABCD)r)r)r)ÚtupleÚsplitra)rrhrgrirrrrfÍs zAnsiToWin32.extract_paramsc Csü|dkrVxî|D]B}||jkr|j|}|d}|dd…}t|jd�}|||ŽqWn¢|dkrttj|d|jd�n„|dkr’tj|d|jd�nf|dkr¬tj||jd�nL|dkrø|d}d| fd|f|df| dfd œ|\} } tj| | |jd�dS) NrXrr)r6ÚJÚKrjrr)ÚAÚBÚCÚD)r4rUr6r:Ú erase_screenÚ erase_lineÚset_cursor_positionÚ cursor_adjust) rrhriÚparamÚ func_argsÚfuncrrÚnÚxÚyrrrrYßs$     *zAnsiToWin32.call_win32cCsvxp|jj|ƒD]`}|jƒ\}}|d|…||d…}|jƒ\}}|dkr|jdƒ}|ddkrtj|dƒqW|S)NúrorÚ02r)Ú ANSI_OSC_REr\r]r`rtr:Ú set_title)rrrcrdrergrhrirrrrZõs    zAnsiToWin32.convert_osc)NNF)r)r*r+r,ÚreÚcompiler[r‡rr9r3rr<rVr^r_rfrYrZrrrrr.@s   ! , r.)r‰r!rÚansirrrrr:rrr Úwin32r r Úobjectr r.rrrrÚs0