U
    ÝáhsŽ  ã                   @   s„   d Z ddlZddlmZmZmZ G dd„ deƒZG dd„ deƒZ	G dd	„ d	e
ƒZG d
d„ de
ƒZG dd„ deƒZG dd„ deƒZdS )a-  The commandlines.library module contains the Command, Arguments, Definitions, Mops, MultiDefinitions, and Switches
classes.  These objects are used to parse command line argument strings to command line syntax specific Python objects.

The Command class is a high level object that is intended to be the public facing portion of the library.  The
commandlines Command object can be imported into projects with the following import statement:

`from commandlines import Command`

Exceptions raised by this module are in the `commandlines.exceptions` module.
é    N)ÚIndexOutOfRangeErrorÚMissingArgumentErrorÚMissingDictionaryKeyErrorc                   @   s*  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ ZdJd-d.„Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIS )KÚCommanda€  An object that maintains syntax specific components of a command line string and provides methods to support
    the development of Python command line applications.

    The class is instantiated from the list of command line arguments that are passed to a Python script in `sys.argv`.

    Attributes:
        arg0 : (string)
               Argument at index position 0
        arg1 : (string)
               Argument at index position 1
        arg2 : (string)
               Argument at index position 2
        arg3 : (string)
               Argument at index position 3
        arg4 : (string)
               Argument at index position 4
        argc : (int)
               Length of the arguments list
        arglp : (string)
                Argument at last index position in the arguments list
        arguments: (Arguments, list)
                   List of all ordered positional arguments in the command string
        defaults: (dict)
                  Dictionary of default key : value mapped as option : argument value
        defs: (Definitions, dict)
               Dictionary of key=option : value=argument definition pairs
        mdefs: (MultiDefinitions, Definitions, dict)
                Dictionary of key=option : value=argument definition pairs for options included more than once in command
        mops: (set)
               Set of multi-option short syntax (i.e. single dash) switches
        subcmd: (string)
                 The first positional argument (=arg0)
        subsubcmd: (string)
               The second positional argument (=arg1)
        switches: (set)
               Set of long and short switch syntax arguments
    c                 C   s  t jdd … | _t| jƒ| _i | _t| jƒ| _t| jƒ| _t	| jƒ| _
t| jƒ| _t| jƒ| _| j d¡| _| j d¡| _| j d¡| _| j d¡| _| j d¡| _| j | jd ¡| _| j| _| j| _t| jƒdk| _t| jƒdk| _t| jƒdk| _t| j
ƒdk| _t| jƒdk| _d S )Né   r   é   é   é   )ÚsysÚargvÚ	ArgumentsÚ	argumentsÚdefaultsÚSwitchesÚswitchesÚMopsÚmopsÚDefinitionsÚdefsÚMultiDefinitionsÚmdefsÚlenÚargcÚget_argument_for_commandobjÚarg0Úarg1Úarg2Úarg3Úarg4ÚarglpÚsubcmdÚ	subsubcmdZhas_argsZhas_switchesZhas_mopsZhas_defsZ	has_mdefs©Úself© r$   úF/var/www/html/venv/lib/python3.8/site-packages/commandlines/library.pyÚ__init__9   s*    zCommand.__init__c                 C   s   d| j  ¡  S ©Nz0< Command object > instantiated from arguments: ©r   Ú__str__r"   r$   r$   r%   Ú__repr__R   s    zCommand.__repr__c                 C   s   d| j  ¡  S r'   r(   r"   r$   r$   r%   r)   U   s    zCommand.__str__c                 C   s
   | j dkS )zŠCommand string validation for missing arguments to the executable.

        :returns: boolean. True = does not validate. False = validatesr   ©r   r"   r$   r$   r%   Údoes_not_validate_missing_args^   s    z&Command.does_not_validate_missing_argsc                 C   s   t | jƒdkot | jƒdkS )z‹Command string validation for missing definitions to the executable

        :returns: boolean. True = does not validate. False = validatesr   )r   r   r   r"   r$   r$   r%   Údoes_not_validate_missing_defse   s    z&Command.does_not_validate_missing_defsc                 C   s   t | jƒdkS )z£Command string validation for missing multi-option short syntax arguments to the executable

        :returns: boolean. True = does not validate. False = validatesr   ©r   r   r"   r$   r$   r%   Údoes_not_validate_missing_mopsl   s    z&Command.does_not_validate_missing_mopsc                 C   s   t | jƒdkS )zˆCommand string validation for missing switches to the executable

        :returns: boolean. True = does not validate. False = validatesr   ©r   r   r"   r$   r$   r%   Ú"does_not_validate_missing_switchess   s    z*Command.does_not_validate_missing_switchesc                 C   s   | j |krdS dS dS )zóCommand string validation for inclusion of exactly n arguments to executable.

           :param number: (integer) Defines the number of expected arguments for this test
           :returns: boolean. True = does not validate. False = validatesFTNr+   ©r#   Únumberr$   r$   r%   Údoes_not_validate_n_argsz   s    
z Command.does_not_validate_n_argsc                 C   s
   | j dkS )z›Command string validation for inclusion of at least one argument to the executable

        :returns: boolean. True = validates. False = does not validate.r   r+   r"   r$   r$   r%   Úvalidates_includes_args…   s    zCommand.validates_includes_argsc                 C   s   t | jƒdkS )z¯Command string validation for inclusion of at least one definition (option-argument) to the executable

        :returns: boolean. True = validates. False = does not validate.r   )r   r   r"   r$   r$   r%   Úvalidates_includes_definitionsŒ   s    z&Command.validates_includes_definitionsc                 C   s   t | jƒdkS )z¾Command string validation for inclusion of at least one multi-option short syntax argument to the
        executable.

        :returns: boolean. True = validates. False = does not validate.r   r.   r"   r$   r$   r%   Úvalidates_includes_mops“   s    zCommand.validates_includes_mopsc                 C   s   t | jƒdkS )z£Command string validation for inclusion of at least one switch argument to the executable.

        :returns: boolean. True = validates. False = does not validate.r   r0   r"   r$   r$   r%   Úvalidates_includes_switches›   s    z#Command.validates_includes_switchesc                 C   s
   | j |kS )zúCommand string validation for inclusion of exactly `number` arguments to the executable.

        :param number: (integer)  Defines the number of expected arguments for this test
        :returns: boolean. True = validates. False = does not validate.r+   r2   r$   r$   r%   Úvalidates_includes_n_args¢   s    z!Command.validates_includes_n_argsc                 C   s   | j  |¡ dS )at  Sets default option : argument definitions with a dictionary parameter. The option keys should not include
        dashes at the beginning of the option string.  One or more key:value pairs can be included in the
        default_dictionary parameter.

        :param default_dictionary: (dict) Defines the default key=option : value=argument mapping
        :returns: NoneN)r   Úupdate)r#   Zdefault_dictionaryr$   r$   r%   Úset_defaults°   s    zCommand.set_defaultsc                 G   s$   |D ]}|| j  ¡ krq dS qdS )a.  Tests for the presence of one or more default option : argument definitions in the Command.defaults parameter

        :param default_needles: (tuple) One or more test default option strings
        :returns: boolean.  True = the default options are defined. False = the default options are not definedFT)r   Úkeys)r#   Zdefault_needlesÚneedler$   r$   r%   Úcontains_defaultsº   s
    zCommand.contains_defaultsc                 C   s$   || j  ¡ kr| j | S t|ƒ‚dS )a  Gets the value for an existing default option : argument definition in the Command.defaults
        parameter.  The default_needle option string should not include dashes at the beginning of the string.

        :param default_needle: (string) The existing default option for which a value is requested
        :returns: User-specified type.  A value of any type that is permissible as a value in Python dictionaries
        :raises: MissingDictionaryKeyError if the key is not found in the Command.defaults dictionaryN)r   r<   r   )r#   Zdefault_needler$   r$   r%   Úget_defaultÇ   s    
zCommand.get_defaultc                 G   s   | j  |¡S )ah  Test for the presence of one or more switches in the command string. Returns boolean that indicates presence
        (True) or absence (False) of switches.  Dashes should not be used at the beginning of the strings in the
        `switch_needles` parameter.

        :param switch_needles: (tuple) One or more expected switch strings.
        :returns: boolean)r   Úcontains)r#   Zswitch_needlesr$   r$   r%   Úcontains_switchesÚ   s    zCommand.contains_switchesc                 G   s   | j  |¡S )zôReturns boolean that indicates presence (True) or absence (False) of one or more multi-option
        short syntax switch characters.

        :type mops_needles: tuple of one or more expected single character switches
        :returns: boolean)r   r@   )r#   Zmops_needlesr$   r$   r%   Úcontains_mopsä   s    zCommand.contains_mopsc                 G   s   | j  |¡S )aŠ  Test for the presence of one or more option-argument definitions in the command string.  Returns boolean
        that indicates presence (True) or absence (False) of definition options.  Dashes should not be used at the
        beginning of the strings in the `def_needles` parameter.

        :param def_needles: (tuple) One or more expected definition option key(s).
        :returns: boolean)r   r@   ©r#   Zdef_needlesr$   r$   r%   Úcontains_definitionsí   s    zCommand.contains_definitionsc                 G   s   | j  |¡S )aÛ  Test for the presence of multiple option-argument definitions that use the same option string.  An example is

        `$ executable -o file1 -o file2`

        The dashes in the argument strings should not be included in the `def_needles` parameter. Returns boolean that
        indicates presence (True) or absence (False) of one or more multi-definition options.

        :param def_needles: (tuple) One or more expected definition option key(s).
        :returns: boolean)r   r@   rC   r$   r$   r%   Úcontains_multi_definitions÷   s    z"Command.contains_multi_definitionsc                 G   sJ   t |ƒt | jƒkrdS d}|D ]"}| j| |kr:|d7 }q dS qdS dS )a$  Test for a sequence of command line tokens in the command string.  The test begins at index position 0
        of the argument list and is case-sensitive.

        :param cmd_list: (tuple) Expected commands in expected order starting at Command.argv index position 0
        :returns: booleanFr   r   TN)r   r   )r#   Zcmd_listÚindexÚtest_argr$   r$   r%   Úhas_command_sequence  s    
zCommand.has_command_sequencer   c                 C   s>   || j kr2| j  |¡}t| jƒ|| kr,dS dS nt|ƒ‚dS )aü  Test for the presence of at least one (default) positional arguments following an existing argument
        (argument_needle).  The number of expected arguments is modified by defining the `number` method parameter.

        :param number: (integer) The number of expected arguments after the test argument
        :param argument_needle: (string) The test argument that is known to be present in the command
        :raises: MissingArgumentError when argument_needle is not found in the parsed argument listTFN)r   Úget_arg_positionr   r   r   )r#   Zargument_needler3   Úpositionr$   r$   r%   Úhas_args_after  s    
zCommand.has_args_afterc                 C   s@   || j kr4| j  |¡}| j  |¡}||kr.dS dS nt|ƒ‚dS )a  Test for the presence of a supported argument in the n+1 index position for a known argument at the
        n position.  start_argument is called as the full argument string including any expected dashes.

        :param start_argument: (string) The argument string including any beginning dashes as used on the command line.
        :param supported_at_next_position: (list) list of strings that define supported arguments in the n+1 index
        :raises: MissingArgumentError when start_argument is not found in the parsed argument listTFN)r   rI   Úget_arg_nextr   )r#   Zstart_argumentZsupported_at_next_positionrJ   Ztest_argumentr$   r$   r%   Únext_arg_is_in'  s    
zCommand.next_arg_is_inc                 C   s   d| j krdS dS dS )z§Test for the presence of the double dash `--` command line idiom.

        :returns: boolean. True = has double dash token. False = does not contain double dash token.ú--TFN)r   r"   r$   r$   r%   Úhas_double_dash?  s    
zCommand.has_double_dashc                 C   s   | j  |¡S )a  Returns the argument to an option that is part of an option-argument definition pair.

        :param def_needle: (string) The option string of the option-argument pair
        :returns: string
        :raises: MissingDictionaryKeyError when the option string is not found)r   Úget_def_argument©r#   Z
def_needler$   r$   r%   Úget_definitionO  s    zCommand.get_definitionc                 C   s   | j  |¡S )ak  Returns a list of argument strings to an option that is included multiple times using option-argument
        syntax on the command line (e.g. `$ executable -o file1 -o file2`)

        :param def_needle: (string) The option string of the option-argument pair
        :returns: string
        :raises: MissingDictionaryKeyError when the option string is not found)r   rP   rQ   r$   r$   r%   Úget_multiple_definitionsX  s    z Command.get_multiple_definitionsc                 C   s.   || j kr"| j |¡}| j |¡S t|ƒ‚dS )a‰  Returns the next positional argument at index position n + 1 to a command line argument at index position n.

           :param target_arg: (string) Argument string for the test.
           :returns: string
           :raises: MissingArgumentError when target_arg is not found in the parsed argument list
           :raises: IndexOutOfRangeError when target_arg is the last positional argumentN)r   r   rI   rL   r   )r#   Z
target_argZrecipient_positionr$   r$   r%   Úget_arg_afterb  s    
zCommand.get_arg_afterc                 C   s8   d| j kr,| j  d¡}|d }| j |d… S tdƒ‚dS )zqReturns the arguments after the double dash `--` command line idiom as a list.

        :returns: list of stringsrN   r   N)r   rI   r   )r#   Zdd_positionZstart_positionr$   r$   r%   Úget_double_dash_argsp  s
    
zCommand.get_double_dash_argsc                 C   s    d| j ksd| j krdS dS dS )z“Tests for `-h` and `--help` options in command string

        :returns: boolean. True = included help option. False = did not include help option.ÚhelpÚhTFN©r   r"   r$   r$   r%   Úis_help_requestƒ  s    zCommand.is_help_requestc                 C   s   d| j krdS dS dS )zTests for `--quiet` option in command string

        :returns: boolean. True = included quiet option.  False = did not include quiet option.ÚquietTFNrX   r"   r$   r$   r%   Úis_quiet_request  s    
zCommand.is_quiet_requestc                 C   s   d| j krdS dS dS )zŒTests for `--usage` option in command string

        :returns: boolean. True = included usage option. False = did not include usage option.ÚusageTFNrX   r"   r$   r$   r%   Úis_usage_request—  s    
zCommand.is_usage_requestc                 C   s   d| j krdS dS dS )z’Tests for `--verbose` option in command string

        :returns: boolean. True = included verbose option. False = did not include verbose option.ÚverboseTFNrX   r"   r$   r$   r%   Úis_verbose_request¡  s    
zCommand.is_verbose_requestc                 C   s    d| j ksd| j krdS dS dS )zTests for `-v` and `--version` options in command string.

        :returns: boolean. True = included version option. False = did not include version option.ÚversionÚvTFNrX   r"   r$   r$   r%   Úis_version_request«  s    zCommand.is_version_requestc                 C   sV  dt | jƒ }|d d t | jƒ }|d d t | jƒ }|d d t | jƒ }|d d t | jƒ }|d d t | jƒ }|d d t | jƒ }|d d	 |  | j	¡ }|d d
 |  | j
¡ }|d d |  | j¡ }|d d |  | j¡ }|d d |  | j¡ }|d d |  | j¡ }|d d |  | j¡ }|d d |  | j¡ }|S )zÛReturns a string of the instance attributes of the Command object intended for standard output use.
        Print the returned string to view the parsed arguments in the standard output stream.

        :returns: stringzobj.argc = Ú
zobj.arguments = zobj.defaults = zobj.switches = zobj.defs = zobj.mdefs = zobj.mops = zobj.arg0 = zobj.arg1 = zobj.arg2 = zobj.arg3 = zobj.arg4 = zobj.arglp = zobj.subcmd = zobj.subsubcmd = )Ústrr   r   r   r   r   r   r   Ú_get_obj_string_format_argr   r   r   r   r   r   r    r!   ©r#   Z
the_stringr$   r$   r%   Ú
obj_string»  s     zCommand.obj_stringc                 C   s   |dkrdS d| d S dS )zNFormats argument strings for standard output display

        :returns: stringÚ z''ú'Nr$   rf   r$   r$   r%   re   Ó  s    z"Command._get_obj_string_format_argN)r   )'Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   r*   r)   r,   r-   r/   r1   r4   r5   r6   r7   r8   r9   r;   r>   r?   rA   rB   rD   rE   rH   rK   rM   rO   rR   rS   rT   rU   rY   r[   r]   r_   rb   rg   re   r$   r$   r$   r%   r      sH   %	

	

	




r   c                   @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )r   aF  A class that includes all command line arguments with positional argument order maintained.  Instantiated with
    a list of command line string tokens.

      The class is derived from the Python list type.

      :param argv: A list of command line arguments that maintain the argument order that was entered on command linec                 C   s   t  | |¡ d S ©N)Úlistr&   ©r#   r   r$   r$   r%   r&   å  s    zArguments.__init__c                 C   sH   d}t | ƒdkr*| D ]}|d | d }q| ¡ }| d¡}d| d S ©Nrh   r   ri   ú', ú,ú[ú]©r   Úrstrip©r#   Zargument_stringÚargumentr$   r$   r%   r*   è  s    
zArguments.__repr__c                 C   sH   d}t | ƒdkr*| D ]}|d | d }q| ¡ }| d¡}d| d S rq   rv   rx   r$   r$   r%   r)   ò  s    
zArguments.__str__c                 C   s$   t | ƒ|kr|dkr| | S dS dS )aB  An argument parsing method for the instantation of the Command object.  This is not intended for public use.
        Public calls should use the get_argument() method instead.

        :param position: The command line index position
        :returns: string or empty string if the index position is out of the index ranger   rh   N)r   ©r#   rJ   r$   r$   r%   r   ü  s    z%Arguments.get_argument_for_commandobjc                 C   s&   t | ƒ|kr|dkr| | S tƒ ‚dS )zÿReturns an argument string by the argument list index position.

        :param position: (integer) The command line index position
        :returns: string
        :raises: IndexOutOfRangeError if the requested index falls outside of the list index ranger   N©r   r   rz   r$   r$   r%   Úget_argument  s    zArguments.get_argumentc                 C   s   || kr|   |¡S t|ƒ‚dS )aÃ  Returns the index position of the `test_arg` parameter candidate argument string.  The argument string
        should include the dashes at the beginning of the argument string that would be expected with use on the
        command line.

        :param test_arg: (string) The argument string for which the index position is requested
        :returns: string
        :raises: MissingArgumentError if the requested argument is not in the Argument listN)rF   r   )r#   rG   r$   r$   r%   rI     s    	
zArguments.get_arg_positionc                 C   s&   t | ƒ|d kr| |d  S tƒ ‚dS )a$  Returns the next argument at index `position` + 1 in the command sequence.

        :param position: (integer) The argument index position in the Argument list
        :returns: string
        :raises: IndexOutOfRangeError if the `position` + 1 index falls outside of the existing index ranger   Nr{   rz   r$   r$   r%   rL   "  s    zArguments.get_arg_nextc                 C   s   |D ]}|| krq dS qdS )zñReturns boolean that indicates the presence (True) or absence (False) of a tuple of one or more test
        arguments.

        :param needle: (iterable) An iterable that contains one or more test argument strings.
        :returns: booleanFTr$   ©r#   r=   Zexpected_argumentr$   r$   r%   r@   .  s
    zArguments.containsN)rj   rk   rl   rm   r&   r*   r)   r   r|   rI   rL   r@   r$   r$   r$   r%   r   Þ  s   

r   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )r   ah  A class that is instantiated with all command line switches that have the syntax `-s`, `--longswitch`,
    or `-onedashlong`.

    The class is derived from the Python set type and arguments with this syntax are saved as set items.

    :param argv: (list) A list of command line arguments that maintain the argument order that was entered on command line
    c                 C   s   t  | |  |¡¡ d S rn   )Úsetr&   Ú_make_switch_setrp   r$   r$   r%   r&   F  s    zSwitches.__init__c                 C   sH   d}t | ƒdkr<| D ]}|d | d }q| ¡ }| d¡}d| d S ©Nrh   r   ri   rr   rs   Ú{Ú}rv   ©r#   Zswitch_stringÚswitchr$   r$   r%   r*   I  s    
zSwitches.__repr__c                 C   sH   d}t | ƒdkr<| D ]}|d | d }q| ¡ }| d¡}d| d S r€   rv   rƒ   r$   r$   r%   r)   S  s    
zSwitches.__str__c                 C   sJ   t ƒ }|D ]:}d|d kr
d|kr
|dkr0 qFq
| d¡}| |¡ q
|S )a  Returns a set that includes all switches that are parsed from the command string.  Used to instantiate Switch
        objects.

        :param argv: (list) A list of command line arguments that maintain the argument order that was entered on command line
        :returns: setú-r   ú=rN   )r~   ÚlstripÚadd)r#   r   Z	switchsetZswitch_candidater$   r$   r%   r   ]  s    
zSwitches._make_switch_setc                 C   s   |D ]}|| krq dS qdS )ac  Returns boolean that indicates the presence (True) or absence (False) of a tuple of test switches.
        Switch parameters in needle tuple should be passed without initial dash character(s) in the test switch
        argument name.

        :param needle: (iterable) An iterable that contains one or more test argument strings.
        :returns: booleanFTr$   r}   r$   r$   r%   r@   p  s
    zSwitches.containsN)	rj   rk   rl   rm   r&   r*   r)   r   r@   r$   r$   r$   r%   r   >  s   

r   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )r   aè  A class that is instantiated with unique switches from multi-option command line options that use short,
    single dash syntax.

    Examples: -rnj -tlx

    Each alphabetic character in the option token is parsed to a separate option token.

    The class is derived from the Python set type and the single character option switches are stored as set items.

    :param argv: (list) A list of command line arguments that maintain the argument order that was entered on command line
    c                 C   s   t  | |  |¡¡ d S rn   )r~   r&   Ú_make_mops_setrp   r$   r$   r%   r&   Ž  s    zMops.__init__c                 C   sH   d}t | ƒdkr<| D ]}|d | d }q| ¡ }| d¡}d| d S r€   rv   ©r#   Zmops_stringr„   r$   r$   r%   r*   ‘  s    
zMops.__repr__c                 C   sH   d}t | ƒdkr<| D ]}|d | d }q| ¡ }| d¡}d| d S r€   rv   rŠ   r$   r$   r%   r)   ›  s    
zMops.__str__c                 C   s`   t ƒ }|D ]P}d|d kr
d|kr
t|ƒdkr
|d dkr
| dd¡}|D ]}| |¡ qJq
|S )a3  Returns a set of multi-option short syntax option characters that are parsed from a list of ordered
        command string arguments in the parameter `argv`.

        :param argv: (list) A list of command line arguments that maintain the argument order that was entered on command line
        :returns: setr…   r   r†   r   r   rh   )r~   r   Úreplacerˆ   )r#   r   ZmopssetZmops_candidater„   r$   r$   r%   r‰   ¥  s    zMops._make_mops_setc                 C   s   |D ]}|| krq dS qdS )a…  Returns boolean that indicates the presence (True) or absence (False) of a tuple of test Mops syntax option
        switches.  The test strings should each be a single character without the dash that is used at the beginning of
        the entire token.

        :param needle: (iterable) An iterable that contains one or more test argument characters as strings.
        :returns: booleanFTr$   r}   r$   r$   r%   r@   ¶  s
    zMops.containsN)	rj   rk   rl   rm   r&   r*   r)   r‰   r@   r$   r$   r$   r%   r     s   

r   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )r   a_  A class that is instantiated with all command line definition options as defined by the syntax
    `-s <defintion argument>`,  `--longoption <defintion argument>`,
    `--longoption=<definition argument>`, or `-longoption <definition argument>`.

    To parse as a definition option, the argument to the option must not contain any dashes at the beginning of
    the argument string.  For example, `-o --long` is not considered a definition option-arg pair, whereas
    `-o long` is.

    This class is derived from the Python dictionary type.  The mapping is:

    key = option string with all dash '-' character(s) at the beginning of the string removed.  Internal dashes are
    maintained.

    value = definition argument string.

    :param argv: (list) A list of command line arguments that maintain the argument order that was entered on command line
    c                 C   s   t  | |  |¡¡ d S rn   )Údictr&   Ú_make_definitions_objrp   r$   r$   r%   r&   Ù  s    zDefinitions.__init__c           	      C   s®   i }t |ƒ}d}|D ]”}d|d k}|dkr |dkr: qªnfd|krh| d¡}|d  d¡}|d ||< n8||d k r ||d   d¡s | d¡}||d  ||< |d7 }q|S )aö  Parses definition options from a list of ordered command line arguments to define the dictionary that
        is used to instantiate the Definitions class.  Option string keys are stripped of dash characters before the
        first alphabetic character in the option name.

        :param argv: (list) A list of command line arguments that maintain the argument order that was entered on command line
        :returns: dictionary with {key = option string : value = definition argument string} mappingr   r…   TrN   r†   r   )r   Úsplitr‡   Ú
startswith)	r#   r   ÚdefmapÚarglist_lengthÚcounterÚdef_candidateÚdash_truth_testÚ	split_defÚcleaned_keyr$   r$   r%   r   Ü  s$    


z!Definitions._make_definitions_objc                 C   s"   |D ]}||   ¡ krq dS qdS )aÞ  Returns boolean that indicates the presence (True) or absence (False) of a tuple of option-argument
        definitions by option match attempt.

        The definition option string should be used without any initial dash characters in the definition argument name
        in contrast to how they were used on the command line.

        :param needle: (tuple) A tuple of one or more option strings from expected definition option-argument string pairs
        :returns: booleanFT)r<   )r#   r=   Zexpected_definitionr$   r$   r%   r@   ÿ  s
    
zDefinitions.containsc                 C   s    ||   ¡ kr| | S t|ƒ‚dS )aã  Returns the definition argument string for a definition option test.  The needle parameter should not include
        dash characters at the beginning of the option string (i.e. use 'test' rather than '--test' and 't' rather than
        '-t').

        :param needle: (string) The requested option string from the definition option-argument pair.
        :returns: string
        :raises: MissingDictionaryKeyError if the option needle is not a key defined in the Definitions objectN)r<   r   )r#   r=   r$   r$   r%   rP     s    	zDefinitions.get_def_argumentN)rj   rk   rl   rm   r&   r   r@   rP   r$   r$   r$   r%   r   Ç  s
   #r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   as  A class that is used to parse option-argument definitions from a command line argument list where command line
    use includes multiple same option strings with different argument definitions.  An example is:

    `$ executable -o file1 -o file2`

    The class is derived from the commandlines.Definitions class (which is derived from Python dict). The
    commandlines.Definitions.contains and commandlines.Definitions.get_def_arguments methods are inherited from the
    Definitions class.

    The dictionary mapping is:

    key = option string with all dash '-' character(s) at the beginning of the string removed.  Internal dashes are
    maintained.

    value = list of all argument strings associated with the option string on the command line

    :param argv: (list) A list of command line arguments that maintain the argument order that was entered on command line
    c                 C   s   t  | |¡ d S rn   )r   r&   rp   r$   r$   r%   r&   3  s    zMultiDefinitions.__init__c                 C   s$  i }t |ƒ}d}|D ]Ü}d|d k}|dkrè|dkr: qòn®d|krŠ| d¡}|d  d¡}|| ¡ krz||  |d ¡ qè|d g||< n^||d k rè||d   d¡sè| d¡}|| ¡ krÖ||  ||d  ¡ n||d  g||< |d7 }qi }	| ¡ D ] }
t ||
 ƒdkrþ||
 |	|
< qþ|	S )Nr   r…   TrN   r†   r   )r   rŽ   r‡   r<   Úappendr   )r#   r   r   r‘   r’   r“   r”   r•   r–   Z	multi_mapÚkeyr$   r$   r%   r   6  s4    


z&MultiDefinitions._make_definitions_objN)rj   rk   rl   rm   r&   r   r$   r$   r$   r%   r      s   r   )rm   r
   Zcommandlines.exceptionsr   r   r   Úobjectr   ro   r   r~   r   r   rŒ   r   r   r$   r$   r$   r%   Ú<module>   s      N`CFY