o @&aI@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z e j Z e j Z e jjZe jjZe jZe jZe jjjjZe jZe jjjZz ddlZejZWn eygejZYnwzddlZWn eyydZYnwejdkZerdZ ndZ Gddde!Z"Gd d d e#Z$d d Z%e j rddl&m'Z(ddl)Z)ddl*m+Z,dd l-m.Z.e/Z0ddZ1ddZ2ddZ3d?ddZ4d@ddZ5n2ddl6Z6ddl7Z(ddl)Z)ddl8Z8ddl,Z,dd l9m.Z.e0Z0ddZ1ddZ2ddZ3d?ddZ4d@ddZ5ddZ:d d!Z;d"d#Zd@d(d)Z?ej@d*d+ZAz dd,lmBZBWdSeywd-ZCd.d/ZDeEd0ejFZGeEd1ejFZHeEd2ejFZId3ZJd4d5ZKeEd6ejLZMeEd7ejLZNeEd8ejLZOd9d9d9eJd:fd;d<ZBd=d>ZPYdSw)AN)six) OrderedDictwin32morezless -RcseZdZfddZZS)StdinMissingErrorcsd}tt||dS)Nz;stdin is required for this operation, but is not available.)superr__init__)selfmessage __class__//usr/lib/python3/dist-packages/awscli/compat.pyrDszStdinMissingError.__init__)__name__ __module__ __qualname__r __classcell__r r r rrCsrc@s eZdZdZddZddZdS)NonTranslatedStdouta This context manager sets the line-end translation mode for stdout. It is deliberately set to binary mode so that ` ` does not get added to the line ending. This can be useful when printing commands where a windows style line ending would cause errors. cCs.tjdkrddl}|tjtj|_tjSNrr) sysplatformmsvcrtsetmodestdoutfilenoosO_BINARY previous_mode)r rr r r __enter__Ss  zNonTranslatedStdout.__enter__cCs.tjdkrddl}|tj|jdSdSr)rrrrrrr)r typevalue tracebackrr r r__exit__Zs zNonTranslatedStdout.__exit__N)rrr__doc__rr"r r r rrKs rcCs6t|tjr|St|tjr|dStdt|)Nutf-8z,Expected str, unicode or bytes, received %s.) isinstancer text_type binary_typedecode ValueErrorr)sr r rensure_text_type`s   r+)URLErrorcCstjdurttjjSN)rstdinrbufferr r r rget_binary_stdinqs r0cCstjjSr-)rrr/r r r rget_binary_stdoutvsr1cCs|Sr-r )streamerrorsr r r_get_text_writerysr4rcCsd|vrt}t|||dS)a>Back-port open() that accepts an encoding argument. In python3 this uses the built in open() and in python2 this uses the io.open() function. If the file is not being opened in binary mode, then we'll use locale.getpreferredencoding() to find the preferred encoding. bencoding)localegetpreferredencodingopenfilenamemoder8r r r compat_open|s r?cCs>|durtj}t|ddr|j|dS||ddS)zE This function is used to write raw bytes to stdout. Nr/r$)rrgetattrr/writer( statementrr r r bytes_prints  rDcCstjdurttjSr-)rr.rr r r rr0s cCstjSr-)rrr r r rr1scCs$t}|dur d}t|||S)Nascii)r9r:codecs getwriter)r2r3r8r r rr4scCs d|vrt}tj|||dS)Nr6r7)r9r:ior;r<r r rr?scCs|durtj}||dSr-)rrrArBr r rrDscCttjddS)Nstrictr3)r4rrr r r rget_stdout_text_writerrLcCrI)NreplacerK)r4rstderrr r r rget_stderr_text_writerrMrPcCstj|tjtS)au Cygwin's pty's are based on pipes. Therefore, when it interacts with a Win32 program (such as Win32 python), what that program sees is a pipe instead of a console. This is important because python buffers pipes, and so on a pty-based terminal, text will not necessarily appear immediately. In most cases, this isn't a big deal. But when we're doing an interactive prompt, the result is that the prompts won't display until we fill the buffer. Since raw_input does not flush the prompt, we need to manually write and flush it. See https://github.com/mintty/mintty/issues/56 for more details. )rrrAflush raw_input)promptr r r compat_inputs rTcCs&|durtj}|dkrt|St|S)zReturn a shell-escaped version of the string *s* Unfortunately `shlex.quote` doesn't support Windows, so this method provides that functionality. Nr)rr_windows_shell_quote shlex_quote)r*rr r rcompat_shell_quotes rWcCs|sdSg}d}|D]6}|dkr|d7}q |dkr.|dkr(|d|dd}|dq |dkr;|d|d}||q |dkrL|d|d|}d |vsYd |vr]d |S|S) aReturn a Windows shell-escaped version of the string *s* Windows has potentially bizarre rules depending on where you look. When spawning a process via the Windows C runtime the rules are as follows: https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments To summarize the relevant bits: * Only space and tab are valid delimiters * Double quotes are the only valid quotes * Backslash is interpreted literally unless it is part of a chain that leads up to a double quote. Then the backslashes escape the backslashes, and if there is an odd number the final backslash escapes the quote. :param s: A string to escape :return: An escaped string z""r\"z\"  z"%s")appendjoin)r*buffnum_backspaces characternew_sr r rrUs,    rUcCs4i}|durt}trddi}nt|}||d<|S)zReturns the default pager to use dependent on platform :rtype: str :returns: A string represent the paging command to run based on the platform being used. NshellTargs) default_pager is_windowsshlexsplit) pager_cmd popen_kwargsr r rget_popen_kwargs_for_pager_cmd9s  rmc cstrtjg}ntjtjtjg}g}|D] }|t|tjqzdVWt|D] \}}t|||q*dSt|D] \}}t|||q=w)zG Ignores user entered signals to avoid process getting killed. N)rhsignalSIGINTSIGQUITSIGTSTPr_SIG_IGN enumerate) signal_listactual_signals user_signalsigr r rignore_user_entered_signalsMs rx)linux_distributionz/etcc CstjdrLd}td3}|D](}|}t|dkr |\}}nq|dkr*|}q|dkr7|d}|d}qWdn1sBwY|||fStjdrtd.}|D]#}|d} t| dkr|| d d kr|d | d |fWdSqYWdn1swYtjd rtd } t t| d d d D]} | | dddkr| | =q| r| d}| d dd}|||fS|||fS)z Tries some special tricks to get the distribution information in case the default method fails. Currently supports older SuSE Linux, Caldera OpenLinux and Slackware Linux distributions. z/var/adm/inst-log/infoSuSEr[MIN_DIST_VERSION DIST_IDENT-Nz/etc/.installedr OpenLinuxrYz/usr/lib/setupzslack-version- slackware) rpathexistsr;rjlenstripisdirlistdirrangesort) distnameversionidflinetvtagr valuespkgverfilesnr r r_dist_try_hardergsN             rz(\w+)[-_](release|version)z'(.+) release ([\d.]+)[^(]*(?:\((.+)\))?z1([^0-9]+)(?: release )?([\d.]+)[^(]*(?:\((.+)\))?)rzdebianfedoraredhatcentosmandrakemandrivarocksr yellowdoggentoo UnitedLinux turbolinuxarchmageiacCszd}d}t|}|durt|St|}|dur"t|S|}|r8|d}t|dkr8|d}d||fS)Nr\rrY)_lsb_release_versionmatchtuplegroups_release_versionrrjr) firstlinerrmlr r r_parse_release_files       rz(?:DISTRIB_ID\s*=)\s*(.*)z(?:DISTRIB_RELEASE\s*=)\s*(.*)z(?:DISTRIB_CODENAME\s*=)\s*(.*)r\rYcCst|||||Sr-)_linux_distribution)rrrsupported_distsfull_distribution_namer r rrys ryc CszWtddH}|D],}t|}|r|d}t|}|r'|d} t|}|r5|d} q |rG| rG|| | fWdWSWdn1sQwYWn ttfybYnwzt t } Wnt yx|||fYSw| | D]} t| }|dur|\} }| |vr| }nqt|||Stt jt | dddd }|}Wdn1swYt|\} }}| r|r| }|r|}|r|}|||fS)a Tries to determine the name of the Linux OS distribution name. The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. supported_dists may be given to define the set of Linux distributions to look for. It defaults to a list of currently supported Linux distributions identified by their release file name. If full_distribution_name is true (default), the full distribution read from the OS is returned. Otherwise the short name taken from supported_dists is used. Returns a tuple (distname, version, id) which default to the args given as parameters. z/etc/lsb-releaser5rYNr$surrogateescape)r8r3)r;_distributor_id_file_researchgroupr_release_file_re_codename_file_reEnvironmentErrorUnboundLocalErrorrr _UNIXCONFDIROSErrorr_release_filenamerrrrr`readliner)rrrrr etclsbrelrr _u_distname _u_version_u_idetcfile _distnamedummyrr_version_idr r rrsf           r)r5Nr-)Qrreriros.pathrzipfilern contextlibbotocore.compatrradvance_iteratorPY3movesqueuerVStringIOBytesIOurllibrequesturlopenr' configparserRawConfigParserzlib ZIP_DEFLATEDZIP_COMPRESSION_MODE ImportError ZIP_STOREDsqlite3rhrg Exceptionrobjectrr+collections.abcabccollections_abcr9 urllib.parseparseurlparse urllib.errorr,inputrRr0r1r4r?rDrF collectionsrHurllib2rLrPrTrWrUrmcontextmanagerrxryrrcompileASCIIrrr_supported_distsrIrrrrr r r rs                     ? 0