+
    Nis                          R t ^ RIt^ RIHtHt RR.tR R ltR^ /R R	 llt]P                  ! R
]P                  R7      t
RRRRRRRRRRRRRRRRRRRR/
tR^ /R R lltR R  ltR# )!z4
Support for unescaping strings produced by GDB MI.
N)IteratorTuple$advance_past_string_with_gdb_escapesunescapec                0    V ^8  d   QhR\         R\         /# )   escaped_strreturn)str)formats   "9/tmp/pip-target-e6j6ikcs/lib/python/pygdbmi/gdbescapes.py__annotate__r      s      # #     c                H    \        V RR7      w  rVR8X  g   Q RV R24       hV# )zUnescape a string escaped by GDB in MI mode.

Args:
    escaped_str: String to unescape (without initial and final double quote).

Returns:
    The strings with escape codes transformed into normal characters.
F)expect_closing_quotezafter_string_index is zE but it was expected to be -1 as expect_closing_quote is set to False_unescape_internal)r   unescaped_strafter_string_indexs   &  r   r   r      sJ     );%)%M # 
 !3 4 5D 	D# r   startc                ^    V ^8  d   QhR\         R\        R\        \         \        3,          /# )r   r   r   r	   )r
   intr   )r   s   "r   r   r   "   s1     S SS #S
38_Sr   c                   \        V RVR7      # )a   Unescape a string escaped by GDB in MI mode, and find the double quote
terminating it.

Args:
    escaped_str: String to unescape (without initial double quote).
    start: the position in escaped_str at which to start unescaping the string

Returns:
    A tuple containing the unescaped string and the index in escaped_str just after
    the escape string (that is, escaped_str[start-1] is always the closing double
    quote and escaped_str[start:] is the portion of escaped_str after the escaped
    string).
T)r   r   r   )r   r   s   &$r   r   r   "   s      kERRr   av  
    # Match all text before an escape or quote so it can be preserved as is.
    (?P<before>
        .*?
    )
    # Match either an escape or an unescaped quote.
    (
        (
            # All escapes start with a backslash...
            \\
            # ... and are followed by either a 3-digit octal number or a single
            # character for common escapes. See _GDB_MI_NON_OCTAL_ESCAPES for valid
            # ones.
            (
                # Instead of matching a single octal escape we match multiple ones in a
                # row.
                # This is because a single Unicode character can be encoded as multiple
                # escape sequences so, if we decoded the escape sequences one at a time,
                # the resulting string would not be valid until all the bytes are
                # converted.
                # This could also be solved by converting the input string into bytes
                # but that's much slower for long strings.
                (?P<escaped_octal>
                    # First octal number without backslash which we matched earlier.
                    [0-7]{3}
                    # Addional (and optional) octal numbers, including a backslash.
                    (
                        \\
                        [0-7]{3}
                    )*
                )
                |
                (?P<escaped_char>.)
            )
        )
        |
        # Match an unescaped quote.
        # If expect_closing_quote is true, then this means the string is finished.
        # If false, then the quote should have been escaped.
        (?P<unescaped_quote>")
    )
    )flags'\abefn
rt	"c          
      j    V ^8  d   QhR\         R\        R\        R\        \         \        3,          /# )r   r   r   r   r	   )r
   boolr   r   )r   s   "r   r   r   u   s:     g; g;g;/3g;<?g;
38_g;r   c          	        TpRp. p\         P                  WR7       EF   pVP                  VR,          4       VR,          pVR,          pVR,          p	VP                  4       w  rVe^   \	        4       p\        VP                  RR	4      ^4       F   p VP                  \        V^R
7      4       K"  	   VP                  R4      pMEVe    \        V,          pM2V	'       d   V'       g   \        RV : 24      hRp M%\        RV : 24      hVP                  V4       EK  	  V'       g-   V'       d   \        RV : 24      hVP                  WR 4       RpR	P                  V4      V3#   \         d   p\        RT: RT : 24      ThRp?ii ; i  \         d	    RT 2p Li ; i  \         d   p\        RT: RT : 24      ThRp?ii ; i)a  Common code for unescaping strings escaped by GDB in MI mode.

MI-mode escapes are similar to standard Python escapes but:
* "\e" is a valid escape.
* "\NNN" escapes use numbers represented in octal format.
  For instance, "\040" encodes character 0o40, that is character 32 in decimal,
  that is a space.

For details, see printchar in gdb/utils.c in the binutils-gdb repo.

Args:
    escaped_str: String to unescape
    expect_closing_quote: If true the closing quote must be in escaped_str[start:].
        Otherwise, no unescaped quote is allowed.
    start: the position in escaped_str at which to start unescaping the string.

Returns:
    A tuple containing the unescaped string and the index in escaped_str just after
    the escape string, or -1 if expect_closing_quote is False.
F)posbeforeescaped_octalescaped_charunescaped_quoteNr    )basezInvalid octal number z in zutf-8zInvalid escape character zUnescaped quote found in Tz+This code should not be reached for string zMissing closing quote in r   )_ESCAPES_REfinditerappendspan	bytearray_split_n_charsreplacer   
ValueErrordecodeUnicodeDecodeError_NON_OCTAL_ESCAPESKeyErrorAssertionErrorjoin)r   r   r   unmatched_start_indexfound_closing_quoteunescaped_partsmatchr1   r2   r3   _octal_sequence_bytesoctal_numberexcreplaceds   &$$            r   r   r   u   s   6 "  O%%k%=uX/o.^, 12#(::< $ $-;  .}/D/DT2/NPQ R(//Lq0IJ !S0/66w? %-l; ' #<[O!LMM #' !=k_M  	x(o >r 8HII 	{+ABC
 !#77?#%:::c " $//?tK?S & 0  /	0   //?tK?SsB   E)5FF&)F4FFF#"F#&G
1GG
c                R    V ^8  d   QhR\         R\        R\        \         ,          /# )r   sr%   r	   )r
   r   r   )r   s   "r   r   r      s%      c c hsm r   c              #  `   "   \        ^ \        V 4      V4       F  pWW!,            x  K  	  R# 5i)z/Iterates over string s `n` characters at a timeN)rangelen)rN   r%   is   && r   r;   r;      s(     1c!fa AEl !s   ,.)__doc__retypingr   r   __all__r   r   compileVERBOSEr6   r@   r   r;    r   r   <module>rZ      s    
 " +&S&'S* jj)T **W,b $ g;BCg;Tr   