Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
utils.cpython-313.pyc271 linesDownload Raw Back to __pycache__
1�

2�j:O���SSKJr SSKJr SSKrSSKrSSKrSSKr	SSK3Jr SSKJ
r
 SSKJr SSKJr SSKJr SS	KJr SS4KJr SSKJr SSKJr SS
KJr SSKJr SSKJr SSKJr SSKJr \	R8(aSSKr\R>"S5r \	RB"S5r"S(Sjr#S)Sjr$S*Sjr%S+S,Sjjr&"SS5r'"SS5r(S-S.Sjjr)S/Sjr*S0S1Sjjr+S2S3S jjr,S4S5S!jjr-S6S7S"jjr."S#S$5r/S8S9S%jjr0SSSS&.S:S'jjr1g);�)�annotationsN��update_wrapper)�5ModuleType)�
TracebackType�)�_default_text_stderr)�_default_text_stdout)�_find_binary_writer)�auto_wrap_for_ansi)�binary_streams)�open_stream)�should_strip_ansi)�6strip_ansi)�text_streams)�WIN)�resolve_color_default�P�Rc�\�SRUR55R5$)N�-)�join�split�lower)�names �QD:\code\apps\devtools\python\user_packages\Python313\site-packages\click/utils.py�	_posixifyr s ���8�8�D�J�J�L�!�'�'�)�)�c�,^�SU4Sjjn[UT5$)z0Wraps a function so that it swallows exceptions.c�6>�T"U0UD6$![a gf=f�N)�	Exception)�args�kwargs�funcs  �r�wrapper�safecall.<locals>.wrapper's-���	���(��(�(���	���	�s��7�)r#zP.argsr$zP.kwargs�returnzR | Noner)r%r&s` r�safecallr)$s�����'�4�(�(rc���[U[5(a%UR[R"55$[
U5$![8a URSS5s$f=f)z%Converts a value into a valid string.�utf-8�replace)�9isinstance�bytes�decode�sys�getfilesystemencoding�UnicodeError�str)�values r�make_strr51sZ���%����	4��<�<�� 9� 9� ;�<�<��u�:����	4��<�<���3�3�	4�s�#A�A%�$A%c�.�URS5nUS:waUSUnUR5nU(dgUSS:XaUSSnSn[U5S-10n[U5HPupgU[U5US:�--
nXA:�a OEUSS:XaS	R	USUS-5s $XA:XdMIXe:wdMP O S	R	U5$U[S115-
nUS:�a)U[X65US:�--nXA::aO
US-nUS:�aM)S	R	USU5S12-$)z<Returns a condensed version of help string.13 14:meta private:15z16 17�����N�r�r�.� z...)�findr�len�	enumerater)�help�18max_length�
paragraph_end�words�total_length�19last_index�i�words        r�make_default_short_helprG;s?���I�I�f�%�M�����N�]�#��
�J�J�L�E���
�Q�x�4���a�b�	���L��U��a��J��U�#�����D�	�Q��U�+�+���$����8�s�?��8�8�E�'�A��E�N�+�+��%�!�/��$��x�x�����C��J��L��a�%���E�H�
��Q��/�/���%��	�Q���
�a�%��8�8�E�"�1�I���&�&rc��\rSrSrSrSSSjjrSSjrSSjrSSjrSSjr	SS	jr20SS21jrSSjrSSjr
S
rg)�LazyFile�pz�A lazy file works like a regular file but it does not fully open22the file but it does perform some basic checks early to see if the23filename parameter does make sense.  This is useful for safely opening24files for writing.25Nc� �[R"U5UlX lX0lX@lXPlU U URS:Xa[XX45uUlUl	gSU;a[X5R5 SUlSUl	g)Nr�rT)�os�fspathr�mode�encoding�errors�atomicr�_f�should_close�open�close)�self�filenamerOrPrQrRs      r�__init__�LazyFile.__init__wsy�����8�,��	��	� �
��������9�9���)4�X�X�)V�&�D�G�T�&��d�{��X�$�*�*�,��D�G� $�D�rc�6�[UR5U5$r!)�getattrrU�rWrs  r�__getattr__�LazyFile.__getattr__�s���t�y�y�{�D�)�)rc��URb[UR5$S[UR5SURS3$)Nz<unopened file 'z' �>)rS�repr�format_filenamerrO�rWs r�__repr__�LazyFile.__repr__�s=���7�7������=� �!�/�$�)�)�"<�!=�R��	�	�{�!�L�Lrc�:�URbUR$[URURURUR26URS9uolXlU$![a'nSSK	J27n U"URURS9UeSnAff=f)z�Opens the file if it's not yet open.  This call might fail with28a :exc:`FileError`.  Not handling this error will produce an error29that Click shows.30N�rRr)�	FileError)�hint)rSrrrOrPrQrRrT�OSError�31exceptionsri�strerror)rW�rv�eris    rrU�
LazyFile.open�s���32�7�7���7�7�N�	?�$/��	�	�4�9�9�d�m�m�T�[�[����%�!�B�!����	���	?�-��D�I�I�A�J�J�7�Q�>��	?�s�AA)�)33B�3"B�Bc�T�URbURR5 gg)z+Closes the underlying file, no matter what.N)rSrVrds rrV�LazyFile.close�s���7�7���G�G�M�M�O�rc�H�UR(aUR5 gg)zyThis function only closes the file if it was opened by the lazy34file wrapper.  For instance this will never close stdin.35N)rTrVrds r�close_intelligently�LazyFile.close_intelligently�s������J�J�L�rc��U$r!�rds r�	__enter__�LazyFile.__enter__�����rc�$�UR5 gr!)rt�rW�exc_type�	exc_value�tbs    r�__exit__�LazyFile.__exit__�s��	
� � �"rc�L�UR5 [UR5$r!)rU�iterrSrds r�__iter__�LazyFile.__iter__�s���	�	���D�G�G�}�r)rSrRrPrQrOrrT)rLN�strictF)36rX�str | os.PathLike[str]rOr3rP�37str | NonerQr�rR�bool�rr3r(�t.Any�r(r3)r(�t.IO[t.Any]�r(�None)r(rI�r}ztype[BaseException] | Noner~zBaseException | NonerzTracebackType | Noner(r��r(zcabc.Iterator[t.AnyStr])�__name__�38__module__�__qualname__�__firstlineno__�__doc__rYr^rerUrVrtrxr�r��__static_attributes__rwrrrIrIps�����#�%��
%�(�%��%��	%�39�%��
%�6*�M�40�$�41��#�,�#�(�#�
!�	#�4243�#�rrIc�`�\rSrSrS44SjrSSjrSSjrS
SjrSSjrSSjr	Sr45g	)�KeepOpenFile��c��Xlgr!��_file)rW�files  rrY�KeepOpenFile.__init__�s��"&�46rc�.�[URU5$r!)r\r�r]s  rr^�KeepOpenFile.__getattr__�s���t�z�z�4�(�(rc��U$r!rwrds rrx�KeepOpenFile.__enter__�rzrc��gr!rwr|s    rr��KeepOpenFile.__exit__�s��	
rc�,�[UR5$r!)rbr�rds rre�KeepOpenFile.__repr__�����D�J�J��rc�,�[UR5$r!)r�r�rds rr��KeepOpenFile.__iter__�r�rr�N)r�r�r(r�r�)r(r�r�r�r�)r�r�r�r�rYr^rxr�rer�r�rwrrr�r��sF��'�)��
�,�
�(�
�
!�	
�4748�
� � rr�Tc���Uc U(a[5nO49[5nUcgUb,[U[[[5045(d[U5nOUnU(a+U=(d Sn[U[5(aUS-
nOUS-
nU(dUR
5 g[U[[5145(aA[U5nUb2UR
5 URU5 UR
5 gOW[U5n[X5(a[U5nO0[(a%[b[X5nOU(d[U5nURU5 UR
5 g)a�Print a message and newline to stdout or a file. This should be52used instead of :func:`print` because it provides better support53for different data, files, and environments.54 55Compared to :func:`print`, this does the following:56 57-   Ensures that the output encoding is not misconfigured on Linux.58-   Supports Unicode in the Windows console.59-   Supports writing to binary outputs, and supports writing bytes60    to text outputs.61-   Supports colors and styles on Windows.62-   Removes ANSI color and style codes if the output does not look63    like an interactive terminal.64-   Always flushes the output.65 66:param message: The string or bytes to output. Other objects are67    converted to strings.68:param file: The file to write to. Defaults to ``stdout``.69:param err: Write to ``stderr`` instead of ``stdout``.70:param nl: Print a newline after the message. Enabled by default.71:param color: Force showing or hiding colors and other styles. By72    default Click will remove color if the output does not look like73    an interactive terminal.74 75.. versionchanged:: 6.076    Support Unicode output on the Windows console. Click does not77    modify ``sys.stdout``, so ``sys.stdout.write()`` and ``print()``78    will still not support Unicode.79 80.. versionchanged:: 4.081    Added the ``color`` parameter.82 83.. versionadded:: 3.084    Added the ``err`` parameter.85 86.. versionchanged:: 2.087    Support colors on Windows if colorama is installed.88Nr8�89�90)r	r91r-r3r.�	bytearray�flushr�writerrrrr)�messager��nl�err�color�out�binary_files       r�echor��s.��Z�|��'�)�D�'�)�D��<����:�g��U�I�7N�#O�#O�.1�'�l����	��i�R���c�3����4�K�C��5�L�C���92�93����#��y�)�*�*�)�$�/���"��J�J�L����c�"������	#�&�e�,���T�)�)��S�/�C�
�S�!�-�)�$�6��� ��o���J�J�s�O��J�J�Lrc�`�[R"U5nUc[SUS35eU"5$)z�Returns a system stream for byte processing.94 95:param name: the name of the stream to open.  Valid names are ``'stdin'``,96             ``'stdout'`` and ``'stderr'``97�Unknown standard stream '�')r
�get�	TypeError)r�openers  r�get_binary_streamr�Hs5���
�
��
%�F�
�~��3�D�6��;�<�<��8�Orc�b�[R"U5nUc[SUS35eU"X5$)a�Returns a system stream for text processing.  This usually returns98a wrapped stream around a binary stream returned from99:func:`get_binary_stream` but it also can take shortcuts for already100correctly configured streams.101 102:param name: the name of the stream to open.  Valid names are ``'stdin'``,103             ``'stdout'`` and ``'stderr'``104:param encoding: overrides the detected default encoding.105:param errors: overrides the default error mode.106r�r�)rr�r�)rrPrQr�s    r�get_text_streamr�Ts9���
�
�d�
#�F�
�~��3�D�6��;�<�<��(�#�#rc��U(a [R"S[XX#US95$[XX#US9upgU(d [R"S[	U55nU$)aOpen a file, with extra behavior to handle ``'-'`` to indicate107a standard stream, lazy open on write, and atomic write. Similar to108the behavior of the :class:`~click.File` param type.109 110If ``'-'`` is given to open ``stdout`` or ``stdin``, the stream is111wrapped so that using it in a context manager will not close it.112This makes it possible to use the function without accidentally113closing a standard stream:114 115.. code-block:: python116 117    with open_file(filename) as f:118        ...119 120:param filename: The name or Path of the file to open, or ``'-'`` for121    ``stdin``/``stdout``.122:param mode: The mode in which to open the file.123:param encoding: The encoding to decode or encode a file opened in124    text mode.125:param errors: The error handling mode.126:param lazy: Wait to open the file until it is accessed. For read127    mode, the file is temporarily opened to raise access errors128    early, then closed until it is read again.129:param atomic: Write to a temporary file and replace the given file130    on close.131 132.. versionadded:: 3.0133r�rh)�t�castrIrr�)rXrOrPrQ�lazyrR�frTs        r�	open_filer�isU��H��v�v��8�H�H�V�T�134�	135�"�(�(�6�R�O�A��
�F�F�=�,�q�/�2���Hrc�<�U(a [RRU5nO[R"U5n[	U[1365(a'UR
[R"5S5nU$URSS5R
SS5nU$)uuFormat a filename as a string for display. Ensures the filename can be137displayed by replacing any invalid bytes or surrogate escapes in the name138with the replacement character ``�``.139 140Invalid bytes or surrogate escapes will raise an error when written to a141stream with ``errors="strict"``. This will typically happen with ``stdout``142when the locale is something like ``en_GB.UTF-8``.143 144Many scenarios *are* safe to write surrogates though, due to PEP 538 and145PEP 540, including:146 147-   Writing to ``stderr``, which uses ``errors="backslashreplace"``.148-   The system has ``LANG=C.UTF-8``, ``C``, or ``POSIX``. Python opens149    stdout and stderr with ``errors="surrogateescape"``.150-   None of ``LANG/LC_*`` are set. Python assumes ``LANG=C.UTF-8``.151-   Python is started in UTF-8 mode  with  ``PYTHONUTF8=1`` or ``-X utf8``.152    Python opens stdout and stderr with ``errors="surrogateescape"``.153 154:param filename: formats a filename for UI display.  This will also convert155                 the filename into unicode without failing.156:param shorten: this optionally shortens the filename to strip of the157                path that leads up to it.158r,r+�surrogateescape)159rM�path�basenamerNr-r.r/r0r1�encode)rX�shortens  rrcrc�s���6��7�7�#�#�H�-���9�9�X�&���(�E�"�"��?�?�3�#<�#<�#>�	�J���O�	�?�?�7�,=�>�E�E��Y�160���Orc���[(akU(aSOSn[RRU5nUc[RRS5n[RR
X@5$U(aH[RR
[RRS[U5355$[RS:Xa=[RR
[RRS5U5$[RR
[RRS[RRS55[U55$)	a"Returns the config folder for the application.  The default behavior161is to return whatever is most appropriate for the operating system.162 163To give you an idea, for an app called ``"Foo Bar"``, something like164the following folders could be returned:165 166Mac OS X:167  ``~/Library/Application Support/Foo Bar``168Mac OS X (POSIX):169  ``~/.foo-bar``170Unix:171  ``~/.config/foo-bar``172Unix (POSIX):173  ``~/.foo-bar``174Windows (roaming):175  ``C:\Users\<user>\AppData\Roaming\Foo Bar``176Windows (not roaming):177  ``C:\Users\<user>\AppData\Local\Foo Bar``178 179.. versionadded:: 2.0180 181:param app_name: the application name.  This should be properly capitalized182                 and can contain whitespace.183:param roaming: controls if the folder should be roaming or not on Windows.184                Has no effect otherwise.185:param force_posix: if this is set to `True` then on any POSIX system the186                    folder will be stored in the home folder with a leading187                    dot instead of the XDG config home or darwin's188                    application support folder.189�APPDATA�LOCALAPPDATA�~z~/.�darwinz~/Library/Application Support�XDG_CONFIG_HOMEz	~/.config)190rrM�environr�r��191expanduserrrr0�platform)�app_name�roaming�force_posix�key�folders     r�get_app_dirr��s���>�s�"�i���������$���>��W�W�'�'��,�F��w�w�|�|�F�-�-���w�w�|�|�B�G�G�.�.��Y�x�5H�4I�/J�K�L�L�192�|�|�x���w�w�|�|��G�G���>�?��193�	194��7�7�<�<�195�196�197���(�"�'�'�*<�*<�[�*I�J��(���rc�6�\rSrSrSrSSjrS	SjrS198SjrSrg)�PacifyFlushWrapperi�a�This wrapper is used to catch and suppress BrokenPipeErrors resulting199from ``.flush()`` being called on broken pipe during the shutdown/final-GC200of the Python interpreter. Notably ``.flush()`` is always called on201``sys.stdout`` and ``sys.stderr``. So as to have minimal impact on any202other cleanup code, and the case where the underlying file is not a broken203pipe, all calls and attributes are proxied.204c��Xlgr!��wrapped)rWr�s  rrY�PacifyFlushWrapper.__init__�s���rc��URR5 g![a)nSSKnURUR:waeSnAgSnAff=f)Nr)r�r�rk�errno�EPIPE)rWror�s   rr��PacifyFlushWrapper.flushsB��	��L�L��� ���	���w�w�%�+�+�%��&��	�s��205A�A�Ac�.�[URU5$r!)r\r�)rW�attrs  rr^�PacifyFlushWrapper.__getattr__206s���t�|�|�T�*�*rr�N)r�r�r(r�r�)r�r3r(r�)	r�r�r�r�r�rYr�r^r�rwrrr�r��s�����+rr�c��Uc[RSnU(d[RSn[USS5S;do[R207S:XazURS:Xaj[RRU5(dF[RRUS35(a[RRU5$[R"[UR5n[RR[RRU55SnUS:waUS	U3nS208URS	53$)a�Determine the command used to run the program, for use in help209text. If a file or entry point was executed, the file name is210returned. If ``python -m`` was used to execute a module or package,211``python -m name`` is returned.212 213This doesn't try to be too precise, the goal is to give a concise214name for help text. Files are only shown as their name without the215path. ``python`` is only shown for modules, and the full path to216``sys.executable`` is not shown.217 218:param path: The Python file being executed. Python puts this in219    ``sys.argv[0]``, which is used by default.220:param _main: The ``__main__`` module. This should only be passed221    during internal testing.222 223.. versionadded:: 8.0224    Based on command args detection in the Werkzeug reloader.225 226:meta private:227N�__main__r�__package__>Nr8�ntr8z.exer:z228python -m )r0�modules�argvr\rMrr�r��existsr�r�r�r3�splitext�lstrip)r��_main�	py_modulers    r�_detect_program_namer�s	��.
�}����J�'����x�x��{���u�m�T�*�j�8�229���4������#������t�$�$��G�G�N�N�d�V�4�=�)�)��w�w����%�%�230���s�E�-�-�.�I�
�7�7���B�G�G�,�,�T�2�3�A�6�D��z�� �k��4�&�)�	�
�	�(�(��-�.�/�/r)�user�env�glob_recursivec�\�SSKJn /nUH�nU(a[RRU5nU(a[RR	U5nU"XcS9nU(dURU5 MpURU5 M� U$![231Ra /nNIf=f)auSimulate Unix shell expansion with Python functions.232 233See :func:`glob.glob`, :func:`os.path.expanduser`, and234:func:`os.path.expandvars`.235 236This is intended for use on Windows, where the shell does not do any237expansion. It may not exactly match what a Unix shell would do.238 239:param args: List of command line arguments to expand.240:param user: Expand user home directory.241:param env: Expand environment variables.242:param glob_recursive: ``**`` matches directories recursively.243 244.. versionchanged:: 8.1245    Invalid glob patterns are treated as empty expansions rather246    than raising an error.247 248.. versionadded:: 8.0249 250:meta private:251r)�glob)�	recursive)	r�rMr�r��252expandvars�re�error�append�extend)r#r�r�r�r�r��arg�matchess        r�_expand_argsrEs���8�253�C�����'�'�$�$�S�)�C���'�'�$�$�S�)�C�	��3�9�G���J�J�s�O��J�J�w���"�J���x�x�	��G�	�s�B�B+�*B+)rr3r(r3)r%zt.Callable[P, R]r(zt.Callable[P, R | None])r4r�r(r3)�-)r?r3r@�intr(r3)NNTFN)r�zt.Any | Noner�zt.IO[t.Any] | Noner�r�r�r�r�zbool | Noner(r�)r�&t.Literal['stdin', 'stdout', 'stderr']r(z254t.BinaryIO)Nr�)rrrPr�rQr�r(zt.TextIO)rLNr�FF)rXr�rOr3rPr�rQr�r�r�rRr�r(r�)F)rXz3str | bytes | os.PathLike[str] | os.PathLike[bytes]r�r�r(r3)TF)r�r3r�r�r�r�r(r3)NN)r�r�r�zModuleType | Noner(r3)255r#zcabc.Iterable[str]r�r�r�r�r�r�r(z	list[str])2�256__future__r�collections.abc�abc�cabcrMr�r0�typingr��	functoolsr�typesrr�_compatr	r257rrr
rrrrr�globalsr�
TYPE_CHECKING�typing_extensions�te�	ParamSpecr�TypeVarrrr)r5rGrIr�r�r�r�r�rcr�r�r�rrwrr�<module>rs��"��	�	�258��$���)�)�(�'�#� �&��!��*��?�?�"�259���S��A��I�I�c�N��*�260)��2'�jU�U�p � �4!�#����d�
�d�261�d�	
�d�262�	d�263�d�264�
d�N	� �!�$�2650�$��$�
�$��	$�.��!���
.
�$�.
�266
�.
��.
�
�	.
�267�.
�
�
.
��.
�f�'�A�'�
�'�	�'�T.�b+�+�49=�40�268�40�$5�40��40�t���1�269�1��1�270�	1�271�1��
1r
codekingpro/portable-devtools · Team Ai