HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/exabgp/vendoring/__pycache__/cmd2.cpython-37.pyc
B

RP�e��@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZmZddlmZddlmZdZejddkr�ej��ejdd	kr�eZGd
d�dej�Zdd
�Zdd�Zdd�Z eej!_"gZ#dPdd�Z$Gdd�de%�Z&dZ'ej(�r~yddl)Z)dd�Z*dd�Z+Wn"e,k
�rxdd�Z*e*Z+YnX�ndejdk�r�dZ-y"ej.dd ej/ej/ej/d!�d Z-Wnej0e1e2fk
�r�YnXe-�r�d"d�Z*d#d�Z+nd$d�Z*e*Z+n�dZ-y"ej.d%d ej/ej/ej/d!�d Z-Wn�e3k
�r�y^d&Z4ej5d'd ej/ej/d(�Z6e6j7�8e4�e6j7�9�ej5d%d ej/ej/d(�Z6e6j:�;�e4k�r�d Z-Wnek
�r�YnXYnek
�r�YnXe-�r�d)d�Z*d*d�Z+nd+d�Z*e*Z+ej�<d,�Gd-d.�d.e=�Z>Gd/d0�d0e?�Z@d1d2�ZAd3d4�ZBGd5d6�d6eC�ZDGd7d8�d8e�ZEdQd:d;�ZFGd<d=�d=ejG�ZGGd>d?�d?e=�ZHGd@dA�dAeI�ZJGdBdC�dCe�ZKdDdE�ZLGdFdG�dGeM�ZNGdHdI�dIeM�ZOGdJdK�dKeO�ZPGdLdM�dMe	jQ�ZReSdNk�r�ejTejUdO�dS)Ra,Variant on standard library's cmd with extra features.

To use, simply import cmd2.Cmd instead of cmd.Cmd; use precisely as though you
were using the standard library's cmd, while enjoying the extra features.

Searchable command history (commands: "hi", "li", "run")
Load commands from file, save to file, edit commands in file
Multi-line commands
Case-insensitive commands
Special-character shortcut commands (beyond cmd's "@" and "!")
Settable environment parameters
Optional _onchange_{paramname} called when environment parameter changes
Parsing commands with `optparse` options (flags)
Redirection to file with >, >>; input from file with <
Easy transcript-based testing of applications (see example/example.py)
Bash-style ``select`` available

Note that redirection with > and | will only work if `self.stdout.write()`
is used in place of `print`.  The standard library's `cmd` module is
written to use `self.stdout.write()`,

- Catherine Devlin, Jan 03 2008 - catherinedevlin.blogspot.com

mercurial repository at https://www.assembla.com/wiki/show/python-cmd2
�N)�six)�InteractiveConsole�InteractiveInterpreter)�make_option)�	pyparsingz0.6.8��c@s&eZdZd	dd�Zdd�Zdd�ZdS)
�OptionParserrNcCsd|j_|rt|�dS)NT)�values�_exit�print)�self�status�msg�r�F/opt/alt/python37/lib/python3.7/site-packages/exabgp/vendoring/cmd2.py�exitGszOptionParser.exitcOs>yt|jj�Wntk
r$YnXtjj|f|�|�dS)N)r�_func�__doc__�AttributeError�optparser	�
print_help)r
�args�kwargsrrrrLs
zOptionParser.print_helpcCst�|��dS)z�error(msg : string)

        Print a usage message incorporating 'msg' to stderr and exit.
        If you override this in a subclass, it should not return -- it
        should either exit or raise an exception.
        N)r�
OptParseError)r
rrrr�errorSszOptionParser.error)rN)�__name__�
__module__�__qualname__rrrrrrrr	Fs
r	cCs4d�dd�|D��d}t�||�}||��d�S)z�
    Preserves the spacing originally in the argument after
    the removal of options.

    >>> remaining_args('-f bar   bar   cow', ['bar', 'cow'])
    'bar   cow'
    z\s+css|]}t�|�VqdS)N)�re�escape)�.0�arrr�	<genexpr>esz!remaining_args.<locals>.<genexpr>z\s*$N)�joinr�search�start)ZoldArgs�
newArgList�patternZmatchObjrrr�remaining_args]sr)cCs$y
t||�Stk
rdSXdS)z�Returns an attribute's value, or None (no error) if undefined.
       Analagous to .get() for dictionaries.  Useful when checking for
       value of options that may not have been defined on a given
       method.N)�getattrr)�obj�attrrrr�
_attr_get_js
r-cCs:y tjd|gtjtjd���dStk
r4dSXdS)N�which)�stdout�stderrr)�
subprocess�Popen�PIPE�STDOUT�communicate�OSError)�editorrrr�_whichus r8�argcsDt�t�s�g�x �D]}t�t�|����qW��fdd�}|S)a�Used as a decorator and passed a list of optparse-style options,
       alters a cmd2 method to populate its ``opts`` argument from its
       raw text argument.

       Example: transform
       def do_something(self, arg):

       into
       @options([make_option('-q', '--quick', action="store_true",
                 help="Makes things fast")],
                 "source dest")
       def do_something(self, arg, opts):
           if opts.quick:
               self.fast_button = True
       csft��x�D]}��|�qW��d�jdd��f���_��fdd�}d�j���f|_|S)Nz%s [options] %src
s�y:��|���\}}t||�}t|t�r4|�|�}n|}Wn4tjk
rn}zt|���	�dSd}~XYnXt
|d�r~dS�|||�}|S)Nr)�
parse_args�splitr)�
isinstance�ParsedString�with_args_replacedrrrr�hasattr)�instancer9�optsr'ZnewArgs�e�result)�func�optionParserrr�new_func�s


z/options.<locals>.option_setup.<locals>.new_funcz%s
%s)r	�
add_option�	set_usagerrr�format_help)rD�optrF)�arg_desc�option_list)rDrEr�option_setup�s
zoptions.<locals>.option_setup)r<�list�options_defined�appendr�Literal�get_opt_string)rLrKrJrMr)rKrLr�options�s

rSc@sDeZdZejdd�dkr dZnejdd�dkr4ndZdd�ZdS)	�PasteBufferErrorNr�winz�Redirecting to or from paste buffer requires pywin32
to be installed on operating system.
Download from https://sourceforge.net/projects/pywin32/Zdarz�Redirecting to or from paste buffer requires xclip
to be installed on operating system.
On Debian/Ubuntu, 'sudo apt-get install xclip' will install it.cCst�||j�dS)N)�	Exception�__init__�errmsg)r
rrrrW�szPasteBufferError.__init__)rrr�sys�platformrXrWrrrrrT�srTzWRedirecting to or from paste buffer requires %s
to be installed on operating system.
%scCs<t�d�yt��}Wntk
r.d}YnXt��|S)Nr�)�win32clipboard�
OpenClipboardZGetClipboardData�	TypeError�CloseClipboard)rCrrr�get_paste_buffer�s

r`cCs(t�d�t��t�|�t��dS)Nr)r\r]ZEmptyClipboardZSetClipboardTextr_)�txtrrr�write_to_paste_buffer�s

rbcGsttd��dS)N)Zpywin32z7Download from https://sourceforge.net/projects/pywin32/)r6�pastebufferr)rrrrr`�s�darwinFzpbcopy -helpT)�shellr/�stdinr0cCs$tjddtjtjtjd�}|j��S)Nzpbcopy -helpT)rer/rfr0)r1r2r3r/�read)�
pbcopyprocrrrr`�scCs,tjddtjtjtjd�}|�|���dS)N�pbcopyT)rer/rfr0)r1r2r3r5�encode)rarhrrrrb�scGsttd��dS)N)rizFOn MacOS X - error should not occur - part of the default installation)r6rc)rrrrr`szxclip -o -sel clipzTesting for presence of xclip.zxclip -sel clip)rer/rfcCs tjddtjtjd�}|j��S)Nzxclip -o -sel clipT)rer/rf)r1r2r3r/rg)�	xclipprocrrrr`scCsdtjddtjtjd�}|j�|���|j��tjddtjtjd�}|j�|���|j��dS)Nzxclip -sel clipT)rer/rf�xclip)r1r2r3rf�writerj�close)rarkrrrrb$s
cGsttd��dS)N)rlz;On Debian/Ubuntu, install with "sudo apt-get install xclip")r6rc)rrrrr`/sz 	c@seZdZdd�Zdd�ZdS)r=cCs,td|jj|jjf�}|j|_|j|_|S)Nz%s %s)r=�parsed�commandr�parser)r
�newrrr�full_parsed_statement8sz"ParsedString.full_parsed_statementcCs2t|�}|j|_|j|_||jd<||jjd<|S)Nr)r=rorq�	statement)r
Znewargsrrrrrr>>s
zParsedString.with_args_replacedN)rrrrsr>rrrrr=7sr=c@s@eZdZdZdd�ZeZdd�Zdd�Zdd	�Ze	d
d��Z
dS)
�StubbornDictaGDictionary that tolerates many input formats.
    Create it with stubbornDict(arg) factory function.

    >>> d = StubbornDict(large='gross', small='klein')
    >>> sorted(d.items())
    [('large', 'gross'), ('small', 'klein')]
    >>> d.append(['plain', '  plaid'])
    >>> sorted(d.items())
    [('large', 'gross'), ('plaid', ''), ('plain', ''), ('small', 'klein')]
    >>> d += '   girl Frauelein, Maedchen\n\n shoe schuh'
    >>> sorted(d.items())
    [('girl', 'Frauelein, Maedchen'), ('large', 'gross'), ('plaid', ''), ('plain', ''), ('shoe', 'schuh'), ('small', 'klein')]
    cCst�|t�|��dS)N)�dict�updateru�to_dict)r
r9rrrrwVszStubbornDict.updatecCs|�|�|S)N)rw)r
r9rrr�__iadd__[s
zStubbornDict.__iadd__cCst�|�}|�t|��|S)N)�copyrw�stubbornDict)r
r9�selfcopyrrr�__add___s
zStubbornDict.__add__cCst�|�}|�t|��|S)N)rzrwr{)r
r9r|rrr�__radd__ds
zStubbornDict.__radd__cCszt|d�r|��}t|d�rri}xT|D]F}|��}|r&|�dd�}|d}t|�dkr`|d}nd}|||<q&Wn|}|S)z3Generates dictionary from string or list of strings�
splitlines�__reversed__N�rr[)r?r�stripr;�len)�clsr9rCr"Zkey_val�key�valrrrrxis



zStubbornDict.to_dictN)rrrrrwrPryr}r~�classmethodrxrrrrruGs
rucOs4i}x|D]}|�t�|��q
W|�|�t|�S)az
    >>> sorted(stubbornDict('cow a bovine\nhorse an equine').items())
    [('cow', 'a bovine'), ('horse', 'an equine')]
    >>> sorted(stubbornDict(['badger', 'porcupine a poky creature']).items())
    [('badger', ''), ('porcupine', 'a poky creature')]
    >>> sorted(stubbornDict(turtle='has shell', frog='jumpy').items())
    [('frog', 'jumpy'), ('turtle', 'has shell')]
    )rwrurx)r9�kwargrCr"rrrr{s
	

r{cCsN|rDyttj�|d����}WqJtk
r@d|d}YqJXnt�}|S)Nrz< %s)�open�os�path�
expanduserrg�IOErrorr`)�fnamerCrrr�replace_with_file_contents�sr�c@seZdZdS)�EmbeddedConsoleExitN)rrrrrrrr��sr�c@seZdZdS)�EmptyStatementN)rrrrrrrr��sr�� cCs@t|d�r|�||�St|�|kr8||g|d|�}|SdS)z+analogous to str.ljust, but works for lists�ljustN)r?r�r�)�x�widthZfillcharrrrr��s

r�c	@sdeZdZdZdZdZdZdejej	Z
ddddd	�Zd
��Z
dZd��ZdZd
ZdZdZgZdZdZdZdZdZdZed�Zdd�Zd�dd�Zdd�ZdZ dZ!e"j#�$d�Z%e%s�e&j'dd�dkr�dZ%nxdD]Z%e(e%�r�Pq�Wddd�d d!d�d"d!d�d#d!d�d$d!d�d%d!d�d&d'd�d(�Z)e'�*�d)kZ+d*d+�Z,d,d-�Z-d.d/�Z.d0d1�Z/d2d3�Z0e�1�Z2e�3ej4ej5g�Z6e6�7d4d5��e�8d6�e�9ej:d7A�Z;d8gZ<dZ=gZ>d9d:�Z?d;d<�Z@d=d>�ZAd?d@�ZBdAdB�ZCdCdD�ZDdEdF�ZEdGdH�ZFdIdJ�ZGdKdL�ZHdMdN�ZIdOdP�ZJdQdR�ZKdSdT�ZLd�dUdV�ZMdWdX�ZNeNZOdYdZ�ZPePZQePZRd�d\d]�ZSeTeUd^d_d`dadb�g�dcdd��ZVdedf�ZWdgdh�ZXdidj�ZYdkdl�ZZeTeUdmdnd`dodb�gdpdq�drds��Z[dtdu�Z\dvdw�Z]e[Z^e]Z_e]Z`dxdy�ZaeaZbe�ce�deje�dzA�d{�e�ce�de
d|��d}�ej:Zfd~d�Zgd�d��Zhd�d�d��Ziej�kd��Zld�d�d��ZmemZnd�d��ZoeoZpd�d��Zqd�d��Zrd�d��Zsd�d��ZtdS)��CmdFTz> z	!#$%.:?@_�helpre�loadZ_relative_load)�?�!�@z@@z&run r list l history hi ed edit li eofzset ed edit exitrazcommand.txtN�>a�
        prompt
        colors                Colorized output (*nix only)
        continuation_prompt   On 2nd+ line of input
        debug                 Show full error stack on error
        default_file_name     for ``save``, ``load``, etc.
        editor                Program used by ``edit``
        case_insensitive      upper- and lower-case both OK
        feedback_to_output    include nonessentials in `|`, `>` results
        quiet                 Don't print nonessential feedback
        echo                  Echo command issued into output
        timing                Report execution times
        abbrev                Accept abbreviated commands
        cCs,|r(|j�|�|ddkr(|j�d�dS)zGConvenient shortcut for self.stdout.write(); adds newline if necessary.����
N)r/rm)r
rrrr�poutput�szCmd.poutputcCs|jrt��tt|��dS)N)�debug�	traceback�	print_excr�str)r
rXrtrrr�perror�sz
Cmd.perrorcCs$|js |jr|�|�nt|�dS)z�For printing nonessential feedback.  Can be silenced with `quiet`.
           Inclusion in redirected output is controlled by `feedback_to_output`.N)�quiet�feedback_to_outputr�r)r
rrrr�	pfeedback�sz
Cmd.pfeedbacki���ZEDITORrrUZnotepad)ZgeditZkate�vim�vi�emacsZnanoZpicozz)TFzzzzzzzz)�bold�cyan�blue�red�magenta�green�	underline�WindowscCs6|jr2|j|jkr2|j|d||j|dS|S)a�Given a string (``val``), returns that string wrapped in UNIX-style
           special characters that turn on (and then off) text color and style.
           If the ``colors`` environment paramter is ``False``, or the application
           is running on Windows, will return ``val`` unchanged.
           ``color`` should be one of the supported strings (or styles):
           red/blue/green/cyan/magenta, bold, underlineTF)�colorsr/�initial_stdout�
colorcodes)r
r��colorrrr�colorize�s zCmd.colorizecCs4|j�d|jrdpdt|j�d�|j�d��dS)z)Summary report of interactive parameters.z�
        Commands are %(casesensitive)scase-sensitive.
        Commands may be terminated with: %(terminators)s
        Settable parameters: %(settable)s
znot r[r�)Z
casesensitive�terminators�settableN)r/rm�case_insensitiver�r�r$r�)r
rrrr�do_cmdenvironment	s
zCmd.do_cmdenvironmentc	Csp|r^|�|�}|rlt||�}y|jj|jd�Wqltk
rZtj�||dd��YqlXntj�||�dS)N)�filer)	�
func_namedr*rErr/r�cmdr��do_help)r
r9�funcname�fnrrrr�s

zCmd.do_helpcOsdtjj|f|�|�tj|_t�|_i|_t	|j
��dd�|_
|jdd�t
|�D�|_|��dS)NT)�reversecSs"g|]}|�d�r|dd��qS)�do_rN)�
startswith)r!r�rrr�
<listcomp>)sz Cmd.__init__.<locals>.<listcomp>)r�r�rWrYr/r��History�history�pystate�sorted�	shortcuts�items�reserved_words�dir�keywords�_init_parser)r
rrrrrrW#szCmd.__init__cCs.d�dd�t|j�D��}|j�d|�dS)z%Lists single-key shortcuts available.r�css"|]}d|d|dfVqdS)z%s: %srr�Nr)r!�scrrrr#.sz#Cmd.do_shortcuts.<locals>.<genexpr>z,Single-key shortcuts for other commands:
%s
N)r$r�r�r/rm)r
rrCrrr�do_shortcuts,szCmd.do_shortcutscCsdS)Nr[r)r�rrr�<lambda>3�zCmd.<lambda>z/*z*/�;cst��jd�t���jBt�d�j�Bd�}t�dd��jD��d�}tjdA}t��fdd��jD��d	��_	�j	t�
�j�d
�}tjddd�}�j
�tj��d
d���j
�jBtjB}t�|tj||A|d�d��t�|tj||d��dd��d��}�j�r2�j	�dd��|�dd���j�rDtj�_nRtjtjd��_�j�d��j	|Atj�j|d��dd��d��jd��_�j	|Atj||d��dd��d�|d�tj||A|A|d��dd��d�|�_�j��j�|tj||A|A|A|d��dd��d�d�t�|�|�_�j�d��_�j|�jB�jB�jB�j	tj||d�B�_�j��j
�t�d�}|�dd��t�
�jd�}	|	d�}
|
�t�|t�|
�t�d �t�|	�tjdB�_ �j ��j�d!S)"a�
        >>> c = Cmd()
        >>> c.multilineCommands = ['multiline']
        >>> c.case_insensitive = True
        >>> c._init_parser()
        >>> print (c.parser.parseString('').dump())
        []
        >>> print (c.parser.parseString('').dump())
        []
        >>> print (c.parser.parseString('/* empty command */').dump())
        []
        >>> print (c.parser.parseString('plainword').dump())
        ['plainword', '']
        - command: plainword
        - statement: ['plainword', '']
          - command: plainword
        >>> print (c.parser.parseString('termbare;').dump())
        ['termbare', '', ';', '']
        - command: termbare
        - statement: ['termbare', '', ';']
          - command: termbare
          - terminator: ;
        - terminator: ;
        >>> print (c.parser.parseString('termbare; suffx').dump())
        ['termbare', '', ';', 'suffx']
        - command: termbare
        - statement: ['termbare', '', ';']
          - command: termbare
          - terminator: ;
        - suffix: suffx
        - terminator: ;
        >>> print (c.parser.parseString('barecommand').dump())
        ['barecommand', '']
        - command: barecommand
        - statement: ['barecommand', '']
          - command: barecommand
        >>> print (c.parser.parseString('COMmand with args').dump())
        ['command', 'with args']
        - args: with args
        - command: command
        - statement: ['command', 'with args']
          - args: with args
          - command: command
        >>> print (c.parser.parseString('command with args and terminator; and suffix').dump())
        ['command', 'with args and terminator', ';', 'and suffix']
        - args: with args and terminator
        - command: command
        - statement: ['command', 'with args and terminator', ';']
          - args: with args and terminator
          - command: command
          - terminator: ;
        - suffix: and suffix
        - terminator: ;
        >>> print (c.parser.parseString('simple | piped').dump())
        ['simple', '', '|', ' piped']
        - command: simple
        - pipeTo:  piped
        - statement: ['simple', '']
          - command: simple
        >>> print (c.parser.parseString('double-pipe || is not a pipe').dump())
        ['double', '-pipe || is not a pipe']
        - args: -pipe || is not a pipe
        - command: double
        - statement: ['double', '-pipe || is not a pipe']
          - args: -pipe || is not a pipe
          - command: double
        >>> print (c.parser.parseString('command with args, terminator;sufx | piped').dump())
        ['command', 'with args, terminator', ';', 'sufx', '|', ' piped']
        - args: with args, terminator
        - command: command
        - pipeTo:  piped
        - statement: ['command', 'with args, terminator', ';']
          - args: with args, terminator
          - command: command
          - terminator: ;
        - suffix: sufx
        - terminator: ;
        >>> print (c.parser.parseString('output into > afile.txt').dump())
        ['output', 'into', '>', 'afile.txt']
        - args: into
        - command: output
        - output: >
        - outputTo: afile.txt
        - statement: ['output', 'into']
          - args: into
          - command: output
        >>> print (c.parser.parseString('output into;sufx | pipethrume plz > afile.txt').dump())
        ['output', 'into', ';', 'sufx', '|', ' pipethrume plz', '>', 'afile.txt']
        - args: into
        - command: output
        - output: >
        - outputTo: afile.txt
        - pipeTo:  pipethrume plz
        - statement: ['output', 'into', ';']
          - args: into
          - command: output
          - terminator: ;
        - suffix: sufx
        - terminator: ;
        >>> print (c.parser.parseString('output to paste buffer >> ').dump())
        ['output', 'to paste buffer', '>>', '']
        - args: to paste buffer
        - command: output
        - output: >>
        - statement: ['output', 'to paste buffer']
          - args: to paste buffer
          - command: output
        >>> print (c.parser.parseString('ignore the /* commented | > */ stuff;').dump())
        ['ignore', 'the /* commented | > */ stuff', ';', '']
        - args: the /* commented | > */ stuff
        - command: ignore
        - statement: ['ignore', 'the /* commented | > */ stuff', ';']
          - args: the /* commented | > */ stuff
          - command: ignore
          - terminator: ;
        - terminator: ;
        >>> print (c.parser.parseString('has > inside;').dump())
        ['has', '> inside', ';', '']
        - args: > inside
        - command: has
        - statement: ['has', '> inside', ';']
          - args: > inside
          - command: has
          - terminator: ;
        - terminator: ;
        >>> print (c.parser.parseString('multiline has > inside an unfinished command').dump())
        ['multiline', ' has > inside an unfinished command']
        - multilineCommand: multiline
        >>> print (c.parser.parseString('multiline has > inside;').dump())
        ['multiline', 'has > inside', ';', '']
        - args: has > inside
        - multilineCommand: multiline
        - statement: ['multiline', 'has > inside', ';']
          - args: has > inside
          - multilineCommand: multiline
          - terminator: ;
        - terminator: ;
        >>> print (c.parser.parseString('multiline command /* with comment in progress;').dump())
        ['multiline', ' command /* with comment in progress;']
        - multilineCommand: multiline
        >>> print (c.parser.parseString('multiline command /* with comment complete */ is done;').dump())
        ['multiline', 'command /* with comment complete */ is done', ';', '']
        - args: command /* with comment complete */ is done
        - multilineCommand: multiline
        - statement: ['multiline', 'command /* with comment complete */ is done', ';']
          - args: command /* with comment complete */ is done
          - multilineCommand: multiline
          - terminator: ;
        - terminator: ;
        >>> print (c.parser.parseString('multiline command ends\n\n').dump())
        ['multiline', 'command ends', '\n', '\n']
        - args: command ends
        - multilineCommand: multiline
        - statement: ['multiline', 'command ends', '\n', '\n']
          - args: command ends
          - multilineCommand: multiline
          - terminator: ['\n', '\n']
        - terminator: ['\n', '\n']
        >>> print (c.parser.parseString('multiline command "with term; ends" now\n\n').dump())
        ['multiline', 'command "with term; ends" now', '\n', '\n']
        - args: command "with term; ends" now
        - multilineCommand: multiline
        - statement: ['multiline', 'command "with term; ends" now', '\n', '\n']
          - args: command "with term; ends" now
          - multilineCommand: multiline
          - terminator: ['\n', '\n']
        - terminator: ['\n', '\n']
        >>> print (c.parser.parseString('what if "quoted strings /* seem to " start comments?').dump())
        ['what', 'if "quoted strings /* seem to " start comments?']
        - args: if "quoted strings /* seem to " start comments?
        - command: what
        - statement: ['what', 'if "quoted strings /* seem to " start comments?']
          - args: if "quoted strings /* seem to " start comments?
          - command: what
        rz[^=]�outputcSs$g|]}t|d�r|pt�|��qS)�parseString)r?rrQ)r!�trrrr��sz$Cmd._init_parser.<locals>.<listcomp>�
terminatorz
EOFcsg|]}tj|�jd��qS))�caseless)r�Keywordr�)r!�c)r
rrr��s�multilineCommandrp�|)�
identCharscSsdS)Nr[r)r�rrrr��r�z"Cmd._init_parser.<locals>.<lambda>)�ignore�pipeTocSs|d��S)Nr)r�)r�rrrr��r��outputTocSs|d��S)Nr)�lower)r�rrrr�r�cSs|d��S)Nr)r�)r�rrrr�r�cSs|d��S)Nr)r�)r�rrrr�r�rrtcSs|d��S)Nr)r�)r�rrrr�r�cSs|d��S)Nr)r�)r�rrrr�r��suffixcSs|d��S)Nr)r�)r�rrrr�!r��<cSsdS)Nr[r)r�rrrr�3r�z/\�	inputFromr�N)!rrQ�
redirector�	WordStart�Regex�Orr��	stringEnd�multilineCommandsr��Word�
legalCharsr��commentGrammarsr��quotedString�setParseAction�commentInProgress�Optional�SkipTor��blankLinesAllowed�NoMatchZblankLineTerminationParser�lineEndZblankLineTerminator�setResultsNameZmultilineParserZsingleLineParser�prefixParserrqr��inputParser)r
ZoutputParserZterminatorParserr�ZoneLineCommand�pipeZ
doNotParseZ
afterElementsZ	inputMark�fileNamer�r)r
rr�9sT5,
"
,
X	@.

.zCmd._init_parsercKs|S)Nr)r
�rawrrrr�preparseBszCmd.preparsecCs|S)Nr)r
ZparseResultrrr�	postparseEsz
Cmd.postparsec
Ks�t|t�r|}n�|j|f|�}|j�|���}|j�|�}x4|jD]*\}}|���	|�rB|�
||dd�}PqBW|j�|�}||d<|j
p�|j|d<|�|�}t|j�}||_|j|_x|��D]\}}	|	|j|<q�W|S)Nr�r�r�rp)r<r=r�r��transformString�lstripr�r�r�r��replacerqr�r�rpr�rror�)
r
r�r�p�sZshortcutZ	expansionrCr�r�rrrroHs&


z
Cmd.parsedcCsd}||fS)Nrr)r
rt�stoprrr�postparsing_precmd_szCmd.postparsing_precmdcCs|S)Nr)r
rrrr�postparsing_postcmdcszCmd.postparsing_postcmdcsTd}d�}|t|�kr|}n2|jrP�fdd�|jD�}t|�dkrPd|d}|S)Nr�csg|]}|���r|�qSr)r�)r!r�)r9rrr�msz"Cmd.func_named.<locals>.<listcomp>r�r)r��abbrevr�r�)r
r9rC�target�funcsr)r9rr�fszCmd.func_namedc
Cs
d}z�y�|�|�}|�|�\}}|r.|�|�S|jj|jkrL|j�|jj�zZ|�	|�t
j
��}|�|�}|�
|�}|�||�}|jr�|�dtt
j
��|��Wd|�|�XWnDtk
r�dStk
r�}z|�t|�|�Wdd}~XYnXWd|�|�S)NrzElapsed: %s)�complete_statementrrrorp�excludeFromHistoryr�rPr��redirect_output�datetime�nowZprecmd�onecmdZpostcmd�timingr�r��restore_outputr�rVr�)r
�linerrtZ	timestartrBrrr�onecmd_plus_hooksrs.





 &zCmd.onecmd_plus_hookscCs~|r t�|j��dd���|�s&t��|�|�}x:|jjrj|jjdkrjd|jj	|�
|j�f}|�|�}q2W|jjszt��|S)z<Keep accepting lines of input until the command is complete.cSsdS)Nr[r)r�rrrr��r�z(Cmd.complete_statement.<locals>.<lambda>r[z%s
%s)
rr�r�r�r�r�ror�r�r��pseudo_raw_input�continuation_promptrp)r
rrtrrrr
�s 
zCmd.complete_statementcCs�|jjrNt|d�|_ttd�|_tj|jjdtjtjd�|_	|j	j
t_|_n�|jjr�|jj
sjtsjtd��t|d�|_ttd�|_|jj
r�d}|jjd|jkr�d}ttj�|jj
�|�t_|_n.tjdd	�t_|_|jjd
kr�|j�t��dS)N)r/T)rer/rfzGCannot redirect to paste buffer; install ``xclip`` and re-run to enable�wrr"zw+)�modez>>)ror��Statekeeper�
kept_staterY�kept_sysr1r2r3�redirectrfr/r�r��can_clip�EnvironmentErrorr�r�r�r�r��tempfile�
TemporaryFilermr`)r
rtrrrrr�s& zCmd.redirect_outputcCs�|jr�|jjr2|jjs`|j�d�t|j���n.|jjr`x$|j	�
�D]}|jj�|pXd�qFW|j��|j�
�|j�
�d|_dS)Nrr[)rror�r�r/�seekrbrgr�rr5rmrn�restorer)r
rtrCrrrr�s


zCmd.restore_outputcCsf|�|�}|jj|_|�|jj�}|s0|�|�Syt||�}Wntk
rX|�|�SX||�}|S)a�Interpret the argument as though it had been typed in response
        to the prompt.

        This may be overridden, but should not normally need to be;
        see the precmd() and postcmd() methods for useful execution hooks.
        The return value is a flag indicating whether interpretation of
        commands by the interpreter should stop.

        This (`cmd2`) version of `onecmd` already override's `cmd`'s `onecmd`.

        )ror��lastcmdr�rp�_defaultr*r)r
rrtr�rDrrrrr�s


z
Cmd.onecmdcCs6|��}|jr&t�|�}|s&|�d�S|�|�|��S)N)rs�default_to_shellr��systemr�default)r
rtr9rCrrrr#�s

zCmd._defaultcCsx|jr.yt|�}Wqttk
r*d}YqtXnF|j�|�|j��|j��}t|�s\d}n|ddkrt|dd�}|S)zQcopied from cmd's cmdloop; like raw_input, but accounts for changed stdin, stdoutZEOFr�r�N)	�use_rawinput�	raw_input�EOFErrorr/rm�flushrf�readliner�)r
�promptrrrrr�s

zCmd.pseudo_raw_inputcCs2|��|jr\|jr\y2ddl}|��|_|�|j�|�|jd�Wnt	k
rZYnXz�|dk	rl||_
|j
r�|j�t
|j
�d�d}xT|s�|jr�|j�d�}n|�|j�}|jr�t|jt�r�|j�|d�|�|�}q�W|��Wd|j�r.|j�r.yddl}|�|j�Wnt	k
�r,YnX|S)z�Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.
        rNz
: completer�)Zpreloopr'Zcompletekeyr+Z
get_completerZ
old_completerZ
set_completerZcomplete�parse_and_bind�ImportError�intror/rmr�Zcmdqueue�poprr,�echor<rfr�rZpostloop)r
r/r+rrrrr�_cmdloop�s<	
zCmd._cmdloopcCs|jS)N)�_STOP_SCRIPT_NO_EXIT)r
r9rrr�do_EOFsz
Cmd.do_EOFcCs|jS)N)�_STOP_AND_EXIT)r
r9rrr�do_quit$szCmd.do_quit�
Your choice? c
	Cst|t�rt|��|���}g}xl|D]d}t|t�rD|�||f�q&y|�|d|df�Wq&tk
r�|�|d|df�Yq&Xq&Wx.t|�D]"\}\}}|�d|d|f�q�Wx@t|�}yt	|�}||dd}	PWq�t
k
r�Yq�Xq�W|	S)a�Presents a numbered menu to the user.  Modelled after
           the bash shell's SELECT.  Returns the item chosen.

           Argument ``options`` can be:

             | a single string -> will be split into one-word options
             | a list of strings -> will be offered as options
             | a list of tuples -> interpreted as (value, text), so
                                   that the return value can differ from
                                   the text advertised to the user rr�z
  %2d. %s
)r<�
basestring�zipr;rP�
IndexError�	enumerater�r(�int�
ValueError)
r
rSr,ZfulloptionsrJ�idx�value�text�responserCrrr�select*s*


 
z
Cmd.selectz-lz--long�
store_truezdescribe function of parameter)�actionr�cCs�|����}i}d}xH|jD]>}|r.|�|�rd|tt||��f||<t|t||��}qW|r�xVt|�D]<}|j	r�|�
d||�|�|j|f�ql|�
||�qlWntd|��dS)zShows value of a parameter.rz%s: %sz%s # %szBParameter '%s' not supported (type 'show' for list of parameters).N)
r�r�r�r�r�r*�maxr�r��longr�r��NotImplementedError)r
r9rA�paramrC�maxlenrrrr�do_showLs$zCmd.do_showc
sH�y|jj�dd�\}�}|��}�������|jkrl�fdd�|jD�}t|�dkrb|d�n
|���St|��}|d|dkr�|ddkr�|dd�}n
t	||�}t
|�|�|j�d	�||f�||k�ryt|d
��}|||d�Wnt
k
�r
YnXWn4tt
tfk
�rB}z|�|�Wdd}~XYnXdS)z�
        Sets a cmd2 parameter.  Accepts abbreviated parameter names so long
        as there is no ambiguity.  Call without arguments for a list of
        settable parameters with their values.Nrcsg|]}|���r|�qSr)r�)r!r)�	paramNamerrr�iszCmd.do_set.<locals>.<listcomp>r�rr�)�'�"z%s - was: %s
now: %s
z_onchange_%s)�oldrr)ror�r;r�r�r�r�rJr*�cast�setattrr/rmrr=�NotSettableError)r
r9rtr��hitsZ
currentValZ
onchange_hookrBr)rKr�do_set_s.






z
Cmd.do_setcCst|d�dS)zDDisplays the specified text then waits for the user to press RETURN.r�N)r()r
r9rrr�do_pause~szCmd.do_pausecCst�|�dS)z)execute a command as if at the OS prompt.N)r�r%)r
r9rrr�do_shell�szCmd.do_shellcs
��jd<|jjdd���}�jr*�jp,i}t|d����d�|��rV��|�n�dd�}�fdd	�}��fd
d�}|�jd<|�jd
<|�jd<|�jd<yHd}ttd�}�j	t_	�j
t_
�jdtjtj
|�jj�jjfd�Wntk
r�YnX|��dS)aI
        py <command>: Executes a Python command.
        py: Enters interactive Python mode.
        End with ``Ctrl-D`` (Unix) / ``Ctrl-Z`` (Windows), ``quit()``, '`exit()``.
        Non-python commands can be issued with ``cmd("your command")``.
        Run python code from external files with ``run("filename.py")``
        r
rN)�localsz.import sys, os;sys.path.insert(0, os.getcwd())cSst�dS)N)r�rrrr�quit�szCmd.do_py.<locals>.quitcs��|d�S)Nr�)r)r9)r
rrr�sz$Cmd.do_py.<locals>.onecmd_plus_hooksc
sTy"t|�}��|���|��Wn,tk
rN}z��|�Wdd}~XYnXdS)N)r��runcodergrnr�r�)r9r�rB)�interpr
rr�run�szCmd.do_py.<locals>.runrWrr�rZzFType "help", "copyright", "credits" or "license" for more information.)rfr/zPython %s on %s
%s
(%s)
%s)Zbanner)r�ror�r��locals_in_pyrrXrrYr/rfZinteract�versionrZ�	__class__r�do_pyrr�r!)r
r9Z	localvarsrWrrZZcprt�	keepstater)rYr
rr^�s2







$z	Cmd.do_pyz-sz--scriptz"Script format; no separation linesz$(limit on which commands to include))rKcCsL|r|j�|�}n|j}x.|D]&}|jr4|�|�q|j�|���qWdS)ahistory [arg]: lists past commands issued

        | no arg:         list all
        | arg is integer: list one history item, by index
        | arg is string:  string search
        | arg is /enclosed in forward-slashes/: regular expression search
        N)r��get�scriptr�r/rm�pr)r
r9rAr��hirrr�
do_history�s
zCmd.do_historycCs<y"|r|j�|�dS|jdSWntk
r6dSXdS)Nr�)r�r`r:)r
r9rrr�
last_matching�szCmd.last_matchingcCsVy|j�|pd�}Wn tk
r4|j�|�}YnXx|D]}|�|���q<WdS)ailist [arg]: lists last command issued

        no arg -> list most recent command
        arg is integer -> list one history item, by index
        a..b, a:b, a:, ..b -> list spans from a (or start) to b (or end)
        arg is string -> list all commands matching string search
        arg is /enclosed in forward-slashes/ -> regular expression search
        z-1N)r��spanr:r%r�rb)r
r9r�rcrrr�do_list�s	
zCmd.do_listcCs�|jstd��|j}|rJy|�t|��}WqTtk
rF|}d}YqTXn
|jd}|r�ttj	�
|�d�}|�|ptd�|��t�
d|j|f�|�|�dS)a8ed: edit most recent command in text editor
        ed [N]: edit numbered command from history
        ed [filename]: edit specified file name

        commands are run after editor is closed.
        "set edit (program-name)" or set  EDITOR environment variable
        to control which editing program is used.zGPlease use 'set editor' to specify your text editing program of choice.r[r�rz%s %sN)r7r�default_file_namerer<r=r�r�r�r�r�rmrnr%�do__load)r
r9�filename�buffer�frrr�do_ed�s 
z	Cmd.do_ed�*r>z/\r�c
Csy|j�|�}Wn0tjk
r@|�d|�t|jj��YnX|jpL|j	}|j
dkrnd�|jdd��}n&|j
r�|jt
|j
�d}n
|jd}y6ttj�|�d�}|�|�|��|�d|�Wn2tk
r�}z|�d	|��Wdd}~XYnXdS)
z�`save [N] [filename.ext]`

        Saves command from history to file.

        | N => Number of command (from history), or `*`;
        |      most recent command if omittedz#Could not understand save target %srnz

Nr�r�rzSaved to %szError saving %s)�
saveparserr�r�ParseExceptionr��SyntaxError�do_saverr�rhr>r$r�r<r�r�r�r�rmrnr�rV)r
r9rr�ZsavemerlrBrrrrr
s&


zCmd.do_savecCs�t|t�rt|d�}nv|j�|�}|r8t�|�d��}nTtj	�
|�}yttj	�
|�d�}Wn0tk
r�tdtj	�
|�|jfd�}YnX|S)N�rr�z%s.%s)
r<r�r��urlre�match�urllib�urlopen�groupr�r�r�r��defaultExtension)r
r�rCrurrr�read_file_or_url*s
"zCmd.read_file_or_urlcCsZ|rV|�dd�}|d|dd�p&dgd}}tj�|jp>d|�}|�d||f�dS)z�
        Runs commands in script at file or URL; if this is called from within an
        already-running script, the filename will be interpreted relative to the
        already-running script's directory.Nr�rr[z%s %s)r;r�r�r$�current_script_dirri)r
r9�
targetnamerrrr�do__relative_load:s
 zCmd.do__relative_loadz(https?://[-\w\./]+)c
Cs�|dkr|j}n0|�dd�}|d|dd�p2dgd��}}y|�|�}Wn4tk
r�}z|�d||f�dSd}~XYnXt|d�}||_d|_d|_	|_
tj�|�d|_
|��}|j��|��d|_|o�||jkS)z-Runs script of command(s) from a file or URL.Nr�rr[z%Problem accessing script from %s: 
%s)rfr'r,rr{F)rhr;r�rzr�r�rrfr'r,rr�r�r{r2rnr!r"r3)r
r9r|rrrBr_rrrr�do_loadGs&$

zCmd.do_loadcCs&|�|�}|�|�|r"|�|�}dS)arun [arg]: re-runs an earlier command

        no arg -> run most recent command
        arg is integer -> run one history item, by index
        arg is string -> run most recent command by string search
        arg is /enclosed in forward-slashes/ -> run most recent by regex
        N)rer�r)r
r9Zrunmerrrr�do_run`s	

z
Cmd.do_runcCsNyttj�|��}Wn$tk
r8|j�d|�dSX|��}|��|S)NzCouldn't read from file %s
r[)	r�r�r�r�r�r/rmrgrn)r
rt�sourcerl�datarrr�
fileimportpszCmd.fileimportcsNG�fdd�dt�}|�j_tjdgt_|�}t��}|�|�}|��dS)NcseZdZ�jZdS)z-Cmd.runTranscriptTests.<locals>.TestMyAppCaseN)rrrr]�CmdAppr)r
rr�
TestMyAppCase{sr�r)	�Cmd2TestCaser]�	testfilesrY�argv�unittestZTextTestRunnerrZZprintErrors)r
�callargsr�Ztestcase�runnerrCr)r
r�runTranscriptTestszs
zCmd.runTranscriptTestscCs&x |D]}|�|d�r|jSqWdS)Nr�)rr5)r
r�Zinitial_commandrrr�run_commands_at_invocation�s
zCmd.run_commands_at_invocationcCsPt��}|jdddddd�|��\}}|jr:|�|�n|�|�sL|��dS)Nz-tz--test�testrCz1Test against transcript(s) in FILE (wildcards OK))�destrDr�)rr	rGr:r�r�r�r2)r
rqZcalloptsr�rrr�cmdloop�s
zCmd.cmdloop)N)N)r7)N)N)urrrr1r�rrr�	alphanums�
alphas8bitr�r�r;rr$ZnoSpecialParseryrhrr{r�r�r�r�r[rr�r{r�r�r�r�r5r3r��environr`r7rYrZr8r�r%r�r�r�r�rWr��Emptyr�r��pythonStyleComment�
cStyleCommentr��addParseActionrQr�r�r�r�r�r�r�r�r�rorrr�rr
rrrr#rr2r4Zdo_eofr6Zdo_exitZdo_qrBrSrrJrSrTrUr^rdrergZdo_hiZdo_lZdo_lirmZdo_editr�r��numsrorrrzr}r�compilertr~rirZdo_rr�r�r�r�rrrrr��s�
	
	
,
"0	8



r�c@s eZdZdZdd�Zdd�ZdS)�HistoryItemz!-------------------------[%d]
%s
cCst�|�|��|_d|_dS)N)r�rWr��	lowercaser>)r
�instrrrrrW�s

zHistoryItem.__init__cCs|j|jt|�fS)N)�
listformatr>r�)r
rrrrb�szHistoryItem.prN)rrrr�rWrbrrrrr��sr�c@s^eZdZdZdd�Zdd�Zdd�Ze�d�Z	d	d
�Z
e�d�Zdd
�Zdd�Z
ddd�ZdS)r�abA list of HistoryItems that knows how to respond to user requests.
    >>> h = History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
    >>> h.span('-2..')
    ['third', 'fourth']
    >>> h.span('2..3')
    ['second', 'third']
    >>> h.span('3')
    ['third']
    >>> h.span(':')
    ['first', 'second', 'third', 'fourth']
    >>> h.span('2..')
    ['second', 'third', 'fourth']
    >>> h.span('-1')
    ['fourth']
    >>> h.span('-2..-3')
    ['third', 'second']
    >>> h.search('o')
    ['second', 'fourth']
    >>> h.search('/IR/')
    ['first', 'third']
    cCs|}|dkr|d8}|S)Nrr�r)r
ZonebasedrCrrr�zero_based_index�szHistory.zero_based_indexcCs|r|�t|��}nd}|S)N)r�r<)r
r�rCrrr�to_index�szHistory.to_indexcsl|��}|d|dkr$dkrBnnt|�dkrB|dd�}n
t�|�}t�|tj���fdd�|D�S)Nrr��/r�csg|]}��|�r|�qSr)r%)r!r)r(rrr��sz"History.search.<locals>.<listcomp>)r�r�rr r��
IGNORECASE)r
rr)r(rr%�s,
zHistory.searchzJ^\s*(?P<start>\-?\d+)?\s*(?P<separator>:|(\.{2,}))?\s*(?P<end>\-?\d+)?\s*$cCs�|��dkrd}|j�|�}|s$t�|�d�sD||�|�d��gS|�|�d��}|�|�d��}d}|dk	r�||kr�||}}d}|d7}|||�}|r�|��|S)	N)rn�-�all�:�	separatorr&�endFTr�)r��spanpatternr%r:rxr�r�)r
r��resultsr&r�r�rCrrrrf�s&

zHistory.spanz0^\s*(?P<start>[\d]+)?\s*\-\s*(?P<end>[\d]+)?\s*$cCs"t|�}t�||�t|�|_dS)N)r�rNrPr�r>)r
rrrrrrP�szHistory.appendcCsx|D]}|�|�qWdS)N)rP)r
rr�nrrr�extend�s
zHistory.extendNFcs&�s|Sy2t����dkr*|dd��S|�dgSWn�tk
rNgStk
�r |j���}|r�|�d�pzd}|�d�p�d}|r�t|�d}|r�t|�}|||�S������d��r��d��rt	�
�dd�t	jt	jBt	j
B���fdd��n�fdd���fd	d
�|D�SXdS)Nrr�r�r&r�cs
��|�S)N)r%)rc)�finderrr�isin
szHistory.get.<locals>.isincs���|jkS)N)r�r�)rc)�getmerrr�scsg|]}�|�r|�qSrr)r!Zitm)r�rrr�szHistory.get.<locals>.<listcomp>)r<r:r=�rangePatternr%rxr�r��endswithrr��DOTALL�	MULTILINEr�)r
r�ZfromEndZrangeResultr&r�r)r�r�r�rr`�s2"zHistory.get)NF)rrrrr�r�r%rr�r�rfr�rPr�r`rrrrr��s	

r�c@seZdZdS)rQN)rrrrrrrrQsrQc	Cs�t|�}|tkr�ytt|��Sttfk
r4YnXy|��}Wntk
rVYnX|dksl|ddkrpdS|dks�|ddkr�dSny||�Stk
r�YnXtd||f�|S)	z=Tries to force a new value into the same type as the current.�onr)�yr�T�off)r�rlFz9Problem setting parameter (now %s) to %s; incorrect type?)�type�boolr<r=r^r�rVr)�currentrr�typrrrrOs(rOc@s$eZdZdd�Zdd�Zdd�ZdS)rcCs||_||_|jr|��dS)N)r+�attribs�save)r
r+r�rrrrW6szStatekeeper.__init__cCs(x"|jD]}t||t|j|��qWdS)N)r�rPr*r+)r
�attribrrrr�<szStatekeeper.savecCs.|jr*x"|jD]}t|j|t||��qWdS)N)r+r�rPr*)r
r�rrrr!@szStatekeeper.restoreN)rrrrWr�r!rrrrr5src@seZdZdZiZdd�ZdS)�BorgzcAll instances of any Borg subclass will share state.
    from Python Cookbook, 2nd Ed., recipe 6.16cOstj|f|�|�}|j|_|S)N)�object�__new__�
_shared_state�__dict__)r�r"�kr+rrrr�LszBorg.__new__N)rrrrr�r�rrrrr�Fsr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
OutputTrapz�Instantiate  an OutputTrap to divert/capture ALL stdout output.  For use in unit testing.
    Call `tearDown()` to return to normal output.cCsd|_tj|_|t_dS)Nr[)�contentsrYr/�
old_stdout)r
rrrrWVszOutputTrap.__init__cCs|j|7_dS)N)r�)r
rarrrrm[szOutputTrap.writecCs|j}d|_|S)Nr[)r�)r
rCrrrrg^szOutputTrap.readcCs|jt_d|_dS)Nr[)r�rYr/r�)r
rrr�tearDowncszOutputTrap.tearDownN)rrrrrWrmrgr�rrrrr�Rs
r�c@s�eZdZdZdZdd�Zdd�Zdd�Zej	d	d
ddd�Z
e
�ej�e�
ej�Ze�d
d��e
eBZe�dejejB�Zdd�Zdd�ZdS)r�z�Subclass this, setting CmdApp, to make a unittest.TestCase class
       that will execute the commands in a transcript file and expect the results shown.
       See example.pyNcCsdi|_xF|jjD]:}x4t�|�D]&}t|�}t|���|j|<|��q WqWt|j�s`t	d��dS)Nz&No test files found - nothing to test.)
�transcriptsr�r��globr��iter�	readlinesrnr��
StandardError)r
Zfilesetr�Ztfilerrr�fetchTranscriptsos
zCmd2TestCase.fetchTranscriptscCs$|jr t�|_|��|_|��dS)N)r�r��
outputTrap�cmdappr�)r
rrr�setUpys
zCmd2TestCase.setUpcCs6|jr2t|j���}x|D]\}}|�||�qWdS)N)r�r�r�r��_test_transcript)r
Zitsr��
transcriptrrr�runTestszCmd2TestCase.runTestr��\T)�	quoteChar�escChar�	multiline�unquoteResultscCst�|d�S)Nr)rr )r�rrrr��r�zCmd2TestCase.<lambda>z\scCsd}d}t�|�}|d7}d}�x�|�s
xD|�|jj�slyt�|�}Wntk
r`d}PYnX|d7}q*W|t|jj�d�g}t�|�}xh|�|jj�r�|�|t|jj�d��yt�|�}Wn$tk
r�td|df�YnX|d7}q�Wd�	|�}|j�
|�}|j��}	|�|jj��rLd||||	f}
|�
|	��|
�q"g}xT|�|jj��s�|�|�yt�|�}Wntk
�r�d}PYnX|d7}�qRWd�	|�}d|||||	f}
|j�|�}|j�d|�}|j�d|	�}	|�
t�||	tjtjB�|
�q"WdS)	NrFr�TzGTranscript broke off while reading command beginning at line %d with
%sr[z>
File %s, line %d
Command was:
%r
Expected: (nothing)
Got:
%r
z7
File %s, line %d
Command was:
%s
Expected:
%s
Got:
%s
)r�nextr�r�r,�
StopIterationr�rrPr$rr�rgZassert_r��expectationParserr��
anyWhitespace�subrrur�r�)r
r�r�ZlineNum�finishedrZ	tests_runrprrC�message�expectedrrrr��sl






zCmd2TestCase._test_transcriptcCs|jr|j��dS)N)r�r�r�)r
rrrr��szCmd2TestCase.tearDown)rrrrr�r�r�r�r�QuotedStringZregexPatternr�r�r��
printablesZnotRegexPatternr�r�rr�r�r�r�r�r�rrrrr�hs
Cr��__main__)Zoptionflags)r9)r�)Vrr�rr�rYrr1r�doctestr�r
rvr�r�rZrzZexabgp.vendoringr�coderrrr�__version__�version_info�
ParserElement�
enablePackratrVr�r	r)r-r8�Valuesr`rOrSrrTrcZ	mswindowsr\r`rbr.r�
check_callr3�CalledProcessErrorr6r�rZ
teststringr2rkrfrmrnr/rg�setDefaultWhitespaceCharsr�r=rvrur{r��
SystemExitr�r�r�r�r�rNr�rQrOr�rr�r�ZTestCaser�r�testmodZNORMALIZE_WHITESPACErrrr�<module>s�


7	



8

rul