
    Rpf7                        U d Z ddlZddlZddl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mZ ddlmZ 	 ddlZn# e$ r dZY nw xY w	 ddlZn# e$ r dZY nw xY wdZdZdZ ej        d          Z e eej        e                   g          Zee         e d	<   dZ!ee d
<   dZ"ej#        e d<    G d de          Z$de	e%ef         de$fdZ&de$fdZ'de%fdZ(dej)        de%dedej*        fdZ+defdZ,dee%         dee%         dee%         fdZ-d Z.	 	 	 d(de%dee         de%d ee%         de%f
d!Z/	 d)d"e	e%ef         d#eee%                  de
e%         fd$Z0d%e%de%fd&Z1de%de%fd'Z2dS )*z:Internal helper functions for Abseil Python flags library.    N)AnyDictIterableList
NamedTupleOptionalSequenceSet)minidomP   (   g      ?u    [ -----￾￿]disclaim_module_idsSPECIAL_FLAGSFLAGS_MODULEc                   2    e Zd ZU dZej        ed<   eed<   dS )_ModuleObjectAndNamezkModule object and name.

  Fields:
  - module: object, module object.
  - module_name: str, module name.
  modulemodule_nameN)__name__
__module____qualname____doc__types
ModuleType__annotations__str     S/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/absl/flags/_helpers.pyr   r   P   s9           
r   r   globals_dictreturnc                     |                      dd          }t          j                             |d          }t          ||dk    rt          j        d         n|          S )aN  Returns the module that defines a global environment, and its name.

  Args:
    globals_dict: A dictionary that should correspond to an environment
      providing the values of the globals.

  Returns:
    _ModuleObjectAndName - pair of module object & module name.
    Returns (None, None) if the module could not be identified.
  r   N__main__r   )getsysmodulesr   argv)r    namer   s      r   get_module_object_and_namer)   [   s\     
		*d	+	+$;??4&&&	f.2j.@.@sx{{d
M 
M Mr   c                     t          dt          j                              D ]W} t          j        |           j        }t          |          \  }}t          |          t          vr|t          ||          c S Xt          d          )a)  Returns the module that's calling into this module.

  We generally use this function to get the name of the module calling a
  DEFINE_foo... function.

  Returns:
    The module object that called into this one.

  Raises:
    AssertionError: Raised when no calling module could be identified.
     NzNo module was found)
ranger%   getrecursionlimit	_getframe	f_globalsr)   idr   r   AssertionError)depthglobals_for_framer   r   s       r   "get_calling_module_object_and_namer4   o   s     Q-//00 7 7e e,,645FGGFK	&zz,,,1H!&+66666,---r   c                  (    t                      j        S )z?Returns the name of the module that's calling into this module.)r4   r   r   r   r   get_calling_moduler6      s    	+	-	-	99r   docr(   valuec                 &   t          |          }t          |t                    r|                                }t                              d|          }|                     |          }|                    |                     |                     |S )a  Returns an XML DOM element with name and text value.

  Args:
    doc: minidom.Document, the DOM document it should create nodes from.
    name: str, the tag of XML element.
    value: object, whose string representation will be used
        as the value of the XML element. Illegal or highly discouraged xml 1.0
        characters are stripped.

  Returns:
    An instance of minidom.Element.
   )	r   
isinstanceboollower_ILLEGAL_XML_CHARS_REGEXsubcreateElementappendChildcreateTextNode)r7   r(   r8   ses        r   create_xml_dom_elementrE      s{     
%jj!t 			A""3**!	!--""1%%&&&	
(r   c                     t           j                                        rt          t          t
          S 	 t	          j        t           j        t          j        d          } t          j	        d|           d         }|t          k    r|S t          t          j        dt
                              S # t          t          t          j        f$ r
 t
          cY S w xY w)zAReturns the integer width of help lines that is used in TextWrap.Ns   1234hhr+   COLUMNS)r%   stdoutisattytermiosfcntl_DEFAULT_HELP_WIDTHioctl
TIOCGWINSZstructunpack_MIN_HELP_WIDTHintosgetenv	TypeErrorIOErrorerror)datacolumnss     r   get_help_widthr[      s    					 5=;sz7#5w??DmD$''*G /!!nry$788999
Wfl	+   s   AB. &B. .#CCattemptlongopt_listc                 .    t                     dk    s|sg S d |D             } fd|D             }|                                 |d         \  }}|t          t                     z  k    rg S g }|D ]!\  }}||k    r|                    |           ! |S )z4Returns helpful similar matches for an invalid flag.   c                 D    g | ]}|                     d           d         S )=r   )split).0vs     r   
<listcomp>z(get_flag_suggestions.<locals>.<listcomp>   s&    888a!''#,,q/888r   c           
      ^    g | ])}t          |d t                                       |f*S )r   )_damerau_levenshteinlen)rc   optionr\   s     r   re   z(get_flag_suggestions.<locals>.<listcomp>   sG     + + + %WfQs7||^.DEEvN + + +r   r   )rh   sort _SUGGESTION_ERROR_RATE_THRESHOLDappend)	r\   r]   option_names	distancesleast_errors_suggestionserrorsr(   s	   `        r   get_flag_suggestionsrs      s    
 	\\QlI88<888,+ + + +)+ + +) ..aL/,5GDDDI+  lfd	r   c                 .    i fd | |          S )z6Returns Damerau-Levenshtein edit distance from a to b.c           
      0   | |fv r
| |f         S | st          |          }n|st          |           }nt           | dd         |          dz    | |dd                   dz    | dd         |dd                   | d         |d         k    z             }t          |           dk    r^t          |          dk    rK| d         |d         k    r9| d         |d         k    r' | dd         |dd                   dz   }||k    r|}|| |f<   |S )z5Recursively defined string distance with memoization.r+   Nr   r_   )rh   min)xydtdistancememos       r   r{   z&_damerau_levenshtein.<locals>.distance   sD   	1v~~!Q$Z 
a&&aa 
a&&aa

(1QRR5!

q
 
(1ae

q
 
(1QRR5!ABB%
 
 AaDAaDL
13 3a 
Q1Q111!A$!A$,,HQqrrUAabbE""Q&q55!DAJHr   r   )abr{   r|   s     @@r   rg   rg      s9    	$     * 
!Qr   r:   textlengthindentfirstline_indentc                 4   |t                      }|d}||}t          |          |k    rt          d          t          |          |k    rt          d          |                     d          } g }t	          j        |||          }t	          j        |||          }d |                                 D             D ]D}|r)|                    |                    |                     n|	                    d           |}Ed
                    |          S )	aL  Wraps a given text to a maximum line length and returns it.

  It turns lines that only contain whitespace into empty lines, keeps new lines,
  and expands tabs using 4 spaces.

  Args:
    text: str, text to wrap.
    length: int, maximum length of a line, includes indentation.
        If this is None then use get_help_width()
    indent: str, indent for all but first line.
    firstline_indent: str, indent for first line; if None, fall back to indent.

  Returns:
    str, the wrapped text.

  Raises:
    ValueError: Raised if indent or firstline_indent not shorter than length.
  Nr:   zLength of indent exceeds lengthz*Length of first line indent exceeds length   )widthinitial_indentsubsequent_indentc              3   >   K   | ]}|                                 V  d S N)strip)rc   ps     r   	<genexpr>ztext_wrap.<locals>.<genexpr>%  s*      99!AGGII999999r   
)r[   rh   
ValueError
expandtabstextwrapTextWrapper
splitlinesextendwraprl   join)r   r   r   r   resultwrappersubsequent_wrapper	paragraphs           r   	text_wrapr      sF   2 ^F^F[[F
6
7
77	f$$
A
B
BB			$&  #3vO O O'+6VE E E :9t'8'8999 ! !i mmGLL++,,,,mmB GG	6		r   flag_mapmulti_flagsc              #     K   |                                  D ]\  }}|d|z  V  t          |t                    r|rd|z  V  .d|z  V  6t          |t          t	          d          f          rd|d|V  e	 |r!||v r|D ]}d|dt          |          V  n'd|dd                    d |D                       V  # t          $ r d|d|V  Y w xY wdS )	a3  Convert a dict of values into process call parameters.

  This method is used to convert a dictionary into a sequence of parameters
  for a binary that parses arguments using this module.

  Args:
    flag_map: dict, a mapping where the keys are flag names (strings).
        values are treated according to their type:

        * If value is ``None``, then only the name is emitted.
        * If value is ``True``, then only the name is emitted.
        * If value is ``False``, then only the name prepended with 'no' is
          emitted.
        * If value is a string then ``--name=value`` is emitted.
        * If value is a collection, this will emit
          ``--name=value1,value2,value3``, unless the flag name is in
          ``multi_flags``, in which case this will emit
          ``--name=value1 --name=value2 --name=value3``.
        * Everything else is converted to string an passed as such.

    multi_flags: set, names (strings) of flags that should be treated as
        multi-flags.
  Yields:
    sequence of string suitable for a subprocess execution.
  Nz--%sz--no%sr:   z--ra   ,c              3   4   K   | ]}t          |          V  d S r   )r   )rc   items     r   r   z$flag_dict_to_args.<locals>.<genexpr>^  s(      *G*G3t99*G*G*G*G*G*Gr   )itemsr;   r<   bytestyper   r   rV   )r   r   keyr8   r   s        r   flag_dict_to_argsr   0  s     8 NN$$ ' 'jc5}SL	E4	 	  '	 sln	EE499-	.	. ' 'ee$$$$$' 	I3+-- / /dd"ssCIII...../ !SS#((*G*G*G*G*G"G"G"GH
H
H
H ' ' ' '33&&&&&&''' 's   =A
CCC	docstringc                    | sdS d}|                                                                  }|}|dd         D ]E}|                                }|r-t          |t	          |          t	          |          z
            }F|d                                         g}||k     r<|dd         D ]1}|                    ||d                                                    2|r&|d         s|                                 |r|d         |r'|d         s|                    d           |r|d         d	                    |          S )a  Removes indentation from triple-quoted strings.

  This is the function specified in PEP 257 to handle docstrings:
  https://www.python.org/dev/peps/pep-0257/.

  Args:
    docstring: str, a python docstring.

  Returns:
    str, docstring with indentation removed.
  r:   i    r+   Nr   r   )
r   r   lstriprv   rh   r   rl   rstrippopr   )r   
max_indentlinesr   linestrippedtrimmeds          r   trim_docstringr   d  sl    
 2 * 


 
 
+
+
-
-% &ABBi 6 6d{{}}H 663t99s8}}455f1X^^'jabb	 - -nnT&'']))++,,,,  KKMMM 	   
 KKNNN 	 
  
7		r   c                     |                                  } t          j        dt          j                  }|                    d|           } t          |           } t          j        dd| t          j                  } | S )z0Takes a __doc__ string and reformats it as help.z^[ 	]+$r:   z(?<=\S)\n(?=\S) )flags)r   recompileMr?   r   )r7   whitespace_only_lines     r   doc_to_helpr     sm     			# J55  S))# 	s# 	!324888#	*r   )Nr:   Nr   )3r   rT   r   rP   r%   r   r   typingr   r   r   r   r   r   r	   r
   xml.domr   rL   ImportErrorrK   rM   rR   rk   r   r>   setr0   r&   r   r   rS   r   r   r   r   r   r   r)   r4   r6   DocumentElementrE   r[   rs   rg   r   r   r   r   r   r   r   <module>r      s   A @ @ 				 				  



   Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q      ,,,,   
%%%....   '''
    $(  
 &2:NP P  !$RRH(=%>%>$? @ @ SX @ @ @ s    "&e % % %    :   MsCx.MM M M M(.,@ . . . .,:C : : : :
		!$-0_   6    $c]*23-	#Y   >  < !&*	; ;
;SM; ; sm	;
 	; ; ; ;~ AE1' 1'38n1'+3CH+=1'c]1' 1' 1' 1'h'c 'c ' ' ' 'TS S      s!   < AA
A AA