%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/stringutils.pyo

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZe	je�Zed�ddd	��Zdded
�Zdded�Zed�ed
�d���Zd�Zd�Zd�Z ed�d��Z!d�Z"ed�dd��Z#ed�d��Z$d�Z%d�Z&d�Z'ed�ddd��Z(ddd�Z)d d!d"�Z*d#dd$�Z+d%�Z,dS(&u<
Functions for manipulating or otherwise processing strings
i(tabsolute_importtprint_functiontunicode_literalsN(tjinja_filter(tsix(trangeuto_bytesustrictcC@s|dkrdtf}nt|ttf�s<|f}n|sQtd��nd}tjr�t|t�rs|St|t	�r�t|�St|tj
�r�xA|D]9}y|j||�SWq�tk
r�}|}q�q�Xq�W|�nt
d��nt|||�SdS(ua
    Given bytes, bytearray, str, or unicode (python 2), return bytes (str for
    python 2)
    uutf-8uencoding cannot be emptyu!expected bytes, bytearray, or strN(tNonet__salt_system_encoding__t
isinstancettupletlistt
ValueErrorRtPY3tbytest	bytearraytstring_typestencodetUnicodeEncodeErrort	TypeErrortto_str(tstencodingterrorstexctencterr((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytto_bytess,	

	c@s��fd�}|dkr*dtf}nt|ttf�sK|f}n|s`td��nt|t�ry||�Sd}tjrt|t	t
f�r�xG|D]?}y||j||��SWq�tk
r�}|}q�q�Xq�W|�nt
djt|����n�t|t
�r't|�St|t�r�xG|D]?}y||�j||�SWq=tk
r{}|}q=q=Xq=W|�nt
d��dS(uC
    Given str, bytes, bytearray, or unicode (py2), return str
    c@s7y�rtjd|�S|SWntk
r2|SXdS(NuNFC(tunicodedatat	normalizeR(R(R(s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyt
_normalizeFs
uutf-8uencoding cannot be emptyu(expected str, bytes, or bytearray not {}u#expected str, bytearray, or unicodeN(RRRR	R
RtstrRRR
RtdecodetUnicodeDecodeErrorRtformatttypetunicodeRR(RRRRRRRR((Rs:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyRBs>
	
	

	c@sS�fd�}|dkr*dtf}nt|ttf�sK|f}n|s`td��nd}tjr�t|t�r�||�St|t	t
f�r�|t|||��Std��n�t|t
�r�||�St|tt
f�rCxG|D]?}y||j||��SWq�tk
r5}|}q�q�Xq�W|�ntd��dS(uA
    Given str or unicode, return unicode (str for python 3)
    c@s�rtjd|�S|S(NuNFC(RR(R(R(s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyR}suutf-8uencoding cannot be emptyu!expected str, bytes, or bytearrayuexpected str or bytearrayN(RRRR	R
RRRRR
RRRR#RR (RRRRRRRR((Rs:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyt
to_unicodeys2	


	u
str_to_numuto_numcC@sIyt|�SWn4tk
rDyt|�SWqEtk
r@|SXnXdS(u�
    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.
    N(tintRtfloat(ttext((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytto_num�s	

cC@stj|�j�r|SdS(uR
    Convert a string to None if the string is empty or contains only spaces.
    N(Rt	text_typetstripR(R'((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytto_none�scC@sLd}t|tj�rH|d|dkrH|jd�rH|d}n|S(ux
    Return a single or double quote, if a string is wrapped in extra quotes.
    Otherwise return an empty string.
    uii����u'u"(u'u"(RRRt
startswith(tvaluetret((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyt	is_quoted�s
cC@st|�r|dd!S|S(u.
    Remove extra quotes around a string.
    ii����(R/(R-((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytdequote�suis_hexcC@s4yt|d�tSWnttfk
r/tSXdS(uP
    Returns True if value is a hexidecimal string, otherwise returns False
    iN(R%tTrueRRtFalse(R-((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytis_hex�s

cC@s�|s#t|tjtjf�r'tSt|tj�rLd|krbtSntd�|krbtSdjgtdd�D]}t	|�^qxt
d��}tjrt|tj�r�ddl}|j
d|jjj|��}qXdjdd|�}|j
|�}nIt|tj�r7d	�|D�f}ndt|�f}|j
|�}tt|��t|�d
kr~tStS(u@
    Detects if the passed string of data is binary or text
    tuui iu

	iNcS@si|]}dt|��qS(N(Rtord(t.0tx((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pys
<dictcomp>�s	g333333�?(RRRtbinary_typeR2R1RtjoinRtchrR
Rtsalt.utils.datat	translateRtutilstdataRt	maketransR)R&tlen(R>R7ttext_characterstsalttnontextttranst
trans_args((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyt	is_binary�s*#;	$"u
random_stri cC@s2tj|�}ttj|�jdd�| �S(Ns
t(tosturandomR$tbase64t	b64encodetreplace(tsizetkey((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytrandomsucontains_whitespacecC@std�|D��S(uK
    Returns True if there are any whitespace characters in the string
    cs@s|]}|j�VqdS(N(tisspace(R6R7((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pys	<genexpr>s(tany(R'((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytcontains_whitespacescC@s�|d }|d}|j�r�t|�}|dkrE|d9}q�|dkr^|d9}q�|dkrw|d9}q�|dkr�|d	9}q�d
}nd
}|S(u�
    Given a human-readable byte string (e.g. 2G, 30M),
    return the number of bytes.  Will return 0 if the argument has
    unexpected form.

    .. versionadded:: 2018.3.0
    i����uPIuTIuGi@uMii(tisdigitR%(RMtsbytestunit((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pythuman_to_bytess





	cC@swd�}d}xX|j�D]J}g||�D]}tj|�^q/}|djdj|��7}qWdj|�S(uz
    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>
        >>>

    cS@sstj|�}t|_d|_d|kr9d|_n0d|krQd|_nd|krid|_nt|�S(Nuu'\"u'u"(tshlexR1twhitespace_splitt
commenterstquotesR
(R'tlexer((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyt
__build_partsLs		uu(?:[\s]+)?{0}(?:[\s]+)?u
(?:[\s]+)?u	(?m)^{0}$(t
splitlinestretescapeR!R9(R'R\tregextlineRtparts((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytbuild_whitespace_split_regex/s	( cC@syTtj||�rtSy#tjdj|�|�r;tSWntjk
rRnXWn$tk
rztjd||�nXt	S(u
    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
    u\A{0}\Zu)Value %r or expression %r is not a string(
tfnmatchR1R^tmatchR!terrorRtlogt	exceptionR2(Ratexpr((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyt
expr_match_s
ucheck_whitelist_blacklistc@s:|rZt|tj�r$|g}nt|d�s`tdjt|�j|���q`ng}|r�t|tj�r�|g}nt|d�s�tdjt|�j|���q�ng}t�fd�|D��}t�fd�|D��}|r
|r
|S|r|r|S|r2|r2|o1|St	SdS(u&
    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``.
    u__iter__u/Expecting iterable blacklist, but got {0} ({1})u/Expecting iterable whitelist, but got {0} ({1})c3@s|]}t�|�VqdS(N(Rj(R6Ri(R-(s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pys	<genexpr>�sc3@s|]}t�|�VqdS(N(Rj(R6Ri(R-(s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pys	<genexpr>�sN(
RRRthasattrRR!R"t__name__RQR1(R-t	whitelistt	blacklistt_blacklist_matcht_whitelist_match((R-s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytcheck_whitelist_blacklist{s2

cC@st}|rdtjd|�rCtj|d|�r:tnt}qdtj||�r[tnt}n|r�tjd|�r�tj|d|�r�tnt}q�tj||�r�tnt}n|r�|r�|}n7|r�|r�|}n!|r	|r	|o|}nt}|S(u
    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
    uE@i(R1R^RetsearchR2Rd(tpath_strtinclude_pattexclude_patR.tretchk_includetretchk_exclude((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytcheck_include_exclude�s:				
	
	i
g{�G�z�?cC@s�x�|r�y9yt|�Wn$tk
r@t|jd��nXWn~tk
r�}dj|�}|jtjkr�d|ks�|jtjfkr�|r�tj	|�|d8}qq��q�nXPqWdS(u�
    Wrapper around print() that suppresses tracebacks on broken pipes (i.e.
    when salt output is piped to less and less is stopped prematurely).
    uutf-8u{0}utemporarily unavailableiN(
tprintRRtIOErrorR!terrnotEPIPEtEAGAINttimetsleep(tmsgtretrieststepRR((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyt	print_cli�s"	



ic
C@s�|j�}t|�}||kr(|Std||d�}t|||�}||d}g}	|dkr�|	jd�|d7}n|	j|||!�||kr�|	jd�n|r�|	|c|7<ndjdj|	��S(uY
    Returns debugging context around a line in a given string

    Returns:: string
    iiu[...]u---
{0}
---u
(R]R@tmaxtmintappendtextendR!R9(
ttemplateRat	num_linestmarkerttemplate_linestnum_template_linest
context_starttcontext_endterror_line_in_contexttbuf((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytget_context	s"

cO@sdddtf}ddl}djtj|jjj|d|�|jjj|d|�||��S(u�
    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.
    uutf-8ulatin-1iNuR(RR;R9tdifflibtunified_diffR=R>tdecode_list(tatbtargstkwargsRRB((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pytget_diff,s(-t__doc__t
__future__RRRRJR�R{RdtloggingRHRWR^R~Rtsalt.utils.decorators.jinjaRtsalt.extRtsalt.ext.six.movesRt	getLoggerRlRgRRR2RR$R(R+R/R0R3RFRORRRVRcRjRqRxR�R�R�(((s:/usr/lib/python2.7/site-packages/salt/utils/stringutils.pyt<module>sL	$7+				
			%			0		@2#

Zerion Mini Shell 1.0