o
    wi=                     @   sR  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Zd dlmZmZ d dl	m	Z
 ejdd Zejdkr=d dlmZ nG dd deZd	d
 Zdd Zdd Zdd Zdd Zd-ddZd.ddZd/ddZdd ZG dd deZe Zeejjjdd Zdd Zi Zd d! Z d"d# Z!d0d%d&Z"G d'd( d(ejZd)d* Z#d1d+d,Z$dS )2    N)datetimedate)gettext   3)getfullargspecc                   @   s   e Zd ZdZdd ZdS )r   z?A quick and dirty replacement for getfullargspec for Python 2.Xc                 C   s,   t |\| _| _| _| _t|di | _d S )N__annotations__)inspect
getargspecargsvarargsvarkwdefaultsgetattrannotations)selff r   F/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/plac_core.py__init__   s   zgetfullargspec.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r      s    r   c                 C      t t| ddd  S )zReturns year-month-dayz%Y-%m-%dr      )r   timestrptimesr   r   r   to_date      r    c                 C   r   )z)Returns year-month-day hour-minute-secondz%Y-%m-%d %H-%M-%Sr      )r   r   r   r   r   r   r   to_datetime   r!   r#   c                 C   s   t | rt| }|S t | rt| }|jd= |S t | r7| jtju r,tdd }nt| j}|jd= |S t| drGt| j	}|jd= |S t
tdt|  )zGiven a callable return an object with attributes .args, .varargs,
    .varkw, .defaults. It tries to do the "right thing" with functions,
    methods, classes and generic callables.r   c                 S   s   d S Nr   r   r   r   r   <lambda>.   s    zgetargspec.<locals>.<lambda>__call__z%Could not determine the signature of )r	   
isfunctionr   ismethodr   isclassr   objecthasattrr'   	TypeError_str)callableobjargspecr   r   r   r
   #   s(   





r
   c                     s    fdd}|S )z
    Returns a decorator annotating a function with the given annotations.
    This is a trick to support function annotations in Python 2.X.
    c                    s^   t | }|j}|jr||j |jr||j  D ]}||vr)ttd| q | _| S )Nz$Annotating non-existing argument: %s)r   r   r   appendr   	NameErrorr.   r   )r   fasr   argnameannr   r   annotate@   s   
zannotations.<locals>.annotater   )r7   r8   r   r6   r   r   ;   s   r   c                 C   s0   z||j | < W |S  ty   | |i|_ Y |S w r$   )r   AttributeError)argr7   r   r   r   r   	_annotateP   s   r;   c              
   C   s   t t| |dd|||fS )z7
    Decorator for annotating positional arguments
    
positionalN	functoolspartialr;   )r:   helptypechoicesmetavarr   r   r   posX   s   rD   c              
   C   s&   |p| d }t t| |d||||fS )z5
    Decorator for annotating optional arguments
    r   optionr=   )r:   r@   rA   abbrevrB   rC   r   r   r   opt`   s   rG   c              
   C   s"   t t| |d|p| d dddfS )z(
    Decorator for annotating flags
    flagr   Nr=   )r:   r@   rF   r   r   r   flgi   s   rI   c                 C   s<   t | dot | dot | dot | dot | dot | dS )zt
    An object is an annotation object if it has the attributes
    help, kind, abbrev, type, choices, metavar.
    r@   kindrF   rA   rB   rC   )r,   objr   r   r   is_annotationq   s   rM   c                   @   s*   e Zd Z		dddZdd ZeeZdS )
AnnotationNr<   c                 C   sP   |dv sJ ||dkr|d u sJ ||| _ || _|| _|| _|| _|| _d S )N)r<   rE   rH   r<   )r@   rJ   rF   rA   rB   rC   )r   r@   rJ   rF   rA   rB   rC   r   r   r   r   |   s   
zAnnotation.__init__c                 C   s>   t |r|S t|rt|}| |S t|r| | S | |S )z9Helper to convert an object into an annotation, if needed)rM   r	   r*   r/   iterable)clsrL   r   r   r   from_   s   
zAnnotation.from_)Nr<   NNNN)r   r   r   r   rQ   classmethodr   r   r   r   rN   {   s    
	rN      c                 C   sL   t | jrt| j ndtjd}t| D ]}|tv r#t	| |||< q|S )zN
    Extracts the configuration of the underlying ArgumentParser from obj
    N)descriptionformatter_class)
dictr   textwrapdedentrstripargparseRawDescriptionHelpFormatterdir
PARSER_CFGr   )rL   cfgnamer   r   r   pconf   s   r`   c                 K   s   zt |  W S  ty   Y nw t|  }|| tdi | t | < }| |_|dt| dd|_	t
| drGt| sG|| j| d |S ||  |S )zg
    obj can be a callable or an object with a .commands attribute.
    Returns an ArgumentParser.
    case_sensitiveTcommandssubcommandsNr   )_parser_registryKeyErrorr`   copyupdateArgumentParserrL   getr   ra   r,   r	   r*   addsubcommandsrb   populate_from)rL   
confparamsconfparserr   r   r   parser_from   s"   


ro   c                 C   sX   g }i }| D ]!}t d|}|r"|d}|t|d d ||< q|| q||fS )z=
    Returns two lists: regular args and name=value args
    z([a-zA-Z_]\w*)=rS   N)rematchgrouplenr2   )r   arglistkwargsr:   rq   r_   r   r   r   _extract_kwargs   s   
rv   Tc                    s   |s    dd |D } fdd|D }t|dkr |d S  fdd|D }t|}|dkr5|d S |dkrCttd |f dS )	zL
    Extract the command name from an abbreviation or raise a NameError
    c                 S   s   g | ]}|  qS r   )upper).0cr   r   r   
<listcomp>   s    z_match_cmd.<locals>.<listcomp>c                    s   g | ]}| kr|qS r   r   rx   r_   rF   r   r   rz      s    rS   r   c                    s   g | ]	}|  r|qS r   )
startswithr{   r|   r   r   rz      s    z!Ambiguous command %r: matching %sN)rw   rs   r3   r.   )rF   rb   ra   perfect_matchesmatchesnr   r|   r   
_match_cmd   s   r   c                       sn   e Zd ZdZdZedk r fddZdd Zdd	 Zd
d Z	dddZ
dd Zdd Zdd Zdd Z  ZS )rh   zk
    An ArgumentParser with .func and .argspec attributes, and possibly
    .commands and .subparsers.
    T)r   
   c                    sB   t t| j|i | | jd jtdkrtd| jd _d S d S )NrS   zoptional argumentsoptions)superrh   r   _action_groupstitler.   )r   r   ru   	__class__r   r   r      s   zArgumentParser.__init__c                 C   s   |S )z6Can be overridden to preprocess command-line argumentsr   )r   r:   r   r   r   alias   s   zArgumentParser.aliasc                    s  fdd|D }d}t dr,|\}}|du r&|dur&||fS |dur,|t dr=jjr=|\ }n|g  }t dsLtt drjjrjj}jj}| j	v rt j	
|}t|\}}	| j	|< n| j	v r j	
|}t|\}}	| j	|< |r|std|  ni }	tjjt|	@ }
|
rtdd|
   fd	djjD }t jjpd
g }|j|| | i |	fS )z
        Call the underlying function with the args. Works also for
        command containers, by dispatching to the right subparser.
        c                    s   g | ]}  |qS r   )r   rx   ar%   r   r   rz      s    z*ArgumentParser.consume.<locals>.<listcomp>N
subparsersr1   zUnrecognized arguments: %szcolliding keyword arguments: %s c                    s   g | ]
}t  |d qS )r.   )r   rY   r   )nsr   r   rz     s     )r,   _extract_subparser_cmdmissingr1   r   parse_known_args
parse_args
SystemExitr   __dict__poprv   errorr.   setr   joinr   func)r   r   rt   cmdsubp	extraoptsvr   lstru   	collisionr   r   )r   r   r   consume   sH   




zArgumentParser.consumec                 C   s\   | j d }| jj}t|D ]\}}||s+t||| j}||= |||p'|f  S qdS )zP
        Extract the right subparser from the first recognized argument
        r   NN)prefix_charsr   _name_parser_map	enumerater}   r   ra   ri   )r   rt   	optprefixname_parser_mapir:   r   r   r   r   r   !  s   

z%ArgumentParser._extract_subparser_cmdNr   c           
      C   s   t ||r|j| jv rttd| t | ds | j|d| _n|r(| j|d tt	|dd}t	|dd}|D ]*}t	|||d }|j
rNt|j
 nd}	| jj|f||	d	t|| q8dS )
zS
        Extract a list of subcommands from obj and add them to the parser
        zThe prefix %r is already taken!r   )r   	cmdprefixr   add_helpTN)r   r@   )r,   r   r   
ValueErrorr.   add_subparsersr   add_argument_grouprs   r   r   rW   rX   rY   
add_parserr`   rk   )
r   rb   rL   r   r   	prefixlenr   r   r   docr   r   r   rj   .  s.   

zArgumentParser.addsubcommandsc                 C   s   || _ t|| _| t|< dS )z
        Extracts the signature from a callable object and adds an .argspec
        attribute to the parser. Also adds a .func reference to the object.
        N)r   r
   r1   rd   )r   rL   r   r   r   _set_func_argspecB  s   
z ArgumentParser._set_func_argspecc              
   C   s  |  | | j}|jpd}t|j}t|}tf||  | }t|ddd  }| _t|j|D ]\}}	|j	
|d}
t|
}|j}|	tu rJd}n6|	}|jdu rXdt| |_|jdu rxt|	trft|_nt|	trot|_n	|	durxt|	|_|s|	dkrd}|jd	v r|d
r|d
}n|d
d}|jr||j |d | f}n'|| f}n!|	tu r| j||j|j|j|d n| j|d|j||j|j|d |jdkr|	tur|pt|	}| j||j||j|j|d q0|jdkr|	tur|	durttd||	f | j|d|jd q0|jr.t|j	
|jd}| j|jd|jg |j|jd |j rNt|j	
|j d}| j|j d|ji |j|jd dS dS )z
        Extract the arguments from the attributes of the passed function
        and return a populated ArgumentParser instance.
        r   r   -r   Nz[%s]r   z'')rE   rH   r.   r   )r@   rA   rB   rC   ?)nargsr@   defaultrA   rB   rC   rE   )r@   r   rA   rB   rC   rH   Fz#Flag %r wants default False, got %r
store_true)actionr@   *)r   r@   r   rA   rC   )!r   r1   r   rs   r   NONEr   prefixzipr   ri   rN   rQ   rC   r@   r/   rA   
isinstancer   r#   r   r    rJ   endswithrY   replacerF   add_argumentrB   r-   r.   r   r   )r   r   r   r   n_args
n_defaultsalldefaultsr   r_   r   r7   r   rC   dfltsuffix	shortlongr   r   r   rk   K  s   

















zArgumentParser.populate_fromc                    s   t  jd fdd}||S )zMay raise a SystemExit__missing__c                    s     d|  S )NzNo command %r)r   )r_   r%   r   r   r&     s   z(ArgumentParser.missing.<locals>.<lambda>)r   rL   )r   r_   missr   r%   r   r     s   zArgumentParser.missingc                 C   s    t |  | jD ]}t | qdS )zUseful for debuggingN)print_actions)r   r   r   r   r   print_actions  s   

zArgumentParser.print_actions)Nr   )r   r   r   r   ra   versionr   r   r   r   rj   r   rk   r   r   __classcell__r   r   r   r   rh      s    ,
	Irh   c                 C   s&   t | dot|  ot| ttf S )zAAny object with an __iter__ method which is not a string or class__iter__)r,   r	   r*   r   r/   bytesrK   r   r   r   rO     s   &rO   c                 C   sZ   |du rt jdd }t| }|r|jddd|d ||\}}t|r+|r+t|S |S )a  
    If obj is a function or a bound method, parse the given arglist
    by using the parser inferred from the annotations of obj
    and call obj with the parsed arguments.
    If obj is an object with attribute .commands, dispatch to the
    associated subparser.
    NrS   z	--versionz-vr   )r   r   )sysargvro   r   r   rO   list)rL   rt   eagerr   rn   r   resultr   r   r   call  s   r   )NNNN)NNNNNr   )T)NTN)%rp   r   r   r	   rW   r>   rZ   r   r   r   r.   version_infor   r   r+   r    r#   r
   r   r;   rD   rG   rI   rM   rN   r   rh   r   r   r]   r`   rd   ro   rv   r   rO   r   r   r   r   r   <module>   sD   



	

 >