/usr/lib/python3/dist-packages/sos/__pycache__
NameSizeModeActions
archive.cpython-310.pyc235540644editdlrm
component.cpython-310.pyc161280644editdlrm
missing.cpython-310.pyc27590644editdlrm
options.cpython-310.pyc115130644editdlrm
utilities.cpython-310.pyc232920644editdlrm
__init__.cpython-310.pyc52530644editdlrm
Edit: /usr/lib/python3/dist-packages/sos/__pycache__/utilities.cpython-310.pyc (23292B)
o G%@id @sddlZddlZddlZddlZddlmZmZmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlmZddlmZzddlmZWneyeddlmZYnwedZdZz ddlZee d ZWn!ee!fydd l"m#Z#d Z$e%d e#e$d ddd YnwdZ&gdZ'ddZ(dTddZ)ddZ*dUddZ+ddZ,ddZ-ddZ.dVd d!Z/d"d#Z0dWd$d%Z1d&e2fd'd(Z3e&dddddddddddf d)d*Z4dXd+d,Z5dWd-d.Z6dYd0d1Z7dZd3d4Z8ej9fd5d6Z:d7d8Z;d9d:ZZ>d?d@Z?ej@dAdBdCZAdDdEZBgfdFdGZCGdHdIdIZDGdJdKdKejEZFGdLdMdMejEZGGdNdOdOZHGdPdQdQZIGdRdSdSeJZKdS)[N)PopenPIPESTDOUT)closing)deque)parse) parse_versionsosFT)fillzWARNING: Failed to load 'magic' module version >= 0.4.20 which sos aims to use for detecting binary files. A less effective method will be used. It is recommended to install proper python3-magic package with the module.  H)replace_whitespacei,)TIMEOUT_DEFAULTImporterHelperSoSTimeoutError TempFileUtilboldfile_is_binaryfileobjfindget_human_readablegrep import_module is_executablelistdirr path_exists path_isdir path_isfile path_islink path_joinrecursive_dict_values_by_key shell_outsos_get_command_outputtac_logstailc Cstd}z#|j|dd\}}}|s|WStdd|d}|d|}|WStyG}ztd|d ||WYd }~Sd }~ww) z< Convert the version into a PEP440 compliant version scheme.z2^([0-9][0-9.]*(?:(?:a|b|rc|.post|.dev)[0-9]+)*)\+?)maxsplitz[+~]+.-+zUnable to format z to pep440 format: N)recompilesplitsubstrip Exceptionlogdebug)verpublic_version_re_publiclocalsanitized_localpep440_versionerrr://usr/lib/python3/dist-packages/sos/utilities.pyformat_version_to_pep440Psr<cCs|r t|}t|St|S)z6 Converts the version to PEP440 format before parsing )r<r)r2pep440 ver_pep440r:r:r;sos_parse_versionasr?cCsTt|d}t|j|kr|| d|WdS1s#wYdS)z,Returns the last number_of_bytes of filenamerbN)openosstatst_sizeseekread)filenamenumber_of_bytesfr:r:r;r$js $r$rcCsTt|tr&zt||ddWSty%td|dttYSwt|S)z@Returns a file-like object that can be used as a context managerutf-8encodingz fileobj: z could not be opened) isinstancestrrBIOErrorr0r1rioStringIO) path_or_filemoder:r:r;rrs  rcCsHddddd}|D]\}}||kr t||d|Sq |S)zCConverts a number of bytes to a shorter, more human friendly formatli@)TGMKz.1f)itemsfloat) num_bytessizessymbolsizer:r:r; convert_bytes~s rbcCs|dddvrDt|ddd+}|}td|r# WddStd |r2 Wdd SWddS1s=wYdSdS) aHelper to determine if a given file is a certificate or not. This is especially helpful for `sos clean`, which cannot obfuscate certificate files content and instead, by default, will keep them as is. :param fname: The full path of the file to check :type fname: ``str`` :returns: The type of the certificate or ``None`` :rtype: ``string`` or ``None`` N)z.csrz.crtz.pemrKrLrMz-----BEGIN CERTIFICATE----- certificatez"-----BEGIN [A-Z]+ PRIVATE KEY-----certificatekey)rBrGr*search)fnamerJcontentr:r:r;file_is_certificates    ric str'zt|ddg}jdkotfdd|D WSty&Ynwt|ddd }z|d WWd d StyMYWd d Sw1sQwYd S) azHelper to determine if a given file contains binary content or not. This is especially helpful for `sos clean`, which cannot obfuscate binary data and instead, by default, will remove binary files. :param fname: The full path of the file to check binaryness of :type fname: ``str`` :returns: True if binary, else False :rtype: ``bool`` ztext/zinode/binaryc3s|] }j|VqdSN) mime_type startswith).0_mt_ftupr:r; z!file_is_binary..trrLrMr%NFT) magic_modmagicdetect_from_filenamerNanyr/rBrGUnicodeDecodeError)rg_mimestfiler:rpr;rs*      rc cs|rtj|tjj}||7}t|D]/\}}}|r,|tjj|kr,|dd=|r5t||s5qt||D] }tj||Vq;qdS)zGenerator function to find files recursively. Usage:: for filename in find("*.properties", "/var/log/foobar"): print filename N) rCpathdirnamecountsepwalkfnmatchfilterjoin) file_patterntop_dir max_depth path_pattern base_depthr|dirlistfilelistnamer:r:r;rs rc sRg}|D]"}t|}|fdd|DWdn1s!wYq|S)zReturns lines matched in fnames, where fnames can either be pathnames to files to grep through or open file objects to grep through line by linec3s |] }t|r|VqdSrk)r*match)rnlinepatternr:r;rrszgrep..N)rextend)rfiles_or_pathsmatchesfopfor:rr;rs rcs\tjddtjj}gfdd|D}r%|fdd|D7}tdd|DS)z6Returns if a command matches an executable on the PATHPATHcsg|] }tj|qSr:)rCr|r)rnp)commandr:r; z!is_executable..cs g|] }tj|dqS)/)rCr|rlstrip)rncsysrootr:r;rscss|] }t|tjVqdSrk)rCaccessX_OK)rnr|r:r:r;rrsz is_executable..)rCenvirongetr,r|pathseprx)rrpaths candidatesr:)rrr;rs rurlcCsddlm}m}z2||}|js|jr8d}|jr||j7}|jr(|d|j7}||j||j|j |j |j fWS|WSt yE|YSw)zK Replace username:password@ with ********@ in proxy URL if present r)urlparse urlunparsez ********@:) urllib.parserrusernamepasswordhostnameportschemer|paramsqueryfragmentr/)rrr parsed_urlnetlocr:r:r;scrub_url_credentials"     rc  s(fdd} fdd}r3zt}Wnty&ddddYSw||j|jdtj}d |d <|rT|D]\}}|rM|||<qB| |d qB|rit d rid |r_dndd|d|}t |}g}|D]#}| drd|vrt|}|r||qr||qr||qr| r|rt}n| rtjtj| d}nt| d}nt}zTzt|d||rtntd|d| d}| r|r| rtjtj| d}nt| d}t|j|||}n t||}nt|j||}r|jr|||jsn]z ||r |nd WnPty^| | r<| r._child_prep_fncs,s |dkr|ttddS)N|{Gz?)poll terminatertimesleep)proc)pollerr:r; _check_pollersz-sos_get_command_output.._check_pollerr)statusoutput truncated)HOMELOGNAMEPWDUSERzC.UTF-8LC_ALLNtimeoutztimeout z --foreground zs r*dirwbFT)shellstdoutstderrbufsizeenv close_fds preexec_fnrcloser)~r)+rrKeyErrorupdaterrCrcopyr\poprshlexr,rmglobrappendrtempfile TemporaryFiler|r}rBrr HeadReaderr FakeReader TailReaderrunningwaitr/rr# get_contentsis_fullhasattrrr returncodeOSErrorerrnoENOENT)rrrrrr foregroundrj sizelimitrto_filetacrrrpwd_usercmd_envkeyvalueargs expanded_argsarg expanded_arg_outputrreaderf_dstrer:)rrrrr;r"s                 @      @ ;   @  r"c Cs d}d}d}|t|jdkrdStj|dtjdZ}|d}}|||kr2d}|dkrk||d|}||d|krK|d krJn)q2|rPd }n | ||d|d|}|dks6WddSWddSWddS1s~wYdS) zPython implementation of the tac utility with support for multiline logs (starting with space). It is intended to reverse the output of 'journalctl --reverse'.  rN)rr%TrF) flushrCfstatfilenorEmmap ACCESS_READrarfindwrite) f_srcr  drop_last_log NEWLINE_B NEWLINE_ISPACE_Immsep1sep2r:r:r;r#s4  "r#c sdd}z ttt|g}Wnty-}ztdd|jj|d}~wwfddt |tj D}rGfdd|D}|S) aImports the module module_fqname and returns a list of defined classes from that module. If superclasses is defined then the classes returned will be subclasses of the specified superclass or superclasses. If superclasses is plural it must be a tuple of classes.r'rz"Error while trying to load module z: Ncsg|] \}}|jkr|qSr:) __module__)rncnameclass_) module_fqnamer:r;rs z!import_module..csg|] }t|r|qSr:) issubclass)rnm) superclassesr:r;rr) rpartition __import__globalslocals ImportErrorprint __class____name__inspect getmembersisclass)r r# module_namemoduler modulesr:)r r#r;rs    rcCst||||ddS)zeShell out to an external command and return the output or the empty string in case of error. )rrrr)r")cmdrrrunatr:r:r;r!s r!rAcCsVgd}d}|dkr|dkr|d7}|d}|dkr|dks|d|d||S) N)BKiBMiBGiBTiBrrWr%g@r'rJr:)ra precisionsuffixes suffixindexr:r:r;rsrcCs>|r|tjkr||stj||d}t||}||Sr)rCrrmr|rrgetattr)r|rmethodr0_methr:r:r; _os_wrappers   rAcCs$d|vr t||dtdSt||dS)Nrr)r0exists)rArr|rr:r:r;rs rcC t||dS)NisdirrArCr:r:r;r rcCrD)NisfilerFrCr:r:r;rrGrcCrD)NislinkrFrCr:r:r;rrGrcCst||dtS)Nr)rArCrCr:r:r;rrrcGs8|r||stj||tj}tjj|g|RSrk)rmrCr|rrr)r|rrr:r:r;rsrcCs d|dS)a"Helper to make text bold in console output, without pulling in dependencies to the project unneccessarily. :param text: The text to make bold :type text: ``str`` :returns: The text wrapped in the ASCII codes to display as bold :rtype: ``str`` zzr:)textr:r:r;r s rc sg}g||t|trS|D]?\}||r!||vr)|tqttrQz|tfdd|DdWn tyIYnwqn||fdd|DS)a Recursively compile all elements of a potentially nested dict by a set of keys. If a given key is a dict within ``dobj``, then _all_ elements within that dict, regardless of child keys, will be returned. For example, if a Plugin searches the devices dict for the 'storage' key, then all storage devices under the that dict (e.g. block, fibre, etc...) will be returned. However, if the Plugin specifies 'block' via ``keys``, then only the block devices within the devices['storage'] dict will be returned. Any elements passed here that are _not_ keys within the dict or any nested dicts will also be returned. :param dobj: The 'top-level' dict to intially search by :type dobj: ``dict`` :param keys: Which keys to compile elements from within ``dobj``. If no keys are given, all nested elements are returned :param keys: ``list`` of ``str`` :returns: All elements within the dict and any nested dicts :rtype: ``list`` c3s |] }|vr|VqdSrkr:)rnr)vr:r;rrAsz/recursive_dict_values_by_key..rcsg|]}|vr|qSr:r:)rnd)_filtr:r;rMsz0recursive_dict_values_by_key..)rrOdictr\rr IndexErrorkeys)dobjrQ_itemskr:)rNrLr;r s2        r c@s8eZdZdZddZeddZddZedd Zd S) rzUsed when we are writing directly to disk without sizelimits, this allows us to keep more simplified flows for executing, monitoring, and collecting command output. cCs||_||_dSrk)processrj)selfrUrjr:r:r;__init__V zFakeReader.__init__cCsdS)NFr:rVr:r:r;rZszFakeReader.is_fullcC|jsdSdSNrrrjrYr:r:r;r^rJzFakeReader.get_contentscCs|jduSrk)rUrrYr:r:r;raszFakeReader.runningN) r+r __qualname____doc__rWpropertyrrrr:r:r:r;rPs rcs@eZdZdZdZfddZddZddZed d Z Z S) rzzUsed to 'head' the command output (f_src) to a given size without deadlocking sos. Takes a sizelimit value in MB. rVcs8t||_||_|d|_||_d|_|dS)NrVT)superrWrr  remainingrjrstart)rVrr rrjr*r:r;rWms   zHeadReader.__init__cCsb|jdkr'|jt|j|j}|sn|j||jt|8_|jdks|jd|_ dS)zReads from the f_src (Popen stdout pipe) until we reach sizelimit. once done, close f_src to signal the program that we are done. rFN) rarrGmin COPY_BUFSIZEr rlenrr)rVbufr:r:r;runvs    zHeadReader.runcCrZr[r\rYr:r:r;rrJzHeadReader.get_contentscCs |jdkS)Nr)rarYr:r:r;rs zHeadReader.is_full) r+rr]r^rerWrhrr_r __classcell__r:r:rcr;rfs   rcs<eZdZdZfddZddZddZedd ZZ S) rzUsed to tail the command output to a given size without deadlocking sos. Takes a sizelimit value in MB, and will compile stdout from Popen into a string that is limited to the given sizelimit. cs^t||_||_d|_d|_|r|d}t||j|_t|jd|_d|_| dS)NirV)maxlenT) r`rWchanrj chunksizeslotsintrrrb)rVchannelrrjrcr:r;rWs  zTailReader.__init__c CsJz |j|j}|s n|j|qWn ttfyYnwd|_dS)alReads from the channel (pipe) that is the output pipe for a called Popen. As we are reading from the pipe, the output is added to a deque. After the size of the deque exceeds the sizelimit earlier (older) entries are removed. This means the returned output is chunksize-sensitive, but is not really byte-sensitive. TFN)rkrGrlrr ValueErrorrQr)rVrr:r:r;rhs   zTailReader.runcCsH|jr td|js|jsddd|jDSddd|jDS)z-Returns the contents of the deque as a stringrrcss|] }|ddVqdS)rLignoreN)decodernlnr:r:r;rrrsz*TailReader.get_contents..rcss|]}|VqdSrkr:rsr:r:r;rrs)rrrrjrrrYr:r:r;rs  zTailReader.get_contentscCs|jsdSt|j|jkS)z?Checks if the deque is full, implying that output was truncatedF)rmrfrrYr:r:r;rszTailReader.is_full) r+rr]r^rWrhrr_rrir:r:rcr;rs   rc@s8eZdZdZddZddZddZdd Zd d Zd S) rzProvides a list of modules that can be imported in a package. Importable modules are located along the module __path__ list and modules are files that end in .py. cCs ||_dS)zopackage is a package module import my.package.module helper = ImporterHelper(my.package.module)N)package)rVrur:r:r;rWs zImporterHelper.__init__cCs tj|}tj|\}}|S)z-Returns the plugin module name given the path)rCr|basenamesplitext)rVr|baserr4r:r:r; _plugin_names zImporterHelper._plugin_namecsfdd|D}||S)Ncs(g|]}d|vr|dr|qS)rWz.py)endswithry)rnpluginrYr:r;rs z9ImporterHelper._get_plugins_from_list..)sort)rVlist_pluginsr:rYr;_get_plugins_from_lists z%ImporterHelper._get_plugins_from_listcCs0tj|rttd|}||}|r|SgS)Nz*.py)rCr|rBlistrr)rVr|py_filespnamesr:r:r;_find_plugins_in_dirs  z#ImporterHelper._find_plugins_in_dircCs2g}|jjD]}tj|r|||q|S)zQReturns the list of importable modules in the configured python package. )ru__path__rCr|rErr)rVr~r|r:r:r; get_moduless   zImporterHelper.get_modulesN) r+rr]r^rWryrrrr:r:r:r;rs rc@s$eZdZddZddZddZdS)rcCs||_g|_dSrk)tmp_dirfiles)rVrr:r:r;rWrXzTempFileUtil.__init__cCs2tj|jd\}}t|d}|j||f|S)Nrzw+)rmkstemprrCfdopenrr)rVfdrgfobjr:r:r;news zTempFileUtil.newc Csb|jD](\}}z ||Wn tyYnwzt|Wqty+Yqwg|_dSrk)rrrr/rCunlink)rVrgrJr:r:r;cleans    zTempFileUtil.cleanN)r+rr]rWrrr:r:r:r;rs rc@s eZdZdS)rN)r+rr]r:r:r:r;rsr)T)rK)NNrk)F)r2NN)rA)LrCrr*r, subprocessrrrloggingrrrrr threadingrrRr contextlibr collectionsrpackaging.versionrrr( pkg_resources getLoggerr0rurvrw__file__AttributeErrortextwrapr msgwarningr__all__r<r?r$rrbrirrrrrPrr"r#rr!rr|rArrrrrrrrr rThreadrrrrrrr:r:r:r;s             "     *    6%<,