ó œÃÒYc@s£ddlZddlZddlmZddlmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZe s«ddlmZn%erÐddlmZmZmZne eefZd„Zd„Zd „Zd d „Z d e!fd „ƒYZ"de!fd„ƒYZ#dde%e&dd„Z'd„Z(ddd„Z)ddde&e&d„Z*d„Z+e&d„Z,e%e&d„Z-dS(iÿÿÿÿNi(tresolve_color_default(t text_typet open_streamtget_filesystem_encodingt get_streerrort string_typestPY2tbinary_streamst text_streamstfilename_to_uitauto_wrap_for_ansit strip_ansitshould_strip_ansit_default_text_stdoutt_default_text_stderrtis_bytestWIN(t_find_binary_writer(t_get_windows_argvt _hash_py_argvt_initial_argv_hashcCsdj|jƒƒjƒS(Nt-(tjointsplittlower(tname((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt _posixifyscs‡fd†}|S(s0Wraps a function so that it swallows exceptions.cs)yˆ||ŽSWntk r$nXdS(N(t Exception(targstkwargs(tfunc(s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytwrappers ((RR((Rs^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytsafecallscCsQt|tƒrGy|jtƒƒSWqGtk rC|jddƒSXnt|ƒS(s%Converts a value into a valid string.sutf-8treplace(t isinstancetbytestdecodeRt UnicodeErrorR(tvalue((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytmake_str#s  i-cCsÔ|jƒ}d}g}t}x¦|D]ž}|ddkrDt}n|rZdt|ƒpct|ƒ}|||krŒ|jdƒt}n#|r¢|jdƒn|j|ƒ|r¹Pn||7}q%Wdj|ƒS(Niiÿÿÿÿt.is...t t(RtFalsetTruetlentappendR(thelpt max_lengthtwordst total_lengthtresulttdonetwordt new_length((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytmake_default_short_help-s$   "   tLazyFilecBskeZdZdd ded„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z RS( sî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. trtstrictcCs•||_||_||_||_||_|dkr]t||||ƒ\|_|_n4d|krt||ƒj ƒnd|_t |_dS(NRR9( RtmodetencodingterrorstatomicRt_ft should_closetopentclosetNoneR,(tselftfilenameR;R<R=R>((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt__init__Ls         cCst|jƒ|ƒS(N(tgetattrRA(RDR((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt __getattr__`scCs0|jdk rt|jƒSd|j|jfS(Ns(R?RCtreprRR;(RD((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt__repr__cs cCs¡|jdk r|jSy7t|j|j|j|jd|jƒ\}|_WnDt t fk r“}ddl m }||jdt |ƒƒ‚nX||_|S(s­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. R>i(t FileErrorthintN(R?RCRRR;R<R=R>R@tIOErrortOSErrort exceptionsRKR(RDtrvteRK((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyRAhs  cCs#|jdk r|jjƒndS(s+Closes the underlying file, no matter what.N(R?RCRB(RD((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyRBzscCs|jr|jƒndS(s‰This function only closes the file if it was opened by the lazy file wrapper. For instance this will never close stdin. N(R@RB(RD((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytclose_intelligentlys cCs|S(N((RD((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt __enter__†scCs|jƒdS(N(RR(RDtexc_typet exc_valuettb((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt__exit__‰scCs|jƒt|jƒS(N(RAtiterR?(RD((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt__iter__Œs N(t__name__t __module__t__doc__RCR+RFRHRJRARBRRRSRWRY(((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyR8Es         t KeepOpenFilecBs>eZd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs ||_dS(N(t_file(RDtfile((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyRF“scCst|j|ƒS(N(RGR^(RDR((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyRH–scCs|S(N((RD((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyRS™scCsdS(N((RDRTRURV((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyRWœscCs t|jƒS(N(RIR^(RD((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyRJŸscCs t|jƒS(N(RXR^(RD((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyRY¢s(RZR[RFRHRSRWRJRY(((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyR]‘s      cCs†|dkr*|rtƒ}q*tƒ}n|dk rUt|tƒ rUt|ƒ}n|r|pdd}t|tƒrƒ|d7}q|d7}n|rét rét|ƒrét|ƒ}|dk ré|j ƒ|j |ƒ|j ƒdSn|rbt|ƒ rbt |ƒ}t ||ƒr&t |ƒ}qbtrbtdk rGt|ƒ}q_|s_t |ƒ}q_qbn|rx|j |ƒn|j ƒdS(sPrints a message plus a newline to the given file or stdout. On first sight, this looks like the print function, but it has improved support for handling Unicode and binary data that does not fail no matter how badly configured the system is. Primarily it means that you can print binary data as well as Unicode data on both 2.x and 3.x to the given file in the most appropriate way possible. This is a very carefree function as in that it will try its best to not fail. As of Click 6.0 this includes support for unicode output on the Windows console. In addition to that, if `colorama`_ is installed, the echo function will also support clever handling of ANSI codes. Essentially it will then do the following: - add transparent handling of ANSI color codes on Windows. - hide ANSI codes automatically if the destination file is not a terminal. .. _colorama: http://pypi.python.org/pypi/colorama .. versionchanged:: 6.0 As of Click 6.0 the echo function will properly support unicode output on the windows console. Not that click does not modify the interpreter in any way which means that `sys.stdout` or the print statement or function will still not provide unicode support. .. versionchanged:: 2.0 Starting with version 2.0 of Click, the echo function will work with colorama if it's installed. .. versionadded:: 3.0 The `err` parameter was added. .. versionchanged:: 4.0 Added the `color` flag. :param message: the message to print :param file: the file to write to (defaults to ``stdout``) :param err: if set to true the file defaults to ``stderr`` instead of ``stdout``. This is faster and easier than calling :func:`get_text_stderr` yourself. :param nl: if set to `True` (the default) a newline is printed afterwards. :param color: controls if the terminal supports ANSI colors or not. The default is autodetection. uu s N(RCRR R"techo_native_typesRRRRtflushtwriteRR R RR (tmessageR_tnlterrtcolort binary_file((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytecho¦s</             cCs5tj|ƒ}|dkr.td|ƒ‚n|ƒS(s¥Returns a system stream for byte processing. This essentially returns the stream from the sys module with the given name but it solves some compatibility issues between different Python versions. Primarily this function is necessary for getting binary streams on Python 3. :param name: the name of the stream to open. Valid names are ``'stdin'``, ``'stdout'`` and ``'stderr'`` sUnknown standard stream %rN(RtgetRCt TypeError(Rtopener((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytget_binary_streams  R:cCs;tj|ƒ}|dkr.td|ƒ‚n|||ƒS(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 on Python 3 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. sUnknown standard stream %rN(RRiRCRj(RR<R=Rk((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytget_text_streams  R9cCsY|rt||||d|ƒSt||||d|ƒ\}}|sUt|ƒ}n|S(s±This is similar to how the :class:`File` works but for manual usage. Files are opened non lazy by default. This can open regular files as well as stdin/stdout if ``'-'`` is passed. If stdin/stdout is returned the stream is wrapped so that the context manager will not close the stream accidentally. This makes it possible to always use the function like this without having to worry to accidentally close a standard stream:: with open_file(filename) as f: ... .. versionadded:: 3.0 :param filename: the name of the file to open (or ``'-'`` for stdin/stdout). :param mode: the mode in which to open the file. :param encoding: the encoding to use. :param errors: the error handling for this file. :param lazy: can be flipped to true to open the file lazily. :param atomic: in atomic mode writes go into a temporary file and it's moved on close. R>(R8RR](RER;R<R=tlazyR>tfR@((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt open_file(scCs-tr"tr"ttƒkr"tƒStjdS(s†This returns the argument part of sys.argv in the most appropriate form for processing. What this means is that this return value is in a format that works for Click to process but does not necessarily correspond well to what's actually standard for the interpreter. On most environments the return value is ``sys.argv[:1]`` unchanged. However if you are on Windows and running Python 2 the return value will actually be a list of unicode strings instead because the default behavior on that platform otherwise will not be able to carry all possible values that sys.argv can have. .. versionadded:: 6.0 i(RRRRRtsystargv(((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt get_os_argsIscCs%|rtjj|ƒ}nt|ƒS(sKFormats a filename for user display. The main purpose of this function is to ensure that the filename can be displayed at all. This will decode the filename to unicode if necessary in a way that it will not fail. Optionally, it can shorten the filename to not include the full path to the filename. :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. (tostpathtbasenameR (REtshorten((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pytformat_filename^s cCsìtr^|rdpd}tjj|ƒ}|d krKtjjdƒ}ntjj||ƒS|rŠtjjtjjdt|ƒƒƒSt j dkr¸tjjtjjdƒ|ƒStjjtjjdtjjdƒƒt|ƒƒS( sIReturns 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`` Win XP (roaming): ``C:\Documents and Settings\\Local Settings\Application Data\Foo Bar`` Win XP (not roaming): ``C:\Documents and Settings\\Application Data\Foo Bar`` Win 7 (roaming): ``C:\Users\\AppData\Roaming\Foo Bar`` Win 7 (not roaming): ``C:\Users\\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 affect 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. tAPPDATAt LOCALAPPDATAt~s~/.tdarwins~/Library/Application SupporttXDG_CONFIG_HOMEs ~/.configN( RRttenvironRiRCRut expanduserRRRqtplatform(tapp_nametroamingt force_posixtkeytfolder((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyt get_app_diros# &  (.RtRqtglobalsRt_compatRRRRRRRRR R R R R RRRRt _winconsoleRRRR#t bytearrayR`RR R'R7tobjectR8R]RCR,R+RhRlRmRpRsRxR†(((s^/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/click/click/utils.pyts,  j  La