o
    ŠÄŽié  ã                   @   sp   d Z ddlmZmZ ddlZdZdZdZdd„ Zd	d
„ Z	dd„ Z
deeef fdd„Zdeeef fdd„ZdS )z³These decorators provide function metadata to Python Fire.

SetParseFn and SetParseFns allow you to set the functions Fire uses for parsing
command line arguments to client code.
é    )ÚAnyÚDictNÚFIRE_METADATAÚFIRE_PARSE_FNSÚACCEPTS_POSITIONAL_ARGSc                    ó   ‡ ‡fdd„}|S )al  Sets the fn for Fire to use to parse args when calling the decorated fn.

  Args:
    fn: The function to be used for parsing arguments.
    *arguments: The arguments for which to use the parse fn. If none are listed,
      then this will set the default parse function.
  Returns:
    The decorated function, which now has metadata telling Fire how to perform.
  c                    s<   t | ƒ}ˆ sˆ|d< nˆ D ]}ˆ|d |< qt| t|ƒ | S )NÚdefaultÚnamed)ÚGetParseFnsÚ_SetMetadatar   )ÚfuncÚ	parse_fnsÚargument©Ú	argumentsÚfn© úK/home/jeff/fluffinator/venv/lib/python3.10/site-packages/fire/decorators.pyÚ
_Decorator'   s   
zSetParseFn.<locals>._Decoratorr   )r   r   r   r   r   r   Ú
SetParseFn   s   

r   c                     r   )a›  Set the fns for Fire to use to parse args when calling the decorated fn.

  Returns a decorator, which when applied to a function adds metadata to the
  function telling Fire how to turn string command line arguments into proper
  Python arguments with which to call the function.

  A parse function should accept a single string argument and return a value to
  be used in its place when calling the decorated function.

  Args:
    *positional: The functions to be used for parsing positional arguments.
    **named: The functions to be used for parsing named arguments.
  Returns:
    The decorated function, which now has metadata telling Fire how to perform.
  c                    s.   t | ƒ}ˆ|d< |d  ˆ ¡ t| t|ƒ | S )NÚ
positionalr	   )r
   Úupdater   r   )r   r   ©r	   r   r   r   r   D   s
   zSetParseFns.<locals>._Decoratorr   )r   r	   r   r   r   r   ÚSetParseFns4   s   r   c                 C   s    t | ƒ}|||< t| t|ƒ d S )N)ÚGetMetadataÚsetattrr   )r   Ú	attributeÚvalueÚmetadatar   r   r   r   N   s   r   Úreturnc                 C   s>   t t | ¡i}zt| t|ƒ}t |v r|W S |W S    | Y S )zÐGets metadata attached to the function `fn` as an attribute.

  Args:
    fn: The function from which to retrieve the function metadata.
  Returns:
    A dictionary mapping property strings to their value.
  )r   ÚinspectÚ	isroutineÚgetattrr   )r   r   r   r   r   r   r   T   s   
ÿr   c                 C   s    t | ƒ}d g i dœ}| t|¡S )N)r   r   r	   )r   Úgetr   )r   r   r   r   r   r   r
   k   s   r
   )Ú__doc__Útypingr   r   r    r   r   r   r   r   r   Ústrr   r
   r   r   r   r   Ú<module>   s   