
    &$              
       "   S r SSKrSSKrSSKrSSKrSSKr\R                  r\R                  r\R                  " S5      r	SSSSSS	S
SS.r
\" S5       H-  r\" \5      r\\
;  d  M  \\R                  ;  d  M%  S\-  \
\'   M/     \R                  " SR!                  \
R#                  5        V s/ s H  n \R%                  U 5      PM     sn 5      5      r\" S5      r\" S5      r " S S\5      rS rS rS rSrS rSS jrS rS r S r!gs  sn f )z*Some common string manipulation utilities.    Nz[^\000-\177]z\bz\tz\nz\fz\rz\"z\'z\\)	
"'\   z\%03o|)truet1yesy)falsef0nonc                       \ rS rSrSrSrg)Base64ValueError1   zIllegal Base64-encoded value N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       ,platform/bq/third_party/pyglib/stringutil.pyr   r   1   s    #Ar!   r   c                 0    [         R                  S U 5      $ )a  Replaces each non-ASCII character in s with an escape sequence.

Non-ASCII characters are substituted with their 6-character unicode
escape sequence \uxxxx, where xxxx is a hex number.  The resulting
string consists entirely of ASCII characters.  Existing escape
sequences are unaffected, i.e., this operation is idempotent.

Sample usage:
  >>> UnicodeEscape('asdf\xff')
  'asdf\\u00ff'

This escaping differs from the built-in s.encode('unicode_escape').  The
built-in escape function uses hex escape sequences (e.g., '\xe9') and escapes
some control characters in lower ASCII (e.g., '\x00').

Args:
  s: string to be escaped

Returns:
  escaped string
c                 <    S[        U R                  S5      5      -  $ )Nz\u%04xr   )ordgroupms    r"   <lambda>UnicodeEscape.<locals>.<lambda>J   s    IAGGAJ$?r!   )_RE_NONASCIIsub)ss    r"   UnicodeEscaper.   4   s    , 
		?	CCr!   c                 F    [         R                  S U 5      n[        U5      $ )a  Escapes a string so it can be inserted in a Java string or char literal.

Follows the Java Language Specification for "Escape Sequences for Character
and String Literals":

https://docs.oracle.com/javase/tutorial/java/data/characters.html

Escapes unprintable and non-ASCII characters.  The resulting string consists
entirely of ASCII characters.

This operation is NOT idempotent.

Sample usage:
  >>> JavaEscape('single\'double"\n\x00')
  'single\\\'double\\"\\n\\000'

Args:
  s: string to be escaped

Returns:
  escaped string
c                 2    [         U R                  S5         $ )Nr   )_JAVA_ESCAPE_MAPr&   r'   s    r"   r)   JavaEscape.<locals>.<lambda>d   s    (8(Dr!   )_JAVA_ESCAPE_REr,   r.   )r-   s_escs     r"   
JavaEscaper5   M   s$    . 

Da
H%
 
u	r!   c                 b    [         R                  " U 5      nU(       d  UR                  S5      nU$ )a  Python implementation of the Google C library's WebSafeBase64Escape().

Python implementation of the Google C library's WebSafeBase64Escape() (from
strings/strutil.h), using Python's base64 API and string replacement.

Args:
  unescaped: any data (byte) string (example: b"12345~6")
  do_padding: whether to add =-padding (example: false)

Returns:
  The base64 encoding (with web-safe replacements) of unescaped,
  with =-padding depending on the value of do_padding
  (example: b"MTIzNDV-Ng")
   =)base64urlsafe_b64encoderstrip)	unescaped
do_paddingescapeds      r"   WebSafeBase64Escaper>   t   s*     $$Y/'	nnT"G	.r!   s   !!!!!!!!!     !!!!!!!!!!!!!!!!!! !!!!!!!!!!!!+!!0123456789!!!=!!!ABCDEFGHIJKLMNOPQRSTUVWXYZ!!!!/!abcdefghijklmnopqrstuvwxyz!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!c                 T   U R                  [        5      nUR                  S5      S:  a  [        SU -  5      eUR	                  S5      (       d  [        U5      S-  nUSU-  -  n [        R                  " U5      $ ! [        R                   a  n[        U < SU< 35      eSnAff = f)a  Python implementation of the Google C library's WebSafeBase64Unescape().

Python implementation of the Google C library's WebSafeBase64Unescape() (from
strings/strutil.h), using Python's base64 API and string replacement.

Args:
  escaped: A base64 binary string using the web-safe encoding
      (example: b"MTIzNDV-Ng")

Returns:
  The corresponding unescaped string (example: b"12345~6")

Raises:
  Base64ValueError: Invalid character in encoding of string, escaped.
   !r   z(%r: Invalid character in encoded string.r7      z: N)		translate_BASE64_DECODE_TRANSLATIONfindr   endswithlenbinascii
a2b_base64Error)r=   escaped_standardpadding_lenmsgs       r"   WebSafeBase64UnescaperM      s      &&'AB4 A%
EO
PP 
	"	"4	(	(&'!+K{**6/00	 6
w4
556s   &A< <B'B""B'c                    ^ ^ US:  a  [        S5      eTS::  a  [        S5      eUU 4S j[        U[        T 5      T5       5       $ )aZ  Break a string into chunks of a given size.

Args:
  value: The value to split.
  size: The maximum size of a chunk.
  start: The index at which to start (defaults to 0).

Returns:
  Iterable over string slices of as close to the given size as possible.
  Chunk('hello', 2) => 'he', 'll', 'o'

Raises:
  ValueError: If start < 0 or if size <= 0.
r   zinvalid starting positioninvalid chunk sizec              3   2   >#    U  H  nTXT-    v   M     g 7f)Nr   ).0isizevalues     r"   	<genexpr>Chunk.<locals>.<genexpr>   s     	D%C%d(
%Cs   )
ValueErrorrangerF   )rT   rS   starts   `` r"   ChunkrZ      sC     QY
0
11	QY
)
**	DU5#e*d%C	DDr!   c                 D   ^ ^ TS::  a  [        S5      eUU 4S jnU" 5       $ )ap  Break a string into chunks of a given size, starting at the rear.

Like chunk, except the smallest chunk comes at the beginning.

Args:
  value: The value to split.
  size: The maximum size of a chunk.

Returns:
  Iterable over string slices of as close to the given size as possible.
  ReverseChunk('hello', 2) => 'h', 'el', 'lo'

Raises:
  ValueError: If size <= 0.
r   rO   c               3      >#    Sn [        T5      T-  (       a!  TS[        T5      T-   v   [        T5      T-  n [        TTU S9 H  nUv   M	     g7f)zActually perform the chunking.r   N)rY   )rF   rZ   )rY   chunkrS   rT   s     r"   DoChunkReverseChunk.<locals>.DoChunk   sV     E 5zD$3u:$%%%j4eud%0k 1s   AA)rW   )rT   rS   r^   s   `` r"   ReverseChunkr`      s'    $ 
QY
)
**	 
r!   c                     U c  g[        U [        5      (       d  [        S[        U 5      -  5      eU (       a%  U R	                  5       R                  5       [        ;   $ g)a  Checks if the string is a commonly accepted True value.

Useful if you want most strings to default to False except a few
accepted values.  This method is case-insensitive.

Args:
  value: The string to check for true.  Or None.

Returns:
  True if the string is one of the commonly accepted true values.
  False if value is None.  False otherwise.

Raises:
  ValueError: when value is something besides a string or None.
Fz5IsCommonTrue() called with %s type.  Expected string.)
isinstancestrrW   typestriplower_COMMON_TRUE_STRINGSrT   s    r"   IsCommonTrueri      sV      ]	E3		
LE{# $ $
;;= $888	r!   c                     U c  g[        U [        5      (       d  [        S[        U 5      -  5      eU (       a%  U R	                  5       R                  5       [        ;   $ g)a  Checks if the string is a commonly accepted False value.

Useful if you want most strings to default to True except a few
accepted values.  This method is case-insensitive.

Args:
  value: The string to check for true.  Or None.

Returns:
  True if the string is one of the commonly accepted false values.
  True if value is None.  False otherwise.

Raises:
  ValueError: when value is something besides a string or None.
Tz6IsCommonFalse() called with %s type.  Expected string.)rb   rc   rW   rd   re   rf   _COMMON_FALSE_STRINGSrh   s    r"   IsCommonFalserl     sV      ]	E3		
ME{# $ $
;;= $999	r!   )r   )"r   r8   rG   restringsix
ensure_strensure_binarycompiler+   r1   rX   rR   chrc	printablejoinkeysescaper3   	frozensetrg   rk   	Exceptionr   r.   r5   r>   rC   rM   rZ   r`   ri   rl   )rt   s   0r"   <module>r{      s?   1   	  
 ^^
!!zz/*
 



		
	   
sA	!f!1F,<,<#<"Q,Q 

 **SXX+00232aRYYq\235 6 !!?@ !"@A  By AD2N:( 6BE,D4G 4s   .D