o
    TikL                  
   @   sf  d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZ ddlmZ dgZejejB ejB Zdd	 Ze \ZZZd
ZdZedZedeZe	de	de	de	de	de	de	de	de	dd	ZdZdd Z dd Z!dd Z"ddeej#e	d j$eej%fd!d"Z&d#d$ Z'd%d& Z(d1d'd(Z)d)d* Z*	+d2d,d-Z+d.d/ Z,G d0d de-Z.dS )3zImplementation of HjsonDecoder
    )absolute_importN   )fromhexbu	text_typebinary_typePY3unichr)HjsonDecodeErrorHjsonDecoderc                  C   sZ   t d} tjdkr| d d d d d | dd  d d d  } td| \}}||| fS )N 7FF80000000000007FF0000000000000big   dd)r   sys	byteorderstructunpack)_BYTESnaninf r   A/home/ubuntu/.local/lib/python3.10/site-packages/hjson/decoder.py_floatconstants   s
   
,r   z 	
z{}[],:z5[\t ]*(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?[\t ]*z(.*?)([\'"\\\x00-\x1f])"'\/
	)	r   r   r   r   r   fnrtzutf-8c                 C   s  	 | ||d  }|t v r%|dkr||fS |d7 }| ||d  }|t v s| |d |d  }|dks;|dkrA|dkrAt| |}nF|dkr|dkr|d7 }| | }|dkry|dkra| |d  dksy|d7 }| | }|dkry|dkra| |d  dkra|dkr|d7 }n	 ||fS q)Nr       #r   *)
WHITESPACEgetEol)sendchch2r   r   r   getNext'   s.     r3   c                 C   s8   	 | ||d  }|dks|dks|dkr|S |d7 }q)Nr   r#   r"   r)   r   )r/   r0   r1   r   r   r   r.   B   s   r.   c                 C   st   | ||d  }|dkr8|dv r8|dks|dk r8|d7 }|d8 }| ||d  }|dkr8|dv r8|dks|dk s|S )Nr   r)   z 	r   r   )r/   r0   r&   r1   r   r   r   
skipIndentK   s     r4   Tr)   c	                 C   s  |du rt }g }	|	j}
|d }| | }	 || |}|du r#td| || }| \}}|r?|s;t|ts;t||}|
| ||krEn|dksM|dkrR|
| q|dkre|r`d}t|| ||
| qz| | }W n tyx   td| |w |dkrz|| }W n ty   d	}t|| |w |d7 }nd
}| |d |d  }|dd }t	|dks|dks|dkrt|| |d zt
|d}W n ty   t|| |d w |d7 }|dkr@|d@ dkr@| ||d  dkr@| |d |d  }|dd }t	|dkr@|dks@|dks@zt
|d}W n ty(   t|| |w |d@ dkr@d|d d> |d B  }|d7 }t|}|
| q||	|fS )a  Scan the string s for a JSON string. End is the index of the
    character in s after the quote that started the JSON string.
    Unescapes all valid JSON string escape sequences and raises ValueError
    on attempt to decode an invalid string. If strict is False then literal
    control characters are allowed in the string.

    Returns a tuple of the decoded string and the index of the character in s
    after the end quote.Nr   zUnterminated string starting atr   r   r   zInvalid control character %r atr   zInvalid \X escape sequence %rzInvalid \uXXXX escape sequence   r*      xX   i  i   i   z\u   i   i   
   )DEFAULT_ENCODINGappendr   r0   groups
isinstancer   
IndexErrorKeyErrorlenint
ValueErrorr
   )r/   r0   encodingstrict_b_m_join_PY3_maxunicodechunks_appendbeginexitChchunkcontent
terminatormsgesccharescXuniesc2uni2r   r   r   
scanstringT   s   



"GrZ   c                 C   s*  d}d}d}	 | || d  }|dkrn|d7 }qt | |d d}| | }|dkr1t | |d |}	 | ||d  }|dkrDtd| ||dkrg|d7 }|d7 }|dkrf|rb|d dkrb|d	d }||fS q1|dkrw|d7 }|d8 }|dksk|dkr||7 }t | |d |}n|d
kr||7 }|d7 }q2)zScan a multiline stringr)   r   r   r"      r   zBad multiline stringr   Nr#   )r4   r   )r/   r0   stringtripleindentr1   r   r   r   mlscanstring   sD   
r_   c                 C   s  t ||\}}|}|tv rtd||	 |||d  }|dkp'|dkp'|dk}|sV|dksV|dksV|dksV|d	ksV|d
kr||d |d  d
ksV||d |d  dkrd}|}tr`|d8 }|dkrr|||  dkrrd|fS |dkr|||  dkrd|fS |dkr|||  dkrd|fS |dks|dkr|dkrt||}|dur| |kr| \}	}
}|
s|r| 	|	|
pd |pd }t
||krt|dk rt
|}||fS | |	}||fS |r|||  |fS |d7 }q)z4Scan s until eol. return string, True, False or NonezRFound a punctuator character when expecting a quoteless string (check your syntax)r   r#   r"   r)   ,}]r+   r   r*   r,   Nr&   nullr(   trueTr%   falseF-09g    _B)r3   
PUNCTUATORr   nextstrip	NUMBER_REmatchr0   r>   parse_floatrC   abs	parse_int)contextr/   r0   chfrN   r1   isEolmmendintegerfracexpresr   r   r   	scantfnns   sD   8 
rz   c                 C   s&  t | |\}}|dks|dkrt| |d ||S |}d}	 | ||d  }|dkr/td| ||dkr_||kr=td| ||d	krW||d krMtd
| || ||  |fS | || |fS |tv rp|d	k sm||d kro|}n|dks|dks|dks|dks|dkrtd| d | ||d7 }q)z6Scan the string s for a JSON/Hjson key. see scanstringr   r   r   r   r)   zBad key name (eof):z<Found ':' but no key name (for an empty key name use quotes)r   z9Found whitespace in your key name (use quotes to include){ra   [rb   r`   zFound 'zo' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace))r3   rZ   r   rstripr-   )r/   r0   rE   rF   r1   rN   spacer   r   r   scanKeyName
  s.   (r   c                    s   j jj	jj
jjjjj	 	
fdd  fdd} fdd}||fS )Nc                    s   z| | }W n t y   td| |w |dks|dkr4| ||d  dkr+| |S 	| |d S |dkrF| |d f S |dkrS| |d f S 
| |S )	NExpecting valuer   r   r[   z'''r   r|   r}   )r@   r   )r\   idxr1   
_scan_oncerq   rE   memoobject_hookobject_pairs_hookparse_arrayparse_mlstringparse_objectparse_stringparse_tfnnsrF   r   r   r   3  s    
z make_scanner.<locals>._scan_oncec                    s4   |dk r
t d| |z
 | |W   S   w )Nr   r   r   clearr\   r   )r   r   r   r   	scan_onceF  s   
zmake_scanner.<locals>.scan_oncec              	      sD   |dk r
t d| |z| |f dW   S   w )Nr   r   Tr   r   )r   rE   r   r   r   r   rF   r   r   scan_object_onceM  s   
z&make_scanner.<locals>.scan_object_once)
r   r   r   r   r   rE   rF   r   r   r   )rq   r   r   r   r   r   make_scanner'  s   "r   Fc                 C   st  | \}}	|d u r
i }|j }
g }t||	\}}	|s:|dkr:|d ur*||}||	d fS i }|d ur4||}||	d fS 	 t||	||\}}	|
||}t||	\}}	|dkrZtd||	t||	d \}}	|||	\}}	|||f t||	\}}	|dkrt||	d \}}	|r|dkrnn	|dkr|	d7 }	nt||	\}}	q;|d ur||}||	fS t|}|d ur||}||	fS )Nra   r   Tr{   zExpecting ':' delimiterr`   r)   )
setdefaultr3   r   r   r=   dict)staterE   rF   r   r   r   r   objectWithoutBracesr/   r0   memo_getpairsr1   resultkeyvaluer   r   r   
JSONObjectX  sP   
r   c                 C   s   | \}}g }t ||\}}|dkr||d fS |dkr!td|||j}	 |||\}}|| t ||\}}|dkrDt ||d \}}|dkrQ|d7 }	 ||fS t ||\}}q%)Nrb   r   r)   zCEnd of input while parsing an array (did you forget a closing ']'?)Tr`   )r3   r   r=   )r   r   r/   r0   valuesr1   rM   r   r   r   r   	JSONArray  s(   r   c                   @   s:   e Zd ZdZ			dddZefddZdefd	d
ZdS )r   as  Hjson decoder

    Performs the following translations in decoding by default:

    +---------------+-------------------+
    | JSON          | Python            |
    +===============+===================+
    | object        | dict              |
    +---------------+-------------------+
    | array         | list              |
    +---------------+-------------------+
    | string        | str, unicode      |
    +---------------+-------------------+
    | number (int)  | int, long         |
    +---------------+-------------------+
    | number (real) | float             |
    +---------------+-------------------+
    | true          | True              |
    +---------------+-------------------+
    | false         | False             |
    +---------------+-------------------+
    | null          | None              |
    +---------------+-------------------+

    NTc                 C   sp   |du rt }|| _|| _|| _|pt| _|pt| _|| _t	| _
t| _t| _t| _t| _i | _t| \| _| _dS )a  
        *encoding* determines the encoding used to interpret any
        :class:`str` objects decoded by this instance (``'utf-8'`` by
        default).  It has no effect when decoding :class:`unicode` objects.

        Note that currently only encodings that are a superset of ASCII work,
        strings of other encodings should be passed in as :class:`unicode`.

        *object_hook*, if specified, will be called with the result of every
        JSON object decoded and its return value will be used in place of the
        given :class:`dict`.  This can be used to provide custom
        deserializations (e.g. to support JSON-RPC class hinting).

        *object_pairs_hook* is an optional function that will be called with
        the result of any object literal decode with an ordered list of pairs.
        The return value of *object_pairs_hook* will be used instead of the
        :class:`dict`.  This feature can be used to implement custom decoders
        that rely on the order that the key and value pairs are decoded (for
        example, :func:`collections.OrderedDict` will remember the order of
        insertion). If *object_hook* is also defined, the *object_pairs_hook*
        takes priority.

        *parse_float*, if specified, will be called with the string of every
        JSON float to be decoded.  By default, this is equivalent to
        ``float(num_str)``. This can be used to use another datatype or parser
        for JSON floats (e.g. :class:`decimal.Decimal`).

        *parse_int*, if specified, will be called with the string of every
        JSON int to be decoded.  By default, this is equivalent to
        ``int(num_str)``.  This can be used to use another datatype or parser
        for JSON integers (e.g. :class:`float`).

        *strict* controls the parser's behavior when it encounters an
        invalid control character in a string. The default setting of
        ``True`` means that unescaped control characters are parse errors, if
        ``False`` then control characters will be allowed in strings.

        N)r<   rE   r   r   floatrn   rC   rp   rF   r   r   r   r   rZ   r   r_   r   rz   r   r   r   r   r   )selfrE   r   rn   rp   rF   r   r   r   r   __init__  s   )

zHjsonDecoder.__init__c                 C   sX   |rt |tr|| j}| |\}}t||\}}|t|kr*td||t||S )zzReturn the Python representation of ``s`` (a ``str`` or ``unicode``
        instance containing a JSON document)

        z
Extra data)r?   r   decoderE   
raw_decoder3   rB   r   )r   r/   rJ   objr0   r1   r   r   r   r     s   zHjsonDecoder.decoder   c              
   C   s  |dk r
t d|||rt|tstdt||kr<t|| }|dkr*|d7 }n|dkr<|||d  dkr<|d7 }|}t||\}}|dkrQ|d	krQi dfS |d
ksY|dkr_| ||S z| ||W S  t y } zz| ||W W  Y d}~S    |d}~ww )a  Decode a JSON document from ``s`` (a ``str`` or ``unicode``
        beginning with a JSON document) and return a 2-tuple of the Python
        representation and the index in ``s`` where the document ended.
        Optionally, ``idx`` can be used to specify an offset in ``s`` where
        the JSON document begins.

        This can be used to decode a JSON document from a string that may
        have extraneous data at the end.

        r   r   zInput string must be texti  r      r[   u   ï»¿r)   r|   r}   N)	r   r?   r   	TypeErrorrB   ordr3   r   r   )r   r/   r   rJ   ord0start_indexr1   er   r   r   r     s2   
zHjsonDecoder.raw_decode)NNNNTN)__name__
__module____qualname____doc__r   r	   r   r   r   r   r   r   r     s    
9)NT)NF)/r   
__future__r   rer   r   compatr   r   r   r   r   r	   r
   scannerr   __all__VERBOSE	MULTILINEDOTALLFLAGSr   NaNPosInfNegInfr-   ri   compilerl   STRINGCHUNK	BACKSLASHr<   r3   r.   r4   rm   join
maxunicoderZ   r_   rz   r   r   r   r   objectr   r   r   r   r   <module>   sD    $	
		
[.
-2
8