Files
intellecton/venv/lib/python3.12/site-packages/click/__pycache__/utils.cpython-312.pyc
T

271 lines
25 KiB
Plaintext
Raw Normal View History

Ë
j¢OãóŒddlmZddlmZddlZddlZddlZddlZ ddl
m Z ddl m Z
ddlmZddlmZddlmZdd lmZdd
lmZdd lmZdd lmZdd
lmZddlmZddlmZddlmZddlmZddlmZe j<rddlZ e jBd«Z"e jFd«Z$d)dZ%d*dZ&d+dZ'd,d-dZ(Gdd«Z)Gdd«Z* d. d/dZ+d0dZ, d1 d2d „Z- d3 d4d!„Z. d5 d6d"„Z/d7d8d#„Z0Gd$„d%«Z1 d9 d:d&„Z2dddd'œ d;d(„Z3y)<é)Ú annotationsN©Úupdate_wrapper)Úgettext)Ú
ModuleType)Ú
TracebackTypeé)Ú_default_text_stderr)Ú_default_text_stdout)Ú_find_binary_writer)Úauto_wrap_for_ansi)Úbinary_streams)Ú open_stream)Úshould_strip_ansi)Ú
strip_ansi)Ú text_streams)ÚWIN)Úresolve_color_defaultÚRcó\dj|j««j«S)-)ÚjoinÚsplitÚlower©Únames úN/home/antigravity/intellecton/venv/lib/python3.12/site-packages/click/utils.pyÚ _posixifyr!s Ø 8‰8D—JJ“LÓ !× có(dˆfd }t|«S)z0Wraps a function so that it swallows exceptions.có4 |i|¤ŽS#t$rYywxYw©N)Ú Exception)ÚargsÚkwargsÚfuncs €rÚwrapperzsafecall.<locals>.wrapper(s-ø€ð Ù˜ÐÑ (øÜò Ø Øð ús ƒ )r%zP.argsr&zP.kwargsÚreturnzR | Noner)r'r(s` rÚsafecallr*%sø€õô ˜'  (r cóÂt|t«r$ |jtj««St
|«S#t
$r|jdd«cYSwxYw)z%Converts a value into a valid string.úutf-8Úreplace)Ú
isinstanceÚbytesÚdecodeÚsysÚgetfilesystemencodingÚ UnicodeErrorÚstr)Úvalues rÚmake_strr62sWäÔð—<× 9Ñ 9Ó ;Ó  ˆuøôò—<< ¨Ó  4ús"AÁAÁAcó|jd«}|dk7r|d|}|j«}|sy|ddk(r|dd}d}t|«dz
}t|«D]N\}}|t|«|dkDzz
}||kDrnA|ddk(rd j |d|dz«cS||k(sŒH||k7sŒNnd j |«S|td
«z
}|dkDr(|t||«|dkDzz}||krn |dz}|dkDrŒ(d j |d|«d
zS) zDReturns a condensed version of help string.
:meta private:
z
éÿÿÿÿNÚrúr ú z...)ÚfindrÚlenÚ enumerater)ÚhelpÚ
max_lengthÚ
paragraph_endÚwordsÚ total_lengthÚ
last_indexÚwords rÚmake_default_short_helprH<sPð —I‘I˜fÓ%€Mà˜ÒØNð
J‰J‹L€Eá Øð
ˆQxØab ˆà€LÜU“˜a‘€Jä˜UÓ ˆˆ4Øœ˜D›  Q¨¡UÑ à ˜*Ò à ‰8sŠ?Ø—88˜E ' ¡E˜ ˜:Ó %¨!¨z«/Ù ð ðx‰x˜Ðð”C˜“JÑ€Lð ˆaŠ%Øœ˜E !™H›
¨¨Q©Ñ à ˜:Ò à ˆQ‰ˆð
ˆa 8‰8E˜"˜1  Ñ &r cóÐeZdZUdZded<ded<ded<ded<ded <d
ed <ded < d ddZddZddZddZddZ ddZ
ddZ ddZ ddZ
y
) ÚLazyFilezîA lazy file works like a regular file but it does not fully open
the file but it does perform some basic checks early to see if the
filename parameter does make sense. This is useful for safely opening
files for writing.
r4rÚmodeú
str | NoneÚencodingÚerrorsÚboolÚatomicút.IO[t.Any] | NoneÚ_fÚ should_closeNcótj|«|_||_||_||_||_|jdk(rt||||«\|_|_ yd|vrt||«j«d|_d|_ y)NrÚrT) ÚosÚfspathrrKrMrNrPrrRrSÚopenÚclose)ÚselfÚfilenamerKrMrNrPs rÚ__init__zLazyFile.__init__€sô—II˜hÓŒ ؈Œ Ø ˆŒ
؈Œ ؈Œ à 9‰9˜Ò Ü)4°X¸tÀXÈvÓ)VÑ &ˆDŒGd‰{ôX˜ˆDŒGØ $ˆ r có6t|j«|«Sr#)ÚgetattrrX©rZrs rÚ __getattr__zLazyFile.__getattr__™sÜt—yy“{ )r có|jt|j«Sdt|j«d|jdS)Nz<unopened file 'z' ú>)rRÚreprÚformat_filenamerrK©rZs rÚ__repr__zLazyFile.__repr__œs=Ø 7‰7РܘŸ“=Ð Ø!¤/°$·)±)Ó"<Ð!=¸Ç Á ¸{È!ÐLr cóF|j |jS t|j|j|j|j
|j ¬«\}|_||_|S#t$r*}ddl m
}||j|j¬«|d}~wwxYw)z­Opens the file if it's not yet open. This call might fail with
a :exc:`FileError`. Not handling this error will produce an error
that Click shows.
rPr )Ú FileError)Úhint) rRrrrKrMrNrPrSÚOSErrorÚ
exceptionsriÚstrerror)rZÚrvÚeris rrXz
LazyFile.open¡s‡ð
7‰7Ð Ø—7‘7ˆNð ?Ü$/Ø ˜4Ÿ9™9 d§m¡m°T·[±[ÈÏÉô%Ñ !ˆBÔˆŒØˆ øô ò ˜DŸI™I¨A¯J©JÔ7¸ >ûð ?úsšA
A-Á- B Á6%BÂB cóR|j|jj«yy)z+Closes the underlying file, no matter what.N)rRrYres rrYzLazyFile.close³sà 7‰7Ð Ø G‰GM‰M r có>|jr|j«yy)z‰This function only closes the file if it was opened by the lazy
file wrapper. For instance this will never close stdin.
N)rSrYres rÚclose_intelligentlyzLazyFile.close_intelligently¸sð × Ò Ø J‰J r có|Sr#©res rÚ __enter__zLazyFile.__enter__¿ó؈ r có$|j«yr#)rr©rZÚexc_typeÚ exc_valueÚtbs rÚ__exit__zLazyFile.__exit__Âsð
× Ñ Õ"r cóL|j«t|j«Sr#)rXÚiterrRres rÚ__iter__zLazyFile.__iter__ÊsØ ‰ Œ ÜD—GGr )rUstrictF) r[ústr | os.PathLike[str]rKr4rMrLrNrLrPrOr)ÚNone©rr4r)út.Any©r)r4)r)ú t.IO[t.Any]©r)r)r)rJ©ryztype[BaseException] | NonerzzBaseException | Noner{zTracebackType | Noner)r©r)zcabc.Iterator[t.AnyStr])Ú__name__Ú
__module__Ú __qualname__Ú__doc__Ú__annotations__r\r`rfrXrYrrrur|rrtr rrJrJqñð ƒIØ
ƒIØÓØ ÓØ ƒLØÓØÓð
Øð
ðð 
ð  ð

ó%ó2Mó
ó$ó
óð

ó r rJcóXeZdZUded<d
dZd dZd dZ d
dZddZddZ y )Ú KeepOpenFiler†Ú_filecó||_yr#)r)rZÚfiles rr\zKeepOpenFile.__init__Òs ؈
r có.t|j|«Sr#)r^rr_s rr`zKeepOpenFile.__getattr__ÕsÜt—zz (r có|Sr#rtres rruzKeepOpenFile.__enter__Ørvr cóyr#rtrxs rr|zKeepOpenFile.__exit__Ûsð
r có,t|j«Sr#)rcrres rrfzKeepOpenFile.__repr__ãóÜD—J‘JÓÐr có,t|j«Sr#)r~rres rrzKeepOpenFile.__iter__ær˜r N)r“r†r)r)r)rrˆr…r‰)
rr\r`rur|rfrrtr rrrÏsLØ Óóóð
à
ð
ð

ð
ó 
ó ô r rTcó ||r t«}n
t«}|y|xxtd˜x\nxtd˜x\nxtd˜x\nn|}nd}n t|«}|rt |t«r|dz
}n|dz
}|s|j
«yt |ttf«r?t|«}|{|j
«|j|«|j
«yt|«}t||«r t|«}n&tr t
t||«}n
|s t|«}|j|«|j
«y)aPrint a message and newline to stdout or a file. This should be
used instead of :func:`print` because it provides better support
for different data, files, and environments.
Compared to :func:`print`, this does the following:
- Ensures that the output encoding is not misconfigured on Linux.
- Supports Unicode in the Windows console.
- Supports writing to binary outputs, and supports writing bytes
to text outputs.
- Supports colors and styles on Windows.
- Removes ANSI color and style codes if the output does not look
like an interactive terminal.
- Always flushes the output.
:param message: The string or bytes to output. Other objects are
converted to strings.
:param file: The file to write to. Defaults to ``stdout``.
:param err: Write to ``stderr`` instead of ``stdout``.
:param nl: Print a newline after the message. Enabled by default.
:param color: Force showing or hiding colors and other styles. By
default Click will remove color if the output does not look like
an interactive terminal.
.. versionchanged:: 6.0
Support Unicode output on the Windows console. Click does not
modify ``sys.stdout``, so ``sys.stdout.write()`` and ``print()``
will still not support Unicode.
.. versionchanged:: 4.0
Added the ``color`` parameter.
.. versionadded:: 3.0
Added the ``err`` parameter.
.. versionchanged:: 2.0
Support colors on Windows if colorama is installed.
Nrtr9ú
ó
)r
r r4r/Ú bytearrayr.Úflushr Úwriterrrrr
)Úmessager“ÚnlÚerrÚcolorÚoutÚ binary_files rÚechor¦ês$ðZ €|Ù Ü)‰Dä)ˆ ˆ à
Ø
*ˆUŒSUW”U—W˜{œyŸ{Ó
‰CØ
؉CØ
Üg“,ˆCá Ü cœ3Ô Ø 4‰K‰Cà 5‰LˆCá Ø
Œ Øô œyÐ)¨$Ó/ˆ Ø Ð J‰JŒLØ × Ñ ˜cÔ × Ñ Ô Ø ô
& ,ˆä ˜T  ˜S“/‰CÝ
Ü)¨$°Ó6‘ÙÜ  “oà‡JJˆs„O؇JJ…Lr có†tj|«}|€$ttd«j |¬««|«S)z°Returns a system stream for byte processing.
:param name: the name of the stream to open. Valid names are ``'stdin'``,
``'stdout'`` and ``'stderr'``
ú Unknown standard stream '{name}'r)rÚgetÚ TypeErrorÚformat)rÚopeners rÚget_binary_streamr®Qs?ô ×
Ñ
 Ó
%€FØ
€~ÜœÐ=×DÈ$Ð 8€Or cóŠtj|«}|€$ttd«j |¬««|||«S)Returns a system stream for text processing. This usually returns
a wrapped stream around a binary stream returned from
:func:`get_binary_stream` but it also can take shortcuts for already
correctly configured streams.
:param name: the name of the stream to open. Valid names are ``'stdin'``,
``'stdout'`` and ``'stderr'``
:param encoding: overrides the detected default encoding.
:param errors: overrides the default error mode.
r)r)rrMrNr­s rÚget_text_streamr°]sEô×
Ñ
˜
#€FØ
€~ÜœÐ=×DÈ$Ð (˜ #r c
óº|r$tjdt|||||¬««St|||||¬«\}}|stjdt |««}|S)a^Open a file, with extra behavior to handle ``'-'`` to indicate
a standard stream, lazy open on write, and atomic write. Similar to
the behavior of the :class:`~click.File` param type.
If ``'-'`` is given to open ``stdout`` or ``stdin``, the stream is
wrapped so that using it in a context manager will not close it.
This makes it possible to use the function without accidentally
closing a standard stream:
.. code-block:: python
with open_file(filename) as f:
...
:param filename: The name or Path of the file to open, or ``'-'`` for
``stdin``/``stdout``.
:param mode: The mode in which to open the file.
:param encoding: The encoding to decode or encode a file opened in
text mode.
:param errors: The error handling mode.
:param lazy: Wait to open the file until it is accessed. For read
mode, the file is temporarily opened to raise access errors
early, then closed until it is read again.
:param atomic: Write to a temporary file and replace the given file
on close.
.. versionadded:: 3.0
r†rh)ÚcastrJrr)r[rKrMrNÚlazyrPÚfrSs rÚ open_filer¶rs_ñH Üv‰vØ œ8 H¨d°H¸fÈVÔ
ð
ô" (¨D°(¸FÈ6ÔRO€A€|á Ü
F‰F=¤,¨q£/Ó 2ˆà €Hr có$|r tjj|«}ntj|«}t |t
«r&|j
tj«d«}|S|jdd«j
dd«}|S)Format a filename as a string for display. Ensures the filename can be
displayed by replacing any invalid bytes or surrogate escapes in the name
with the replacement character ``�``.
Invalid bytes or surrogate escapes will raise an error when written to a
stream with ``errors="strict"``. This will typically happen with ``stdout``
when the locale is something like ``en_GB.UTF-8``.
Many scenarios *are* safe to write surrogates though, due to PEP 538 and
PEP 540, including:
- Writing to ``stderr``, which uses ``errors="backslashreplace"``.
- The system has ``LANG=C.UTF-8``, ``C``, or ``POSIX``. Python opens
stdout and stderr with ``errors="surrogateescape"``.
- None of ``LANG/LC_*`` are set. Python assumes ``LANG=C.UTF-8``.
- Python is started in UTF-8 mode with ``PYTHONUTF8=1`` or ``-X utf8``.
Python opens stdout and stderr with ``errors="surrogateescape"``.
:param filename: formats a filename for UI display. This will also convert
the filename into unicode without failing.
:param shorten: this optionally shortens the filename to strip of the
path that leads up to it.
r-r,Úsurrogateescape)
rVÚpathÚbasenamerWr.r/r0r1r2Úencode)r[Úshortens rrdrd£s}ñ6Ü—7‘7×# HÓ-‰ä—99˜&ˆä(œEÔ—??¤3×#<Ñ#<Ó#>À ÓJˆð €Oð —?? 7Ð,=Ó>× 
ˆð €Or cóÖtrf|rdnd}tjj|«}|tjj d«}tjj
||«S|rHtjj
tjj dt|«««Stjdk(r=tjj
tjj d«|«Stjj
tjjdtjj d««t|««S) a†Returns the config folder for the application. The default behavior
is to return whatever is most appropriate for the operating system.
To give you an idea, for an app called ``"Foo Bar"``, something like
the following folders could be returned:
Mac OS X:
``~/Library/Application Support/Foo Bar``
Mac OS X (POSIX):
``~/.foo-bar``
Unix:
``~/.config/foo-bar``
Unix (POSIX):
``~/.foo-bar``
Windows (roaming):
``C:\Users\<user>\AppData\Roaming\Foo Bar``
Windows (not roaming):
``C:\Users\<user>\AppData\Local\Foo Bar``
.. versionadded:: 2.0
:param app_name: the application name. This should be properly capitalized
and can contain whitespace.
:param roaming: controls if the folder should be roaming or not on Windows.
Has no effect otherwise.
:param force_posix: if this is set to `True` then on any POSIX system the
folder will be stored in the home folder with a leading
dot instead of the XDG config home or darwin's
application support folder.
ÚAPPDATAÚ LOCALAPPDATAú~z~/.Údarwinz~/Library/Application SupportÚXDG_CONFIG_HOMEz ~/.config)
rrVÚenvironr©Ú
expanduserrrr1Úplatform)Úapp_nameÚroamingÚ force_posixÚkeyÚfolders rÚ get_app_dirrËÍõ> Ù"‰i¨ˆÜ ÓØ ˆ>Ü—WW×Ó,ˆw‰w|‰|˜F Üw‰w|‰|œBŸG™G×´Y¸xÓ5HÐ4IÐ/JÓ
‡||Üw‰w|‰|Ü G‰G× Ñ Ð ó
ð
ô 7‰7<‰<Ü
Ð(¬"¯'©'×*<Ñ*<¸[Ó*IÓó ðr có4eZdZUdZded<ddZd dZd
dZy) ÚPacifyFlushWrappera«This wrapper is used to catch and suppress BrokenPipeErrors resulting
from ``.flush()`` being called on broken pipe during the shutdown/final-GC
of the Python interpreter. Notably ``.flush()`` is always called on
``sys.stdout`` and ``sys.stderr``. So as to have minimal impact on any
other cleanup code, and the case where the underlying file is not a broken
pipe, all calls and attributes are proxied.
r†Úwrappedcó||_yr#))rZs rr\zPacifyFlushWrapper.__init__ s ؈ r có¢ |jj«y#t$r(}ddl}|j|jk7rYd}~yd}~wwxYw)Nr)rkÚerrnoÚEPIPE)rZros rzPacifyFlushWrapper.flush sBð Ø L‰L× Ñ Õ øÜò Û àw‰w˜%Ÿ+™+Òô&ûð ús A¦A Á Acó.t|j|«Sr#)r^)rZÚattrs rr`zPacifyFlushWrapper.__getattr__sÜt—|| *r N)r†r)rr‡)r4r)r„)rrr\r`rtr rþsñðÓóóô+r có~|tjd}|stjd}t|dd«dvsctj
dk(ro|j dk(r`tjj|«sAtjj|d«rtjj|«Stjt|j «}tjjtjj|««d}|dk7r|d |}d
|jd «S) a:Determine the command used to run the program, for use in help
text. If a file or entry point was executed, the file name is
returned. If ``python -m`` was used to execute a module or package,
``python -m name`` is returned.
This doesn't try to be too precise, the goal is to give a concise
name for help text. Files are only shown as their name without the