HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/awscli/__pycache__/shorthand.cpython-38.pyc
U

>�^�=�@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||_t�|tj�|_dS�N)�name�re�compile�UNICODE�regex)�selfrZ	regex_str�r
�2/usr/lib/python3/dist-packages/awscli/shorthand.py�__init__1sz_NamedRegex.__init__cCs|j�|�Sr)r�match�r	�valuer
r
rr
5sz_NamedRegex.matchN)�__name__�
__module__�__qualname__rr
r
r
r
rr0src@seZdZdd�ZdS)�ShorthandParseErrorcCs�|jd|j}}}d|jd|j�krL|jd|j��d�}|j|d}d|j|jd�kr�|j|j|jd��d�}|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
rr9srcs$eZdZ�fdd�Zdd�Z�ZS)�ShorthandParseSyntaxErrorcs4||_||_||_||_|��}tt|��|�dSr)r�expected�actualr�_construct_msg�superrr)r	rrrr�msg��	__class__r
rrSsz"ShorthandParseSyntaxError.__init__cCsd|j|j|��f}|S)Nz,Expected: '%s', received: '%s' for input:
%s)rrr�r	r"r
r
rr [s�z(ShorthandParseSyntaxError._construct_msg�rrrrr �
__classcell__r
r
r#rrRsrcs$eZdZ�fdd�Zdd�Z�ZS)�DuplicateKeyInObjectErrorcs.||_||_||_|��}tt|��|�dSr)�keyrrr r!r(r)r	r)rrr"r#r
rrds
z"DuplicateKeyInObjectError.__init__cCsd|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)rr%r
r
rr ks�z(DuplicateKeyInObjectError._construct_msgr&r
r
r#rr(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|_dSr)Z_tokens�r	r
r
rr�szShorthandParser.__init__cCs||_d|_|��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�
_parameterrr
r
r�parse�szShorthandParser.parsecCsvi}|��\}}|||<|j}|jt|j�krr|jddd�|��\}}||krbt||j|d��|||<|j}q|S�N�,T��consume_whitespacer)�_keyvalr/�lenr.�_expectr()r	�paramsr)�valZ
last_indexr
r
rr0�s �zShorthandParser._parametercCs&|��}|jddd�|��}||fS)N�=Tr4)�_keyr8�_values)r	r)�valuesr
r
rr6�szShorthandParser._keyvalcCsLtjtjd}|j}|��s<|��|kr,q<|jd7_q|j||j�S)Nz-_.#/:r)�stringZ
ascii_lettersZdigitsr/�_at_eof�_currentr.)r	Zvalid_chars�startr
r
rr<�szShorthandParser._keycCs@|��rdS|��dkr |��S|��dkr4|��S|��SdS)Nr�[�{)r@rA�_explicit_list�
_hash_literal�
_csv_valuer-r
r
rr=�szShorthandParser._valuescCs�|��}|��|��s(|j|jdkr,|S|jddd�|g}zB|��}|��|��rh|�|�Wq�|jddd�|�|�Wq@tk
r�|��r��|�	d�Yq�Yq@Xq@t
|�dkr�|S|Sr2)�_first_value�_consume_whitespacer@r.r/r8�
_second_value�appendr�
_backtrack_tor7)r	Zfirst_valueZcsv_listZcurrentr
r
rrG�s,	
	
zShorthandParser._csv_valuecCs>|j�|j|jd��}|dk	r:|�|�}|�dd���SdS)N�\,r3r)�_FIRST_VALUEr
r.r/�_consume_matched_regex�replace�rstrip)r	�resultrr
r
r�_values

zShorthandParser._valuecCsf|jddd�g}|��dkrX|��}|�|�|��|��dkr|�d�|��q|�d�|S)NrCTr4�]r3)r8rA�_explicit_valuesrKrI)r	r>r:r
r
rrEs



zShorthandParser._explicit_listcCs4|��dkr|��S|��dkr(|��S|��SdS)NrCrD)rArErFrHr-r
r
rrUs
z ShorthandParser._explicit_valuescCsz|jddd�i}|��dkrl|��}|jddd�|��}|��|��dkrb|�d�|��|||<q|�d�|S)NrDTr4�}r;r3)r8rAr<rUrI)r	Zkeyvalsr)�vr
r
rrF%s


zShorthandParser._hash_literalcCs0|��dkr|��S|��dkr(|��S|��S)N�'�")rA�_single_quoted_value�_double_quoted_valuerSr-r
r
rrH4s
zShorthandParser._first_valuecCs|j|jdd�S)NrX��escaped_char)�_consume_quoted�_SINGLE_QUOTEDr-r
r
rrZ<sz$ShorthandParser._single_quoted_valueNcCs:|�|�dd�}|dk	r6|�d||�}|�dd�}|S)Nr���z\%sz\\�\)�_must_consume_regexrP)r	rr]rr
r
rr^Bs
zShorthandParser._consume_quotedcCs|j|jdd�S)NrYr\)r^�_DOUBLE_QUOTEDr-r
r
rr[Isz$ShorthandParser._double_quoted_valuecCsH|��dkr|��S|��dkr(|��S|�|j�}|�dd���SdS)NrXrYrMr3)rArZr[rb�
_SECOND_VALUErPrQ)r	rr
r
rrJLszShorthandParser._second_valueFcCsr|r|��|jt|j�kr.t|j|d|j��|j|j}||krTt|j|||j��|jd7_|rn|��dS)NZEOFr)rIr/r7r.r)r	�charr5rr
r
rr8Us ��zShorthandParser._expectcCsD|�|j|jd��}|dk	r(|�|�St|jd|jd|j��dS)Nz<%s>z<none>)r
r.r/rOrr)r	rrRr
r
rrbcs
�z#ShorthandParser._must_consume_regexcCs<|��\}}|j|j||j|�}|j||7_|Sr)�spanr.r/)r	rRrB�endrWr
r
rrOjsz&ShorthandParser._consume_matched_regexcCs |jt|j�kr|j|jStSr)r/r7r.�_EOFr-r
r
rrApszShorthandParser._currentcCs|jt|j�kSr)r/r7r.r-r
r
rr@wszShorthandParser._at_eofcCs.|jdkr*|j|j|kr*|jd8_qdS)Nrr)r/r.)r	rer
r
rrLzszShorthandParser._backtrack_tocCs.|��tkr*|��tjkr*|jd7_qdS)Nr)rArhr?Z
whitespacer/r-r
r
rrI~sz#ShorthandParser._consume_whitespace)N)F)%rrr�__doc__rr_rcZ_START_WORDZ_FIRST_FOLLOW_CHARSZ_SECOND_FOLLOW_CHARSZ_ESCAPED_COMMA�formatrNrdrr1r0r6r<r=rGrSrErUrFrHrZr^r[rJr8rbrOrAr@rLrIr
r
r
rr*ts\

����	
0	
	
r*c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ModelVisitorcCs|�i|d|�dS)Nr)�_visit)r	r9Zmodelr
r
r�visit�szModelVisitor.visitcCs&t|d|j|j�}|||||�dS)Nz	_visit_%s)�getattr�	type_name�
_visit_scalar)r	�parent�shaperr�methodr
r
rrl�s�zModelVisitor._visitc	Cs<t|t�sdS|j��D]\}}|�||||�|��qdSr)�
isinstance�dict�members�itemsrl�get)r	rqrrrr�member_nameZmember_shaper
r
r�_visit_structure�s

�zModelVisitor._visit_structurecCs6t|t�sdSt|�D]\}}|�||j||�qdSr)rt�list�	enumeraterl�member)r	rqrrrr�i�elementr
r
r�_visit_list�s
zModelVisitor._visit_listcCs:t|t�sdS|j}|��D]\}}|�||||�qdSr)rtrurrwrl)r	rqrrrrZvalue_shape�krWr
r
r�
_visit_map�s

zModelVisitor._visit_mapcCsdSrr
�r	rqrrrrr
r
rrp�szModelVisitor._visit_scalarN)	rrrrmrlrzr�r�rpr
r
r
rrk�srkcs$eZdZ�fdd�Zdd�Z�ZS)�BackCompatVisitorcs8t|t�s|dk	r4|g||<ntt|��||||�SdSr)rtr{r!r�r�r�r#r
rr��s

�zBackCompatVisitor._visit_listcCst|dkrdS|j}|dkr(t|�||<nH|dkr>t|�||<n2|dkrp|��dkr\d||<n|��dkrpd||<dS)N)ZintegerZlong)Zdouble�floatZboolean�trueTZfalseF)ro�intr��lower)r	rqrrrrror
r
rrp�s
zBackCompatVisitor._visit_scalar)rrrr�rpr'r
r
r#rr��s
r�)
rirr?�objectrhr�	Exceptionrrr(r*rkr�r
r
r
r�<module>
s	!