a
    zeA                     @   s   g d Z ddlZzddlmZ W n ey:   dd ZY n0 G dd deZeZg fdd	Zg fd
dZ	dd Z
dd Zdd Zdd ZedkrddlZeeejdd dddg dS ))GetoptErrorerrorgetopt
gnu_getopt    N)gettextc                 C   s   | S N )sr   r   /usr/lib/python3.9/getopt.py_)       r   c                   @   s&   e Zd ZdZdZdddZdd ZdS )r    c                 C   s   || _ || _t| || d S r   )msgopt	Exception__init__)selfr   r   r   r   r
   r   .   s    zGetoptError.__init__c                 C   s   | j S r   )r   )r   r   r   r
   __str__3   s    zGetoptError.__str__N)r   )__name__
__module____qualname__r   r   r   r   r   r   r   r
   r   +   s   
r   c                 C   s   g }t |t dkr|g}nt|}| r| d dr| d dkr| d dkr\| dd  } q| d drt|| d dd  || dd  \}} q$t|| d dd  || dd  \}} q$|| fS )Nr   r   ---      )typelist
startswithdo_longs	do_shorts)args	shortoptslongoptsoptsr   r   r
   r   8   s    ((r   c                 C   s6  g }g }t |tr|g}nt|}|dr>|dd  }d}ntjdrPd}nd}| r.| d dkrz|| dd  7 }q.| d d d dkrt|| d dd  || dd  \}} qT| d d d d	kr| d d	krt|| d dd  || dd  \}} qT|r|| 7 }q.qT|	| d  | dd  } qT||fS )
N+r   TZPOSIXLY_CORRECTFr   r   r   r   )

isinstancestrr   r   osenvirongetr   r   append)r    r!   r"   r#   Z	prog_argsZall_options_firstr   r   r
   r   c   s2    

( (r   c                 C   s   z| d}W n ty$   d }Y n 0 |d | ||d d   }}t||\}}|r|d u r|stttd| ||d |dd   }}n|d urttd| || d| |pdf | |fS )N=r   zoption --%s requires argumentr   z%option --%s must not have an argumentr   r   )index
ValueErrorlong_has_argsr   r   r*   )r#   r   r"   r    ioptarghas_argr   r   r
   r      s    
r   c                    s    fdd|D }|s(t td    |v r8d fS  d |v rLd fS t|dkrjt td   |d	 }|d}|r|d d
 }||fS )Nc                    s   g | ]}|  r|qS r   )r   ).0or   r   r
   
<listcomp>   r   z!long_has_args.<locals>.<listcomp>zoption --%s not recognizedFr+   Tr   zoption --%s not a unique prefixr   )r   r   lenendswith)r   r"   ZpossibilitiesZunique_matchr1   r   r4   r
   r.      s    
r.   c                 C   s   |dkr|d |dd   }}t ||rh|dkr\|sFttd| ||d |dd   }}|d }}nd}| d| |f q | |fS )Nr   r   r   zoption -%s requires argumentr   )short_has_argr   r   r*   )r#   Z	optstringr!   r    r   r0   r   r   r
   r      s    
r   c                 C   sX   t t|D ]4}| ||   kr(dkrn q|d|d   S qttd|  | d S )N:r   zoption -%s not recognized)ranger7   r   r   r   )r   r!   r/   r   r   r
   r9      s    r9   __main__r   za:bzalpha=beta)__all__r'   r   r   ImportErrorr   r   r   r   r   r   r.   r   r9   r   sysprintargvr   r   r   r
   <module>"   s    +2