U
    +cd                     @   sh   d Z ddlmZ ddlmZ ddlmZ ddlZdZdZdZd	d
 Z	dd Z
dd Zdd Zdd ZdS )zThese 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.
    )absolute_import)division)print_functionNFIRE_METADATAFIRE_PARSE_FNSACCEPTS_POSITIONAL_ARGSc                    s    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 3/tmp/pip-unpacked-wheel-1xt1w7un/fire/decorators.py
_Decorator*   s    
zSetParseFn.<locals>._Decoratorr   )r   r   r   r   r   r   
SetParseFn    s    

r   c                     s    fdd}|S )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   G   s
    zSetParseFns.<locals>._Decoratorr   )r   r	   r   r   r   r   SetParseFns7   s    r   c                 C   s    t | }|||< t| t| d S )N)GetMetadatasetattrr   )r   	attributevaluemetadatar   r   r   r   Q   s    r   c                 C   sH   t t| i}z$t| t|}t |kr*|W S |W S W n   | Y S X dS )zGets 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.
  N)r   inspect	isroutinegetattrr   )r   r   r   r   r   r   r   W   s     
r   c                 C   s"   t | }td g i d}|t|S )N)r   r   r	   )r   dictgetr   )r   r   r   r   r   r   r
   o   s    r
   )__doc__
__future__r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   <module>   s   