
    |ha              
          d Z ddlZddlZddlZddlZ G d d ej
                  dd            Zd eej                        z  ej                  _
         G d d ej
                  dd	            Zd eej                        z  ej                  _
         G d
 de      Zd eej                        z  ej                  _
         G d de      Z G d dej                        Z G d dej                        Zej$                  dej&                  dej(                  dej*                  dej,                  diZd Zd Zd Zd Zd0dZd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0y)1aK  Docstring parsing module for Python Fire.

The following features of docstrings are not supported.
TODO(dbieber): Support these features.
- numpy docstrings may begin with the function signature.
- whitespace may be important for proper structuring of a docstring
- I've seen `argname` (with single backticks) as a style of documenting
  arguments. The `argname` appears on one line, and the description on the next.
- .. Sphinx directives such as .. note:: are not understood.
- After a section ends, future contents may be included in the section. E.g.
  :returns: This is what is returned.
  Example: An example goes here.
- @param is sometimes used.  E.g.
  @param argname (type) Description
  @return (type) Description
- The true signature of a function is not used by the docstring parser. It could
  be useful for determining whether something is a section header or an argument
  for example.
- This example confuses types as part of the docstrings.
  Parameters
  argname : argtype
  Arg description
- If there's no blank line after the summary, the description will be slurped
  up into the summary.
- "Examples" should be its own section type. aka "Usage".
- "Notes" should be a section type.
- Some people put parenthesis around their types in RST format, e.g.
  :param (type) paramname:
- :rtype: directive (return type)
- Also ":rtype str" with no closing ":" has come up.
- Return types are not supported.
- "# Returns" as a section title style
- ":raises ExceptionType: Description" ignores the ExceptionType currently.
- "Defaults to X" occurs sometimes.
- "True | False" indicates bool type.
    Nc                       e Zd Zy)DocstringInfoN__name__
__module____qualname__     N/var/www/html/test/engine/venv/lib/python3.12/site-packages/fire/docstrings.pyr   r   :        r
   r   )summarydescriptionargsreturnsyieldsraisesNc                       e Zd Zy)ArgInfoNr   r	   r
   r   r   r   B   r   r
   r   nametyper   c                       e Zd Zy)	KwargInfoNr   r	   r
   r   r   r   J   s    r
   r   c                   "    e Zd ZdZd Zd Zd Zy)	Namespacez4A dict with attribute (dot-notation) access enabled.c                 .    || vrt               | |<   | |   S r   )r   selfkeys     r   __getattr__zNamespace.__getattr__R   s    
$+d3i9r
   c                     || |<   y r   r	   )r   r    values      r   __setattr__zNamespace.__setattr__W   s    DIr
   c                     || v r| |= y y r   r	   r   s     r   __delattr__zNamespace.__delattr__Z   s    
d{
s) r
   N)r   r   r   __doc__r!   r$   r&   r	   r
   r   r   r   O   s    <
r
   r   c                        e Zd ZdZdZdZdZdZy)Sectionsr               N)r   r   r   ARGSRETURNSYIELDSRAISESTYPEr	   r
   r   r)   r)   _   s    	
$'&&	
$r
   r)   c                       e Zd ZdZdZdZy)Formatsr   r*   r+   N)r   r   r   GOOGLENUMPYRSTr	   r
   r   r4   r4   g   s    &
%	#r
   r4   )argumentarg	parameterparamr    )return)yield)raiseexcept	exceptionthrowerrorwarn)r   c                    | 
t               S | j                         j                  d      }t        |      }t	               }d|j
                  _        d|j
                  _        d|j
                  _        d|j
                  _	        d|j                  _        g |j                  _        g |j                  _        g |_        g |_        d|_        g |j"                  _        g |j$                  _        g |j&                  _        t)        |      D ]A  \  }}|dz   |k  }|dkD  r||dz
     nd}|r||dz      nd}t+        |||      }	t-        |	|       C |j                  j                  r%dj/                  |j                  j                        nd}
t1        |j                  j                        |j                  _        t3        j4                  dj/                  |j                  j                              }|sd}t7        |j"                  j                        }t7        |j$                  j                        }t7        |j&                  j                        }|j                  D cg c]]  }t9        |j:                  t=        t7        |j>                  j                              t7        |j                  j                              _ }}|jA                  |j                  D cg c]]  }tC        |j:                  t=        t7        |j>                  j                              t7        |j                  j                              _ c}       t        |
||xs d|||      S c c}w c c}w )	a	  Returns DocstringInfo about the given docstring.

  This parser aims to parse Google, numpy, and rst formatted docstrings. These
  are the three most common docstring styles at the time of this writing.

  This parser aims to be permissive, working even when the docstring deviates
  from the strict recommendations of these styles.

  This parser does not aim to fully extract all structured information from a
  docstring, since there are simply too many ways to structure information in a
  docstring. Sometimes content will remain as unstructured text and simply gets
  included in the description.

  The Google docstring style guide is available at:
  https://github.com/google/styleguide/blob/gh-pages/pyguide.md

  The numpy docstring style guide is available at:
  https://numpydoc.readthedocs.io/en/latest/format.html

  Information about the rST docstring format is available at:
  https://www.python.org/dev/peps/pep-0287/
  The full set of directives such as param and type for rST docstrings are at:
  http://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html

  Note: This function does not claim to handle all docstrings well. A list of
  limitations is available at the top of the file. It does aim to run without
  crashing in O(n) time on all strings on length n. If you find a string that
  causes this to crash or run unacceptably slowly, please consider submitting
  a pull request.

  Args:
    docstring: The docstring to parse.

  Returns:
    A DocstringInfo containing information about the docstring.
  N
Tr*   r    r   )r   r   r   r   r   r   )"r   stripsplitlenr   sectiontitleindentationline1_indentationformatr   	permittedlinesr   r   kwargscurrent_argr   r   r   	enumerate_create_line_info_consume_linejoin_strip_blank_linestextwrapdedent_join_linesr   r   _cast_to_known_typer   extendr   )	docstringrP   	lines_lenstateindexlinehas_nextprevious_line	next_line	line_infor   r   r   r   r   r9   r   s                    r   parserf   v   s   J ?
//

!
!$
'%%j)
+% %--"%--$(%--!%-- %--%--%%*%,%%--%,,%,,u% $keTqy9$H(-	E%!)$tM$,eai $I!$	=AI)U#$ .3]]-@-@CHHU]](()d'.u/@/@/F/FG%		%*;*;*A*A BC+	K++,'u||))*&u||))*& BG
M:= 88-k#((...IJcoo3346 
M$ 
M ++AFO:= 88-k#((...IJcoo3346 O P 
<4
 
MOs   !A"MA"M!c                     d}t        |       }| r.||k  r)t        | |         r|dz  }| r||k  rt        | |         r| |d } | r/t        | d         r!| j                          | rt        | d         r!| S )zRemoves lines containing only blank characters before and after the text.

  Args:
    lines: A list of lines.
  Returns:
    A list of lines without trailing or leading blank lines.
  r   r*   N)rI   	_is_blankpop)rP   start	num_liness      r   rW   rW      s     %%j)%)#	%,(?	QJE 	%)#	%,(? -% 	)E"I&	IIK 	)E"I& 
,r
   c                 ,    |  xs | j                         S r   )isspacera   s    r   ri   ri      s    	#T\\^#r
   c                 &   | syd}g }g }| D ]O  }|j                         }|rd}|j                  |       )|s,dj                  |      }|j                  |       g }Q |r"dj                  |      }|j                  |       dj                  |      S )a  Joins lines with the appropriate connective whitespace.

  This puts a single space between consecutive lines, unless there's a blank
  line, in which case a full blank line is included.

  Args:
    lines: A list of lines to join.
  Returns:
    A string, the lines joined together.
  NFTrF   z

)rG   appendrV   )rP   startedgroup_textsgroup_linesra   stripped_line
group_texts          r   rZ   rZ      s     
'++ 	dJJLMg'	XXk*
:&	 +&Jz"	[	!!r
   c                 B   | j                   | j                  z   D ]  }|j                  |k(  s|c S  t               }||_        g |j                  _        g |j                  _        |r| j                  j                  |       |S | j                   j                  |       |S )a  Gets or creates a new Arg.

  These Arg objects (Namespaces) are turned into the ArgInfo namedtuples
  returned by parse. Each Arg object is used to collect the name, type, and
  description of a single argument to the docstring's function.

  Args:
    state: The state of the parser.
    name: The name of the arg to create.
    is_kwarg: A boolean representing whether the argument is a keyword arg.
  Returns:
    The new Arg.
  )r   rQ   r   r   r   rP   r   rq   )r_   r   is_kwargr9   s       r   _get_or_create_arg_by_namery     s     ZZ%,,& c
xx4j 	##(#((.#//	LL 
* 
JJc	*r
   c                     | j                         } d}t        j                  ||        t        j                  ||       duS )an  Returns whether name is a valid arg name.

  This is used to prevent multiple words (plaintext) from being misinterpreted
  as an argument name. Any line that doesn't match the pattern for a valid
  argument is treated as not being an argument.

  Args:
    name: The name of the potential arg.
  Returns:
    True if name looks like an arg name, False otherwise.
  z^[a-zA-Z_]\w*$N)rG   rematch)r   arg_patterns     r   _is_arg_namer~   .  s:     
$ "+((;	+t	$D	00r
   c                     | j                         }t        |      dk  ryt        |d         r;dj                  |dd       }|j	                  d      j                  d      }|d   |fS y)a=  Returns text as a name and type, if text looks like an arg name and type.

  Example:
    _as_arg_name_and_type("foo (int)") == "foo", "int"

  Args:
    text: The text, which may or may not be an arg name and type.
  Returns:
    The arg name and type, if text looks like an arg name and type.
    None otherwise.
  r+   Nr   rF   r*   z{([z])})rH   rI   r~   rV   lstriprstrip)texttokens
type_tokens      r   _as_arg_name_and_typer   B  sj     ::<&[1_&)&*%J""5)007J!9j  r
   c                     t        j                  d|       }|D cg c]#  }|j                         s|j                         % }}|D ]  }t        |      r y |sy|S c c}w )a   Converts names_str to a list of arg names.

  Example:
    _as_arg_names("a, b, c") == ["a", "b", "c"]

  Args:
    names_str: A string with multiple space or comma separated arg names.
  Returns:
    A list of arg names, or None if names_str doesn't look like a list of arg
    names.
  z,| N)r{   rH   rG   r~   )	names_strnamesr   s      r   _as_arg_namesr   Y  sa     ((5)
$%$)
:DTZZ\4::<
:%
: d 
	, ;s
   AAc                 *    | y| j                  d      S )aG  Canonicalizes a string representing a type if possible.

  # TODO(dbieber): Support additional canonicalization, such as string/str, and
  # boolean/bool.

  Example:
    _cast_to_known_type("str.") == "str"

  Args:
    name: A string representing a type, or None.
  Returns:
    A canonicalized version of the type string.
  N.)r   )r   s    r   r[   r[   o  s     
\	S	r
   c                 :   | j                   j                  dd      }t        |      dkD  r1|\  }}t        |j	                               rUt        ||j	                               }|j                  j                  j                  |j	                                ||_	        yt        |      }|rq|\  }}t        ||      }|j                  j                  j                  |       |j                  j                  j                  |j	                                ||_	        y|j                  r3|j                  j                  j                  j                  |d          yy|j                  r3|j                  j                  j                  j                  |d          yy)z1Consume a single line from a Google args section.:r*   r   N)	remainingrH   rI   r~   rG   ry   r   rP   rq   rR   r   r   )	re   r_   
split_linefirstsecondr9   arg_name_and_typearg_nametype_strs	            r   _consume_google_args_liner     s;   ""((a0*_qME6EKKM"&uekkm<c	oo""6<<>2e/6	.((9h'$$V\\^4



'
'
-
-
4
4Z]
C  ##))00A? r
   c                    t        | |       |j                  j                  |j                  j                  rd| j
                  r0|j                  j                  j                  | j
                         ni|j                  j                  rSd|j                  _        nA|j                  j                  j                  | j                         nd|j                  _        |j                  j                  r|j                  j                  t        j                  k(  rt        |       }|j                         }|j                  j                  t         j"                  k(  rW|d   }t%        |||d   dk(        }t'        |      dk(  r(|j(                  j                  j                  |d          ||_        n?|j                  j                  t         j,                  k(  r|d   }t%        ||      }||_        |j                  j                  t        j.                  k(  rt1        | j
                        ry|j                  j                  t         j"                  k(  r|j                  j                  t        j2                  k(  rt5        | |       y|j                  j                  t        j                  k(  rH|j*                  j                  j                  j                  | j
                  j7                                y|j                  j                  t        j.                  k(  rP| j
                  j7                         }t9        |      rt%        ||      }||_        yt;        |       r|j                  d	d      \  }}t=        |      }	|	r@|	D ]:  }
t%        ||
      }|j(                  j                  j                  |       ||_        < y|j*                  rH|j*                  j                  j                  j                  | j
                  j7                                yy|j*                  rH|j*                  j                  j                  j                  | j
                  j7                                yyy|j                  j                  t         j>                  k(  r>|j@                  j                  j                  | j
                  j7                                y|j                  j                  t         jB                  k(  r>|jD                  j                  j                  | j
                  j7                                y|j                  j                  t         jF                  k(  r>|jH                  j                  j                  | j
                  j7                                y|j                  j                  t         j,                  k(  r~|j                  j                  t        j                  k(  rV|j*                  J |j*                  j(                  j                  j                  | j
                  j7                                yyy)
a-  Consumes one line of text, updating the state accordingly.

  When _consume_line is called, part of the line may already have been processed
  for header information.

  Args:
    line_info: Information about the current and next line of the docstring.
    state: The state of the docstring parser.
  NFrh   r   r    )rx   r,   r*   r   )%_update_section_staterJ   rK   r   rO   r   rP   rq   r   remaining_rawnewrN   r4   r7   _get_directiverH   r)   r.   ry   rI   r   rR   r2   r6   _line_is_hyphensr5   r   rG   r~   _line_is_numpy_parameter_typer   r/   r   r0   r   r1   r   )re   r_   	directivedirective_tokensr   r9   line_strippedpossible_args	type_data	arg_namesr   s              r   rU   rU     s}    	5)
]] }}			""9#6#67=="' $$Y%<%<=#EMM
]]5==//7;;>y)I (}}hmm+b!d&

#A&%/c
 
	!	#.q12e				-b!d&ud3cemmgmm+y**+

]]HMM)}}w~~-	51				,##))001D1D1J1J1LM				.))//1m	m	$ )>(3#0#6#6sA#> y!-0	# $h,UH=CHHNN!!), #E$
 ))//66##))+- 



'
'
-
-
4
4!!'')+ 9 
/< }}h...	MMy2288:;}}hoo-	LLi11779:}}hoo-	LLi11779:}}hmm+}}w{{****"")))*=*=*C*C*EF
 ,r
   c                 d   t               }| |_        | j                         |_        |j                  |_        |j                  |_        t        |       t        | j                               z
  |_        ||j                  _        |du}|r|j                         nd|j                  _        |r%t        |      t        |j                               z
  nd|j                  _        ||j                  _        |du}|r%t        |      t        |j                               z
  nd|j                  _        |S )zAReturns information about the current line and surrounding lines.N)r   ra   rG   strippedr   r   rI   r   rL   nextprevious)ra   rd   rc   re   next_line_existsprevious_line_existss         r   rT   rT     s   k)).zz|)%NN)!**)d)c$++-&88)!)..d*1AIOO-t)..2Bc)ns9++-.. ..))&d2 &: 
-	-


 !"?C   
r
   c                     d}t        | |      }|xr t        |       }|rSt        j                  |j                  _        ||j                  _        t        |       | _        | j                  | _	        d}t        |       }|rSt        j                  |j                  _        ||j                  _        t        |       | _        | j                  | _	        d}t        |       }|rJt        j                  |j                  _        ||j                  _        d| _        | j                  | _	        d}|rRd|j                  _        | j                   |j                  _        | j"                  j                   |j                  _        yd|j                  _        y)zUses line_info to determine the current section of the docstring.

  Updates state and line_info.remaining.

  Args:
    line_info: Information about the current line.
    state: The state of the parser.
  FT N)_google_section_permitted_google_sectionr4   r5   rJ   rN   rK   _get_after_google_headerr   r   _rst_sectionr7   _get_after_directive_numpy_sectionr6   r   rL   r   rM   )re   r_   section_updatedgoogle_section_permittedgoogle_sectionrst_sectionnumpy_sections          r   r   r     s4    /6y%H+J	0J.">>EMM(EMM29=I'11IOY'+";;EMM%EMM.y9I'11IO +-"==EMM'EMMI'11IOEMM ) 5 5EMM&/nn&@&@EMM#EMMr
   c                     |j                   j                  y| j                  |j                   j                  k  xs# | j                  |j                   j                  k  S )a	  Returns whether a new google section is permitted to start here.

  Q: Why might a new Google section not be allowed?
  A: If we're in the middle of a Google "Args" section, then lines that start
  "param:" will usually be a new arg, rather than a new section.
  We use whitespace to determine when the Args section has actually ended.

  A Google section ends when either:
  - A new google section begins at either
    - indentation less than indentation of line 1 of the previous section
    - or <= indentation of the previous section
  - Or the docstring terminates.

  Args:
    line_info: Information about the current line.
    state: The state of the parser.
  Returns:
    True or False, indicating whether a new Google section is permitted at the
    current line.
  T)rJ   rL   rM   )re   r_   s     r   r   r   A  sS    * ]]&


5==#<#<
< E""U]]%D%DDFr
   c                 T    | j                         } |j                         }|| | dd fv S )zReturns whether title is a match for a specific section_title.

  Example:
    _matches_section_title('Yields', 'yield') == True

  Args:
    title: The title to check for matching.
    section_title: A specific known section title to check against.
  Nrh   )lower)rK   section_titles     r   _matches_section_titler   \  s3     ++-%%%'-	5%*-	--r
   c                 <    t         |   D ]  }t        | |      s y y)a  Returns whether title is a match any known title for a specific section.

  Example:
    _matches_section_title('Yields', Sections.YIELDS) == True
    _matches_section_title('param', Sections.Args) == True

  Args:
    title: The title to check for matching.
    section: A specific section to check all possible titles for.
  Returns:
    True or False, indicating whether title is a match for the specified
    section.
  TF)SECTION_TITLESr   )rK   rJ   r   s      r   _matches_sectionr   k  s*     &g. me]3 
r
   c                 :    t         D ]  }t        | |      s|c S  y)zReturns a section matched by the possible title, or None if none match.

  Args:
    possible_title: A string that may be the title of a new section.
  Returns:
    A Section type if one matches, or None if no section type matches.
  N)r   r   )possible_titlerJ   s     r   _section_from_possible_titler     s'       g0n 
r
   c                 l    | j                   j                  d      }| j                   d| }t        |      S )ac  Checks whether the current line is the start of a new Google-style section.

  This docstring is a Google-style docstring. Google-style sections look like
  this:

    Section Name:
      section body goes here

  Args:
    line_info: Information about the current line.
  Returns:
    A Section type if one matches, or None if no section type matches.
  r   N)r   findr   )re   colon_indexr   s      r   r   r     s7     ##((-+&&|4.	%n	55r
   c                 \    | j                   j                  d      }| j                   |dz   d S )z6Gets the remainder of the line, after a Google header.r   r*   N)r   r   )re   r   s     r   r   r     s0    ##((-+			[1_-	..r
   c                 x    | j                   j                  d      r| j                   j                  dd      d   S y)aA  Gets a directive from the start of the line.

  If the line is ":param str foo: Description of foo", then
  _get_directive(line_info) returns "param str foo".

  Args:
    line_info: Information about the current line.
  Returns:
    The contents of a directive, or None if the line doesn't start with a
    directive.
  r   r+   r*   N)r   
startswithrH   )re   s    r   r   r     s9     ""3'##C+A..r
   c                 b    | j                   j                  dd      }t        |      dkD  r|d   S y)z2Gets the remainder of the line, after a directive.r   r+   rh   r   )r   rH   rI   )re   sectionss     r   r   r     s3    %%c1-(]QB<r
   c                 Z    t        |       }|r|j                         d   }t        |      S y)ax  Checks whether the current line is the start of a new RST-style section.

  RST uses directives to specify information. An RST directive, which we refer
  to as a section here, are surrounded with colons. For example, :param name:.

  Args:
    line_info: Information about the current line.
  Returns:
    A Section type if one matches, or None if no section type matches.
  r   N)r   rH   r   )re   r   r   s      r   r   r     s0     Y')__&q)N'77r
   c                 .    | xr | j                  d       S )z=Returns whether the line is entirely hyphens (and not blank).-)rG   ro   s    r   r   r     s    		%djjo%%r
   c                 t    t        | j                  j                        }|r| j                  }t	        |      S y)ag  Checks whether the current line is the start of a new numpy-style section.

  Numpy style sections are followed by a full line of hyphens, for example:

    Section Name
    ------------
    Section body goes here.

  Args:
    line_info: Information about the current line.
  Returns:
    A Section type if one matches, or None if no section type matches.
  N)r   r   r   r   r   )re   next_line_is_hyphensr   s      r   r   r     s5     *)..*A*AB((N'77r
   c                     | j                   j                         }d|v rA| j                  j                  }| j                  }d| j                  j                  v r||kD  ryyy)a  Returns whether the line contains a numpy style parameter type definition.

  We look for a line of the form:
  x : type

  And we have to exclude false positives on argument descriptions containing a
  colon by checking the indentation of the line above.

  Args:
    line_info: Information about the current line.
  Returns:
    True if the line is a numpy parameter type definition, False otherwise.
  r   FT)r   rG   r   rL   ra   )re   r   previous_indentcurrent_indents       r   r   r     s`     %%++--M((44O**N
i  %%%.?*J	r
   )F)1r'   collectionsenumr{   rX   
namedtupler   rI   _fields__new____defaults__r   r   dictr   Enumr)   r4   r.   r/   r0   r1   r2   r   rf   rW   ri   rZ   ry   r~   r   r   r[   r   rU   rT   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r
   r   <module>r      s  #J   	 KIK
 &-s=3H3H/I%I   "K')
  'W__)==  !(3y/@/@+A!A	     tyy 
dii 
 MMCkOOZOOOMM9Zz.$!"H81(.,&@2`F.)XF6.(6&/$&&
,r
   