HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //proc/self/root/lib/python3.6/site-packages/awscli/__pycache__/shorthand.cpython-36.opt-1.pyc
3

�T_�=�@s�dZddlZddlZe�ZGdd�de�ZGdd�de�ZGdd�de�ZGd	d
�d
e�Z	Gdd�de�Z
Gd
d�de�ZGdd�de�ZdS)a�Module for parsing shorthand syntax.

This module parses any CLI options that use a "shorthand"
syntax::

    --foo A=b,C=d
         |------|
            |
            Shorthand syntax


This module provides two main classes to do this.
First, there's a ``ShorthandParser`` class.  This class works
on a purely syntactic level.  It looks only at the string value
provided to it in order to figure out how the string should be parsed.

However, because there was a pre-existing shorthand parser, we need
to remain backwards compatible with the previous parser.  One of the
things the previous parser did was use the associated JSON model to
control how the expression was parsed.

In order to accommodate this a post processing class is provided that
takes the parsed values from the ``ShorthandParser`` as well as the
corresponding JSON model for the CLI argument and makes any adjustments
necessary to maintain backwards compatibility.  This is done in the
``BackCompatVisitor`` class.

�Nc@seZdZdd�Zdd�ZdS)�_NamedRegexcCs||_tj|tj�|_dS)N)�name�re�compile�UNICODE�regex)�selfrZ	regex_str�r	�/usr/lib/python3.6/shorthand.py�__init__1sz_NamedRegex.__init__cCs|jj|�S)N)r�match)r�valuer	r	r
r5sz_NamedRegex.matchN)�__name__�
__module__�__qualname__rrr	r	r	r
r0src@seZdZdd�ZdS)�ShorthandParseErrorcCs�|jd|j}}}d|jd|j�krL|jd|j�jd�}|j|d}d|j|jd�kr�|j|j|jd�jd�}|jd|�}|j|d�}d|d|d|fS)N��
�z%s
%s%s� �^)r
�index�rindex)r�consumedZ	remainingZ
num_spacesZlast_newlineZnext_newliner	r	r
�_error_location;sz#ShorthandParseError._error_locationN)rrrrr	r	r	r
r9srcs$eZdZ�fdd�Zdd�Z�ZS)�ShorthandParseSyntaxErrorcs4||_||_||_||_|j�}tt|�j|�dS)N)r
�expected�actualr�_construct_msg�superrr)rr
rrr�msg)�	__class__r	r
rSsz"ShorthandParseSyntaxError.__init__cCsd|j|j|j�f}|S)Nz,Expected: '%s', received: '%s' for input:
%s)rrr)rr r	r	r
r[sz(ShorthandParseSyntaxError._construct_msg)rrrrr�
__classcell__r	r	)r!r
rRsrcs$eZdZ�fdd�Zdd�Z�ZS)�DuplicateKeyInObjectErrorcs.||_||_||_|j�}tt|�j|�dS)N)�keyr
rrrr#r)rr$r
rr )r!r	r
rds
z"DuplicateKeyInObjectError.__init__cCsd|j|j�f}|S)NzySecond instance of key "%s" encountered for input:
%s
This is often because there is a preceeding "," instead of a space.)r$r)rr r	r	r
rksz(DuplicateKeyInObjectError._construct_msg)rrrrrr"r	r	)r!r
r#csr#c@seZdZdZedd�Zedd�ZdZdZdZ	d	Z
ed
dje
eed��Zed
dje
ee	d��Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd>d)d*�Zd+d,�Zd-d.�Zd?d0d1�Zd2d3�Zd4d5�Z d6d7�Z!d8d9�Z"d:d;�Z#d<d=�Z$d(S)@�ShorthandParserz�Parses shorthand syntax in the CLI.

    Note that this parser does not rely on any JSON models to control
    how to parse the shorthand syntax.

    zsingled quotedz\'(?:\\\\|\\\'|[^\'])*\'z
double quotedz"(?:\\\\|\\"|[^"])*"u\!\#-&\(-\+\--\<\>-Z\\-z|-￿u\s\!\#-&\(-\+\--\\\^-\|~-￿u\s\!\#-&\(-\+\--\<\>-￿z(\\,)�firstzC({escaped_comma}|[{start_word}])({escaped_comma}|[{follow_chars}])*)Z
escaped_commaZ
start_wordZfollow_chars�secondcCs
g|_dS)N)Z_tokens)rr	r	r
r�szShorthandParser.__init__cCs||_d|_|j�S)aSParse shorthand syntax.

        For example::

            parser = ShorthandParser()
            parser.parse('a=b')  # {'a': 'b'}
            parser.parse('a=b,c')  # {'a': ['b', 'c']}

        :tpye value: str
        :param value: Any value that needs to be parsed.

        :return: Parsed value, which will be a dictionary.
        r)�_input_value�_index�
_parameter)rr
r	r	r
�parse�szShorthandParser.parsecCszi}|j�\}}|||<|j}xV|jt|j�krt|jddd�|j�\}}||krdt||j|d��|||<|j}q W|S)N�,T)�consume_whitespacer)�_keyvalr)�lenr(�_expectr#)r�paramsr$�valZ
last_indexr	r	r
r*�s
zShorthandParser._parametercCs&|j�}|jddd�|j�}||fS)N�=T)r-)�_keyr0�_values)rr$�valuesr	r	r
r.�szShorthandParser._keyvalcCsPtjtjd}|j}x(|j�s>|j�|kr.P|jd7_qW|j||j�S)Nz-_.#/:r)�stringZ
ascii_lettersZdigitsr)�_at_eof�_currentr()rZvalid_chars�startr	r	r
r4�s
zShorthandParser._keycCs@|j�rdS|j�dkr |j�S|j�dkr4|j�S|j�SdS)Nr�[�{)r8r9�_explicit_list�
_hash_literal�
_csv_value)rr	r	r
r5�szShorthandParser._valuescCs�|j�}|j�|j�s(|j|jdkr,|S|jddd�|g}xpy@|j�}|j�|j�rh|j|�P|jddd�|j|�WqBtk
r�|j�r��|j	d�PYqBXqBWt
|�dkr�|S|S)Nr,T)r-r)�_first_value�_consume_whitespacer8r(r)r0�
_second_value�appendr�
_backtrack_tor/)rZfirst_valueZcsv_listZcurrentr	r	r
r?�s.
	
zShorthandParser._csv_valuecCs>|jj|j|jd��}|dk	r:|j|�}|jdd�j�SdS)Nz\,r,r)�_FIRST_VALUErr(r)�_consume_matched_regex�replace�rstrip)r�resultrr	r	r
�_values

zShorthandParser._valuecCsj|jddd�g}xH|j�dkrZ|j�}|j|�|j�|j�dkr|jd�|j�qW|jd�|S)Nr;T)r-�]r,)r0r9�_explicit_valuesrCrA)rr6r2r	r	r
r=s


zShorthandParser._explicit_listcCs4|j�dkr|j�S|j�dkr(|j�S|j�SdS)Nr;r<)r9r=r>r@)rr	r	r
rLs
z ShorthandParser._explicit_valuescCs~|jddd�i}x\|j�dkrn|j�}|jddd�|j�}|j�|j�dkrd|jd�|j�|||<qW|jd�|S)Nr<T)r-�}r3r,)r0r9r4rLrA)rZkeyvalsr$�vr	r	r
r>%s

zShorthandParser._hash_literalcCs0|j�dkr|j�S|j�dkr(|j�S|j�S)N�'�")r9�_single_quoted_value�_double_quoted_valuerJ)rr	r	r
r@4s
zShorthandParser._first_valuecCs|j|jdd�S)NrO)�escaped_char)�_consume_quoted�_SINGLE_QUOTED)rr	r	r
rQ<sz$ShorthandParser._single_quoted_valueNcCs:|j|�dd�}|dk	r6|jd||�}|jdd�}|S)Nrz\%sz\\�\���)�_must_consume_regexrG)rrrSr
r	r	r
rTBs
zShorthandParser._consume_quotedcCs|j|jdd�S)NrP)rS)rT�_DOUBLE_QUOTED)rr	r	r
rRIsz$ShorthandParser._double_quoted_valuecCsH|j�dkr|j�S|j�dkr(|j�S|j|j�}|jdd�j�SdS)NrOrPz\,r,)r9rQrRrX�
_SECOND_VALUErGrH)rrr	r	r
rBLszShorthandParser._second_valueFcCsr|r|j�|jt|j�kr.t|j|d|j��|j|j}||krTt|j|||j��|jd7_|rn|j�dS)NZEOFr)rAr)r/r(r)r�charr-rr	r	r
r0Us

zShorthandParser._expectcCsD|j|j|jd��}|dk	r(|j|�St|jd|jd|j��dS)Nz<%s>z<none>)rr(r)rFrr)rrrIr	r	r
rXcs

z#ShorthandParser._must_consume_regexcCs<|j�\}}|j|j||j|�}|j||7_|S)N)�spanr(r))rrIr:�endrNr	r	r
rFjsz&ShorthandParser._consume_matched_regexcCs |jt|j�kr|j|jStS)N)r)r/r(�_EOF)rr	r	r
r9pszShorthandParser._currentcCs|jt|j�kS)N)r)r/r()rr	r	r
r8wszShorthandParser._at_eofcCs2x,|jdkr,|j|j|kr,|jd8_qWdS)Nrr)r)r()rr[r	r	r
rDzszShorthandParser._backtrack_tocCs2x,|j�tkr,|j�tjkr,|jd7_qWdS)Nr)r9r^r7Z
whitespacer))rr	r	r
rA~sz#ShorthandParser._consume_whitespace)N)F)%rrr�__doc__rrUrYZ_START_WORDZ_FIRST_FOLLOW_CHARSZ_SECOND_FOLLOW_CHARSZ_ESCAPED_COMMA�formatrErZrr+r*r.r4r5r?rJr=rLr>r@rQrTrRrBr0rXrFr9r8rDrAr	r	r	r
r%tsT




0	
	
r%c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ModelVisitorcCs|ji|d|�dS)Nr)�_visit)rr1Zmodelr	r	r
�visit�szModelVisitor.visitcCs&t|d|j|j�}|||||�dS)Nz	_visit_%s)�getattr�	type_name�
_visit_scalar)r�parent�shaperr
�methodr	r	r
rb�szModelVisitor._visitcCs@t|t�sdSx,|jj�D]\}}|j||||j|��qWdS)N)�
isinstance�dict�members�itemsrb�get)rrgrhrr
�member_nameZmember_shaper	r	r
�_visit_structure�s


zModelVisitor._visit_structurecCs:t|t�sdSx&t|�D]\}}|j||j||�qWdS)N)rj�list�	enumeraterb�member)rrgrhrr
�i�elementr	r	r
�_visit_list�s
zModelVisitor._visit_listcCs>t|t�sdS|j}x$|j�D]\}}|j||||�qWdS)N)rjrkr
rmrb)rrgrhrr
Zvalue_shape�krNr	r	r
�
_visit_map�s

zModelVisitor._visit_mapcCsdS)Nr	)rrgrhrr
r	r	r
rf�szModelVisitor._visit_scalarN)	rrrrcrbrprvrxrfr	r	r	r
ra�sracs$eZdZ�fdd�Zdd�Z�ZS)�BackCompatVisitorcs8t|t�s|dk	r4|g||<ntt|�j||||�SdS)N)rjrqrryrv)rrgrhrr
)r!r	r
rv�s


zBackCompatVisitor._visit_listcCst|dkrdS|j}|d
kr(t|�||<nH|dkr>t|�||<n2|dkrp|j�dkr\d||<n|j�dkrpd	||<dS)N�integer�long�double�floatZboolean�trueTZfalseF)rzr{)r|r})re�intr}�lower)rrgrhrr
rer	r	r
rf�s
zBackCompatVisitor._visit_scalar)rrrrvrfr"r	r	)r!r
ry�s
ry)
r_rr7�objectr^r�	Exceptionrrr#r%raryr	r	r	r
�<module>(s	!