403Webshell
Server IP : 198.38.94.13  /  Your IP : 216.73.217.33
Web Server : Apache
System : Linux d4744.dxb1.stableserver.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : revivere ( 1140)
PHP Version : 8.2.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/stringutils.cpython-310.pyc
o

;j�C�@szdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZe�
e�Zed�d9dd��Zd:dd	�Zd:d
d�Zed�ed
�dd
���Zdd�Zdd�Zdd�Zed�dd��Zdd�Zed�d;dd��Zed�dd��Zed�d<d!d��Zd"d#�Zd$d%�Zed&�d=d'd&��Zd=d(d)�Zd>d,d-�Z d?d/d0�Z!d1d2�Z"ed3�d4d5��Z#ed6�d@d7d8��Z$dS)Az<
Functions for manipulating or otherwise processing strings
�N)�jinja_filter�to_bytes�strictcCs�|durdtf}t|ttf�s|f}|std��d}t|t�r!|St|t�r*t|�St|t�rS|D]}z	|�||�WSt	yP}z|}WYd}~q1d}~ww|�t
dt|�����)za
    Given bytes, bytearray, str, or unicode (python 2), return bytes (str for
    python 2)
    N�utf-8�encoding cannot be empty�&expected str, bytes, or bytearray not )�__salt_system_encoding__�
isinstance�tuple�list�
ValueError�bytes�	bytearray�str�encode�UnicodeEncodeError�	TypeError�type)�s�encoding�errors�exc�enc�err�r�J/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/stringutils.pyrs,


��Fcs��fdd�}|durdtf}t|ttf�s|f}|std��t|t�r'||�Sd}t|ttf�rV|D]!}z||�||��WSt	yS}z|}WYd}~q2d}~ww|�t
dt|�����)zC
    Given str, bytes, bytearray, or unicode (py2), return str
    cs0z�r
t�d|�WS|WSty|YSw�NZNFC)�unicodedata�	normalizer�r�rrr�
_normalize<s
�zto_str.<locals>._normalizeNrrr)rr	r
rrrr
r�decode�UnicodeDecodeErrorrr)rrrrr!rrrrr r�to_str7s*
��r$cs~�fdd�}|durdtf}t|ttf�s|f}|std��t|t�r'||�St|ttf�r6|t|||��St	dt
|�����)zA
    Given str or unicode, return unicode (str for python 3)
    cs�rt�d|�S|Sr)rrrr rrr!bszto_unicode.<locals>._normalizeNrrr)rr	r
rrrr
rr$rr)rrrrr!rr r�
to_unicode]s
r%Z
str_to_num�to_numcCsDzt|�WSty!zt|�WYSty |YYSww)z�
    Convert a string to a number.
    Returns an integer if the string represents an integer, a floating
    point number if the string is a real number, or the string unchanged
    otherwise.
    )�intr�float��textrrrr&us	
��cCst|���r|SdS)zR
    Convert a string to None if the string is empty or contains only spaces.
    N)r�stripr)rrr�to_none�sr,cCs4d}t|t�r|d|dkr|�d�r|d}|S)zx
    Return a single or double quote, if a string is wrapped in extra quotes.
    Otherwise return an empty string.
    �r���)�'�")r	r�
startswith)�value�retrrr�	is_quoted�s��r4cCst|�r
|dd�S|S)z.
    Remove extra quotes around a string.
    �r.)r4�r2rrr�dequote�sr7�is_hexc	Cs*zt|d�WdSttfyYdSw)zP
    Returns True if value is a hexadecimal string, otherwise returns False
    �TF)r'rrr6rrrr8�s
�cCs�|r
t|tftf�sdSt|t�rd|vrdSnd|vrdSd�dd�tdd	�D�td
��}t|t�rDddl}|�d|jj	�
|��}nd�dd|�}|�|�}tt
|��t
|�d
kr^dSdS)z@
    Detects if the passed string of data is binary or text
    F�T�r-cSsg|]}t|��qSr)�chr��.0�xrrr�
<listcomp>�szis_binary.<locals>.<listcomp>� �z

	rNg333333�?)r	rr
�join�ranger�salt.utils.data�	translate�utils�datar�	maketransr(�len)rHZtext_characters�saltZnontextZtransrrr�	is_binary�s"
�"

rLZ
random_strrAcCs(t�|�}tt�|��dd�d|��S)N�
�)�os�urandomr%�base64�	b64encode�replace)�size�keyrrr�random�s
rV�contains_whitespacecCstdd�|D��S)zK
    Returns True if there are any whitespace characters in the string
    cs��|]}|��VqdS�N)�isspacer=rrr�	<genexpr>���z&contains_whitespace.<locals>.<genexpr>)�anyr)rrrrW�s�human_to_bytes�BcCs�t�dt|����}|�d�}|�d���p|��}zt|�}Wnty;zt|�}Wnty8YYdSwYnwd}t�d|�rK|rHdnd}nt�d|�sSdSd	�	|d�}||rcd
|dnd|d
9}t|�S)
z�
    Given a human-readable byte string (e.g. 2G, 30MB, 64KiB),
    return the number of bytes.  Will return 0 if the argument has
    unexpected form.

    .. versionadded:: 2018.3.0
    .. versionchanged:: 3005
    z"(?P<value>[0-9.]*)\s*(?P<unit>.*)$r2�unitrFz[kmgtpezy]b$Tz(b|[kmgtpezy](ib)?)$Z	bkmgtpezy�
��)
�re�matchrr+�group�lowerr'rr(�index)rTZdefault_unitZ
handle_metric�mr2r`�dec�prrrr^�s*

��� cCsLdd�}d}|��D]}dd�||�D�}|d�d�|��7}q
d|�d	�S)
az
    Create a regular expression at runtime which should match ignoring the
    addition or deletion of white space or line breaks, unless between commas

    Example:

    .. code-block:: python

        >>> import re
        >>> import salt.utils.stringutils
        >>> regex = salt.utils.stringutils.build_whitespace_split_regex(
        ...     """if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then"""
        ... )

        >>> regex
        '(?:[\s]+)?if(?:[\s]+)?\[(?:[\s]+)?\-z(?:[\s]+)?\"\$debian'
        '\_chroot\"(?:[\s]+)?\](?:[\s]+)?\&\&(?:[\s]+)?\[(?:[\s]+)?'
        '\-r(?:[\s]+)?\/etc\/debian\_chroot(?:[\s]+)?\]\;(?:[\s]+)?'
        'then(?:[\s]+)?'
        >>> re.search(
        ...     regex,
        ...     """if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then"""
        ... )

        <_sre.SRE_Match object at 0xb70639c0>
        >>>

    cSsXt�|�}d|_d|_d|vrd|_t|�Sd|vr!d|_t|�Sd|vr(d|_t|�S)NTr-z'\"r/r0)�shlexZwhitespace_splitZ
commenters�quotesr)r*Zlexerrrr�
__build_partss
��z3build_whitespace_split_regex.<locals>.__build_partsr-cSsg|]}t�|��qSr)rd�escape)r>rrrrr@-sz0build_whitespace_split_regex.<locals>.<listcomp>z(?:[\s]+)?{}(?:[\s]+)?z
(?:[\s]+)?z(?m)^�$)�
splitlines�formatrC)r*rnZregex�line�partsrrr�build_whitespace_split_regexsrucCstz(t�||�r
WdSzt�d|�d�|�rWWdSWWdStjy(YWdSwty9t�d||�YdSw)a
    Checks whether or not the passed value matches the specified expression.
    Tries to match expr first as a glob using fnmatch.fnmatch(), and then tries
    to match expr as a regular expression. Originally designed to match minion
    IDs for whitelists/blacklists.

    Note that this also does exact matches, as fnmatch.fnmatch() will return
    ``True`` when no glob characters are used and the string is an exact match:

    .. code-block:: python

        >>> fnmatch.fnmatch('foo', 'foo')
        True
    Tz\Az\Zz)Value %r or expression %r is not a stringF)�fnmatchrdre�errorr�log�	exception)rs�exprrrr�
expr_match2s ����r{�check_whitelist_blacklistcs�|rt|t�r
|g}t|d�std�t|�j|���ng}|r8t|t�r'|g}t|d�s7td�t|�j|���ng}t�fdd�|D��}t�fdd�|D��}|rW|sW|S|r]|s]|S|rf|rf|oe|SdS)a&
    Check a whitelist and/or blacklist to see if the value matches it.

    value
        The item to check the whitelist and/or blacklist against.

    whitelist
        The list of items that are white-listed. If ``value`` is found
        in the whitelist, then the function returns ``True``. Otherwise,
        it returns ``False``.

    blacklist
        The list of items that are black-listed. If ``value`` is found
        in the blacklist, then the function returns ``False``. Otherwise,
        it returns ``True``.

    If both a whitelist and a blacklist are provided, value membership
    in the blacklist will be examined first. If the value is not found
    in the blacklist, then the whitelist is checked. If the value isn't
    found in the whitelist, the function returns ``False``.
    �__iter__z-Expecting iterable blacklist, but got {} ({})z-Expecting iterable whitelist, but got {} ({})c3��|]}t�|�VqdSrY�r{�r>rzr6rrr[~��z,check_whitelist_blacklist.<locals>.<genexpr>c3r~rYrr�r6rrr[r�T)r	r�hasattrrrrr�__name__r])r2Z	whitelistZ	blacklistZ_blacklist_matchZ_whitelist_matchrr6rr|Ns>


���


���
c	Cs�dd�}d}|r!t|t�r|D]}|||�}|rnqn|||�}|r>t|t�r8|D]}|||�}|s6nq*n|||�}|rF|sF|}|S|rN|sN|}|S|rX|rX|oU|}|Sd}|S)a
    Check for glob or regexp patterns for include_pat and exclude_pat in the
    'path_str' string and return True/False conditions as follows.
      - Default: return 'True' if no include_pat or exclude_pat patterns are
        supplied
      - If only include_pat or exclude_pat is supplied: return 'True' if string
        passes the include_pat test or fails exclude_pat test respectively
      - If both include_pat and exclude_pat are supplied: return 'True' if
        include_pat matches AND exclude_pat does not match
    cSs<t�d|�rt�|dd�|�rdSdSt�||�rdSdS)NzE@rcTF)rdre�searchrv)�path_strZ	check_patrrr�
_pat_check�sz)check_include_exclude.<locals>._pat_checkT)r	r)	r�Zinclude_patZexclude_patr�r3Zinclude_lineZretchk_includeZexclude_lineZretchk_excluderrr�check_include_exclude�s>

��

�����r�ra�{�G�z�?c
Cs�|rXzzt|�WWdStyt|�d��YnwWdStyW}z-|�}|jtjkrLd|vs:|jtjfvrK|rKt�|�|d8}WYd}~q�WYd}~dSd}~wwdS)z�
    Wrapper around print() that suppresses tracebacks on broken pipes (i.e.
    when salt output is piped to less and less is stopped prematurely).
    rztemporarily unavailabler5N)	�printrr�OSError�errnoZEPIPE�EAGAIN�time�sleep)�msgZretries�steprrrrr�	print_cli�s2����

�	���r��c
Cs�|��}t|�}||kr|Std||d�}t|||�}||d}g}	|dkr3|	�d�|d7}|	�|||��||krE|	�d�|rO|	||7<d�d�|	��S)zY
    Returns debugging context around a line in a given string

    Returns:: string
    rr5z[...]z
---
{}
---�
)rqrJ�max�min�append�extendrrrC)
�templatersZ	num_lines�markerZtemplate_linesZnum_template_linesZ
context_startZcontext_endZerror_line_in_context�bufrrr�get_context�s"

r�cOsNddtf}ddl}d�tj|jjj||d�|jjj||d�g|�Ri|���S)z�
    Perform diff on two iterables containing lines from two files, and return
    the diff as as string. Lines are normalized to str types to avoid issues
    with unicode on PY2.
    rzlatin-1rNr-)r)rrErC�difflibZunified_diffrGrHZdecode_list)�a�b�args�kwargsrrKrrr�get_diff�s
����r�Z
to_snake_casecCsx|d��}t|dd�d�D]*\}}|��r3||d��s/|t|�dkr3||d��r3|d7}||��7}q|S)a
    Converts camelCase (or CamelCase) to snake_case.
    From https://codereview.stackexchange.com/questions/185966/functions-to-convert-camelcase-strings-to-snake-case

    :param str camel_input: The camelcase or CamelCase string to convert to snake_case

    :return str
    rr5N�_)rg�	enumerate�isupper�islowerrJ)Zcamel_input�res�iZletterrrr�camel_to_snake_cases
 r�Zto_camelcasecCsB|�d�}|r|d��|d<|dd�dd�|dd�D��S)ah
    Converts snake_case to camelCase (or CamelCase if uppercamel is ``True``).
    Inspired by https://codereview.stackexchange.com/questions/85311/transform-snake-case-to-camelcase

    :param str snake_input: The input snake_case string to convert to camelCase
    :param bool uppercamel: Whether or not to convert to CamelCase instead

    :return str
    r�rr-csrXrY)�
capitalize)r>�wordrrrr[5r\z&snake_to_camel_case.<locals>.<genexpr>r5N)�splitr�rC)Zsnake_inputZ
uppercamel�wordsrrr�snake_to_camel_case's
$r�)Nr)NrF)rA)r_F)NN)rar�)r�N)F)%�__doc__rQr�r�rv�loggingrOrdrlr�rZsalt.utils.decorators.jinjar�	getLoggerr�rxrr$r%r&r,r4r7r8rLrVrWr^rur{r|r�r�r�r�r�r�rrrr�<module>sX

!
&		

1
@
3
#


Youez - 2016 - github.com/yon3zu
LinuXploit