403Webshell
Server IP : 35.80.110.71  /  Your IP : 216.73.216.221
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.3.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/apsw/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/apsw/__pycache__/shell.cpython-312.pyc
�

��f���.�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZGd�d�Z	ddlZddlZd
d�Zed	k(re�yy#eef$rdD]Zeede����eed�Y�7wxYw)�N)�TextIO�Optionalc��	�eZdZdZGd�de�Z						d�deedefd�Z	d�Z
d	�Zd
�Ze
eedd�Zd�Zd
�Zd�ZdD���cgc]
}t%|���c}}}Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZeZd�Zd�Zd�Zd�Zd�Z e Z!d�Z"d�Z#d�Z$dZ%d�Z&d e&_'d!�Z(d"�Z)d#�Z*d�d$�Z+d%�Z,d&�Z-d�d'�Z.d(�Z/d)�Z0d*�Z1d+�Z2d,�Z3d-�Z4d.�Z5d/�Z6gfd0�Z7e7Z8d1�Z9hd2�Z:d3�Z;d4�Z<d5�Z=d6�Z>d7�Z?d8�Z@d9�ZAd:�ZBd;�ZCd<�ZDeDZEdZFd=�ZGd>�ZHd?�ZId@�ZJdA�ZKdB�ZLdC�ZMdD�ZNdE�ZOdF�ZPdZQdG�ZRdH�ZSdI�ZTdJ�ZUdK�ZVdL�ZWdM�ZXdN�ZYdO�ZZdP�Z[dQ�Z\dR�Z]dS�Z^dTZ_dU�Z`dV�ZadW�ZbdX�ZcdY�ZddZ�Zed[�Zfd\�Zgd]�Zhd^�Zid_�Zjd`�Zkda�Zldb�Zmdc�Zndd�Zode�Zpdf�Zqerj�fdg�ZteuZvd�dh�Zwdi�Zxdj�Zydk�Zzdl�Z{dm�Z|dn�Z}erj�ZeZ�eD��cgc]}|do|dpvz��c}}Zdq�j�Z�drZ�idsd�dtd�dudv�dwe��dxd�dyd�dze��d{e��d|e��d}e��d~d�dd�d�d�d�d�d�e��d�d��d�d�id�d�d�e��d�d�d�e��d�d�d�d�d�e��d�d�d�d�d�d�d�d�d�d�d�d��d�d�d�e��d�e��d�d���id�d�d�d�d�d�d�d�d�d�d�d�d�e��d�d�d�e��d�e��d�e��d�d�d�e��d�d�d�d�d�d��d�d��ddd�de�ddde�d��	�Z�d��Z�d��Z�e�e�e�e�e�e�d��Z�e�d�e�d�<dZ�d��Z�d��Z�d��Z�d��Z�Gd��d��Z�e��die�id�d��d�d��d�d��d�d��d�d��d�dÓd�dœd�dǓd�dɓd�d˓d�d͓d�dϓd�dѓd�dӓd�dՓd�dדd�dٓd�d�d�d�d�d�d�d�d���j!�D����cgc]\}}|d�t|�zd�zf��c}}}}���Z�d�e�d���iZ�e��did�e��j&�d�e��j(�d�e��j*e��j&z�d�e��j(e��j,z�d�e��j.e��j&z�d�e��j(e��j,z�d�e��j0�d�e��j,�d�e��j.e��j&z�d�e��j(e��j,z�d�e��j2�d�e��j4�d�e��j*�d�e��j,�d�e��j6�d�e��j,�d�e��j.�d�e��j,�d�e��j8�d�e��j,��e�d�<[�[�	[�[�[�ycc}}}wcc}}wcc}}}}w#e$rYywxYw(�Shella:Implements a SQLite shell

    :param stdin: Where to read input from (default sys.stdin)
    :param stdout: Where to send output (default sys.stdout)
    :param stderr: Where to send errors (default sys.stderr)
    :param encoding: Default encoding for files opened/created by the
      Shell.  If you want stdin/out/err to use a particular encoding
      then you need to provide them `already configured <https://docs.python.org/library/codecs.html#codecs.open>`__ that way.
    :param args: This should be program arguments only (ie if
      passing in sys.argv do not include sys.argv[0] which is the
      program name.  You can also pass in None and then call
      :meth:`process_args` if you want to catch any errors
      in handling the arguments yourself.
    :param db: A existing :class:`~apsw.Connection` you wish to use

    The commands and behaviour are modelled after the `interactive
    shell <https://sqlite.org/sqlite.html>`__ that is part of
    SQLite.

    You can inherit from this class to embed in your own code and user
    interface.

    Errors and diagnostics are only ever sent to error output
    (self.stderr) and never to the regular output (self.stdout).  This
    means using shell output is always easy and consistent.

    Shell commands begin with a dot (eg .help).  They are implemented
    as a method named after the command (eg command_help).  The method
    is passed one parameter which is the list of arguments to the
    command.

    Output modes are implemented by functions named after the mode (eg
    output_column).

    When you request help the help information is automatically
    generated from the docstrings for the command and output
    functions.

    You should not use a Shell object concurrently from multiple
    threads.  It is one huge set of state information which would
    become inconsistent if used simultaneously, and then give baffling
    errors.  It is safe to call methods one at a time from different
    threads.  ie it doesn't care what thread calls methods as long as
    you don't call more than one concurrently.
    c��eZdZdZy)�Shell.Errorz�Class raised on errors.  The expectation is that the error
        will be displayed by the shell as text so there are no
        specific subclasses as the distinctions between different
        types of errors doesn't matter.N)�__name__�
__module__�__qualname__�__doc__���,/usr/lib/python3/dist-packages/apsw/shell.py�ErrorrLs��	+�	
rrN�stdin�encodingc��d|_d|_i|_d|_d|_|r||j
f|_nd|_t�|_d|_	d|_
d|_d|_d|_
d|_d|_d|_d|_|j$|_|j)d	�|_g|_d
|_g|_|j3|�|xst4j6|_|xst4j8x|_|_|xst4j<|_|j?�r:tA|d�r.|jB|_ddd
d|jEd�d
d�|_#d|_$|jK�d|_&g|_'d|_(|jS�|jU�|jW�g|_,|r	|j[|�|jH�|j?�|_$yy#t\$rBt_|jX�r|jXjad�|jc��wxYw)z9Create instance, set defaults and do argument processing.Fz~/.sqlite_historyN�NNzsqlite> z    ..> �|��tableT�
output_box��NULL�� )�quote�string_sanitize�null�truncate�
text_width�use_unicoderz!Processing command line arguments)2�
exceptions�history_file�bindings�_db�
dbfilename�filename�db�set�
db_references�prompt�
moreprompt�	separator�bail�changes�echo�timer�header�	nullvalue�output_list�output�_fmt_sql_identifier�
_output_table�widthsr �
_output_stack�set_encoding�sysr�stdout�_original_stdout�stderr�_using_a_terminal�hasattrr�_terminal_width�box_options�interactive�command_colour�_using_readline�_input_stack�input_line_number�_calculate_output_modes�
push_input�push_output�_input_descriptions�process_args�	Exception�len�append�handle_exception)�selfrr=r?r�argsr)s       r�__init__zShell.__init__Ss&�� ���/�����
�������
��"�+�+�o�D�G� �D�G� �U��� ���$��������	������	���
��������&�&���!�5�5�g�>��������
����	
���(�#��'�c�i�i��
�.4�.B��
�
�B������*��
�
����!�!�#���l�(C��/�/�D�K��#$�� �"�2�2�2�6�#�
 �D�� �������$������!"����$�$�&���������#%�� ��
��!�!�$�'����#�#�5�5�7�D��$��
�
��t�/�/�0��,�,�3�3�4W�X��%�%�'��	
�s
�H�AIc���t|jdd�xrO|jj�xr3t|jdd�xr|jj�S)N�isatty)�getattrrrVr=�rRs rr@zShell._using_a_terminal�sc���t�z�z�8�T�2�v�t�z�z�7H�7H�7J�v�w�W[�Wb�Wb�dl�W[�P]�v�ae�al�al�as�as�au�	vrc��|jsi|jsd|_tj|jtjtj
ztjz��|_|jS)zQThe database isn't opened until first use.  This function ensures it is now open.z:memory:��flags)r&r'�apsw�
Connection�SQLITE_OPEN_URI�SQLITE_OPEN_READWRITE�SQLITE_OPEN_CREATErXs r�
_ensure_dbzShell._ensure_db�s\���x�x��?�?�",������t���-1�-A�-A�D�D^�D^�-^�)-�)@�)@�.A�B�D�H��x�x�rc��|\}}|jr"|jjd�d|_||_||_y)z-Sets the open database (or None) and filenameTN)r&�closer')rR�newvr)r's    r�_set_dbz
Shell._set_db�s8�����Z��8�8��H�H�N�N�4� ��D�H����$��rz%The current :class:`~apsw.Connection`c��|sdggfSd}d}g}g}|�rn|r|djd�s-d}|sd|df|_d}n|j|d�|dd}�F|ddd|d<|djd�r|ddd|d<|ddk(r9t|�dkr|j	d	��|j|d�|dd}��|dd
k(s|ddk(r|dd
k(|_|dd}��|ddvrt
||dd�|dd}��|dd
k(rd|_|dd}��|ddvrHt|�dkr|j	d|dz��t|d|dz�|dg�|dd}��V|ddk(rF|j|jtj�dz�tjd�|ddk(r?|j|j|j!��tjd�|ddvrd|_|j%�|dd}��t|d|dzd�r|j'|dd�|dd}��>|j)|�}|�|j	d|dzdz��|}|r��n|D]}|j+|g��|D]}|j-|��|j.||fS)a�Process command line options specified in args.  It is safe to
        call this multiple times.  We try to be compatible with SQLite shell
        argument parsing.

        :param args: A list of string options.  Do not include the
           program as args[0]

        :returns: A tuple of (databasefilename, initfiles,
           sqlncommands).  This is provided for informational purposes
           only - they have already been acted upon.  An example use
           is that the SQLite shell does not enter the main interactive
           loop if any sql/commands were provided.

        The first non-option is the database file name.  Each
        remaining non-option is treated as a complete input (ie it
        isn't joined with others looking for a trailing semi-colon).

        The SQLite shell uses single dash in front of options.  We
        allow both single and double dashes.  When an unrecognized
        argument is encountered then
        :meth:`process_unknown_args` is called.
        NTFr�-r�init�z*You need to specify a filename after -initr3�noheader)r1r/rD�batch)r.r4rz#You need to specify a value after -�command_�version�
�help)z	no-colourzno-color�nocolour�nocolor�off�output_zUnrecognized argument '�')�
startswithr)rPrOrr3�setattrrDrW�writer=r\�sqlitelibversionr<�exitr?�usage�
colour_scheme�_out_colour�command_mode�process_unknown_args�command_read�process_complete_liner')	rRrS�options�
havedbname�inits�sqls�newargs�f�ss	         rrMzShell.process_args�s;��2���R�<�����
�������$�q�'�"4�"4�S�"9���!�"�D��G�m�D�G�!%�J��K�K��Q��(��A�B�x����1�g�a�b�k�D��G��A�w�!�!�#�&��q�'�!�"�+��Q���A�w�&� ��t�9�q�=��*�*�%Q�R�R����T�!�W�%��A�B�x����A�w�(�"�d�1�g��&;�"�1�g��1����A�B�x����A�w�9�9���d�1�g�t�,��A�B�x����A�w�'�!�#(�� ��A�B�x����A�w�@�@��t�9�q�=��*�*�%J�T�RS�W�%T�U�U�3���j�4��7�2�3�T�!�W�I�>��A�B�x����A�w�)�#��
�
�4�;�;��(=�(=�(?�$�(F�G�������A�w�&� ��
�
�4�;�;��
�
��5�������A�w�J�J�%*��"�� � �"��A�B�x����t�Y��a��0�$�7��!�!�$�r��(�+��A�B�x����/�/��5�G����j�j�!:�T�!�W�!D�s�!J�K�K��D�M�P�	#�A����q�c�"�	#��	*�A��&�&�q�)�	*�����t�+�+rc��y)aDThis is called when :meth:`process_args` encounters an
        argument it doesn't understand.  Override this method if you
        want to be able to understand additional command line arguments.

        :param args: A list of the remaining arguments.  The initial one will
           have had the leading dashes removed (eg if it was --foo on the command
           line then args[0] will be "foo"
        :returns: None if you don't recognize the argument either.  Otherwise
           return the list of remaining arguments after you have processed
           yours.
        Nr
)rRrSs  rr~zShell.process_unknown_args2s��rc�&�d}|j�S)z>Returns the usage message.  Make sure it is newline terminateda�
Usage: python3 -m apsw [OPTIONS] FILENAME [SQL|CMD] [SQL|CMD]...
FILENAME is the name of a SQLite database. A new database is
created if the file does not exist. If omitted or an empty
string then an in-memory database is created.
OPTIONS include:

   -init filename       read/process named file
   -echo                print commands before execution
   -[no]header          turn headers on or off
   -bail                stop after hitting the first error
   -interactive         force interactive I/O
   -batch               force batch I/O
   -column              set output mode to 'column'
   -csv                 set output mode to 'csv'
   -html                set output mode to 'html'
   -line                set output mode to 'line'
   -list                set output mode to 'list'
   -python              set output mode to 'python'
   -separator 'x'       set output field separator (|)
   -nullvalue 'text'    set text string for NULL values
   -version             show SQLite version
   -encoding 'name'     the encoding to use for files
                        opened via .import, .read & .output
   -nocolour            disables interactive colour output
)�lstrip)rR�msgs  rrzzShell.usage@s����4�z�z�|�rz[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()`_-+={}[]:;,.<>/?|c��t|t�r�dg}|D]�}|dk(r|jd��|dk(r|jd��1|dk(r|jd��H|dk(r|jd	��_t|�|jvr|jd|z���|j|���|jd�d
j|�S|�d|jzdzSt|t�r|d�}t}dg}|D]I}||�|jvr|j||���/|jd||�fz��K|jd�d
j|�Sd|�d�S)
z8Format as a C string including surrounding double quotes�"�\�\\�
�\rrn�\n�	�\trc��|S�Nr
��xs r�<lambda>z%Shell._fmt_c_string.<locals>.<lambda>�s��!�r�\x%02X)	�
isinstance�strrP�ord�
_printable�joinr4�bytes�chr)rR�v�op�c�o�fromc�ress       r�
_fmt_c_stringzShell._fmt_c_stringjsX���a�����B��
!����9��I�I�f�%��$�Y��I�I�e�$��$�Y��I�I�e�$��$�Y��I�I�e�$���V�4�?�?�2��I�I�d�Q�h�'��I�I�a�L�
!�
�I�I�c�N��7�7�2�;��
�Y�����'�#�-�-�
��5�
!��A��E��%�C��
5���Q�4�4�?�?�*��J�J�u�Q�x�(��J�J�y�A�a�D�8�3�4�	
5�

�J�J�s�O��7�7�3�<��"��>�!rc���|j|�jdd�jdd�jdd�jdd�jd	d
�S)z%Format as HTML (mainly escaping &/</>�&z&amp;�>z&gt;�<z&lt;rtz&apos;r�z&quot;)�
_fmt_text_col�replace�rRr�s  r�
_fmt_html_colzShell._fmt_html_col�sQ���!�!�!�$��7�3�� ��7�3����7�3����7�3��!��7�3��!�	"rc��t|t�r�dg}|D]�}|dk(r|jd��|dk(r|jd��1|dk(r|jd��H|dk(r|jd	��_|d
k(r|jd��v|dk(r|jd|z���|dk(r|jd���|d
k(r|jd
���|j|���|jd�dj|�S|�yt|t�r9tj|�jd�}|ddk(r|dd}d|zdzSt|�S)zFormat a value.r�r�r�r�r�rnr�r�r��/z\/z\bz\frNr�ascii���)r�r�rPr�r��base64�encodebytes�decode)rRr�r�r�r�s     r�_fmt_json_valuezShell._fmt_json_value�sB���a�����B��
!����9��I�I�f�%��$�Y��I�I�e�$��$�Y��I�I�e�$��$�Y��I�I�e�$��#�X��I�I�e�$��#�X��I�I�d�Q�h�'��%�Z��I�I�e�$��%�Z��I�I�e�$�
�I�I�a�L�+
!�,
�I�I�c�N��7�7�2�;��
�Y��
��5�
!��"�"�1�%�,�,�W�5�A���u��}��c�r�F����7�S�=� ��q�6�Mrc�8�|�yt|t�rt|�St|t�rjdg}|D]@}||jvr|jt
|���,|jd|fz��B|jd�dj|�S|�S)zFormat as python literal�Nonezb"r�r�r)r�r��reprr�r�rPr�r�)rRr�r��is    r�_fmt_pythonzShell._fmt_python�s����9��
��3�
���7�N�
��5�
!��&�C��
2������'��J�J�s�1�v�&��J�J�y�A�5�0�1�	
2�

�J�J�s�O��7�7�3�<���rc���t|�sytjdd|�}t|�dk(r%|j�|jvr	|ddvr|Sd|vrd|�d�Sd|�d�S)	zPReturn the identifier quoted in SQL syntax if needed (eg table and column names)z""z
[A-Za-z_0-9]+rr�
0123456789r��[�])rO�re�sub�upper�_sqlite_reserved)rRr��nonalnums   rr7zShell._fmt_sql_identifier�sk���1�v���6�6�/�2�q�1���x�=�A���w�w�y�� 5� 5�5��Q�4�|�+��H��(�?��>�!���~�rc�j�|�|jSt|t�r|St|t�ry|�S)zRegular text formattingz
<Binary data>)r4r�r�r�r�s  rr�zShell._fmt_text_col�s3���9��>�>�!�
��3�
��H�
��5�
!�"��rc����|�r���fd�}tt���D�cgc]
}||���}}�jr6|D�cgc]$}dd|dkt|�t|�fzz��&c}�_n+|D�cgc]}dd|dkt|�fzz��c}�_�j
r�j}tt���D�cgc]A}|j
�j|�j�|�fzz|jz��C}}�j�jdj|�dz�|�jdurA�jd	tt|��D�cgc]}d
t||�z��c}�ytt���D�cgc]D}�jj�|�j|�j�|�fz���F}}�j�jdj|�dz�ycc}wcc}wcc}wcc}wcc}wcc}w)aA
        Items left aligned in space padded columns.  They are
        truncated if they do not fit. If the width hasn't been
        specified for a column then 10 is used unless the column name
        (header) is longer in which case that width is used.  Use the
        .width command to change column sizes.
        c����|t�j�kr!�j|dk7r�j|S�j�|�}tt|�d�S)Nr�
)rOr9r��max)�n�text�linerRs  ��r�gwzShell.output_column.<locals>.gw�sV����s�4�;�;�'�'�D�K�K��N�a�,?��;�;�q�>�)��)�)�$�q�'�2���3�t�9�b�)�)r�%)z-%d.%dsz%d.%dsr)z-%dsz%ds�  rnrrFrgN)�rangerOr �abs�
_actualwidthsr3�colourr��header_rwr=r��_colours�
output_column�colour_value)	rRr3r�r�r�r9�wr��colss	` `      rr�zShell.output_column�s����
*�&+�3�t�9�%5�6��b��e�6�F�6��}�}�ek�%l�`a�c�,A�!�a�%�,H�C�PQ�F�TW�XY�TZ�K[�,[�&[�%l��"�Y_�%`�TU�c�O�A��E�,B�c�!�f�Z�,O�&O�%`��"��{�{��K�K��#�3�t�9�-����H�H�� 2� 2�1� 5��9K�9K�D�QR�G�9T�8W� W�X�[\�[d�[d�d����
�
�
�4�;�;��	�	�$��$�(>�?���
�
�e�,�,��&�&�u�U�SV�W]�S^�M_�.`��s�S����^�/C�.`�a���3�t�9�%�
��
�K�K�$�$�T�!�W�d�.@�.@��.C�t�GY�GY�Z^�_`�Za�Gb�Fe�.e�f�
��
�
	
�
�
�4�;�;��	�	�$��$� 6�7��17��&m��%`��
��/a��
s%�H'�)H,�9H1�AH6�7H;
�-A	Ic	���
�d��
|r�tj�}i}�jdk(rd|d<nG�jdk(rd|d<n2tj|d<�
�j�|d<d	|d
<d|d<tj
|fi|��}||f�_�jr�jd
|�y
|�K�j}|D�cgc]3}|j�
�j|��z|jz��5}}n�
�fd�}|D�cgc]
}||���}}�jdj|��jdj�}	|	jd�sJ�|	d
d}	|	jd�s|	jd�rJ��j�j |	dz��jdj#d��jdj%d�y
cc}wcc}w)a�
        Items in csv format (comma separated).  Use tabs mode for tab
        separated.  You can use the .separator command to use a
        different one after switching mode.  A separator of comma uses
        double quotes for quoting while other separators do not do any
        quoting.  The Python csv library used for this only supports
        single character separators.
        c��|Sr�r
r�s rr�z"Shell.output_csv.<locals>.<lambda>0s��A�r�,�excel�dialectr��	excel-tab�quoting�	delimiterF�doublequote��	quotecharNc�f���jj|��j|���Sr��r�r�r�)r��fixdatarRs ��rr�z"Shell.output_csv.<locals>.<lambda>Ms)���D�K�K�4�4�Q���@R�@R�ST�@U�8V�W�rrrz
���r�rn)�io�StringIOr.�csv�
QUOTE_NONE�writer�_csvr3�
output_csvr�r�r��writerow�getvalue�endswithrwr=r �seek)rRr3r�r��kwargsr�r��l�fmt�tr�s`         @rr�zShell.output_csv"s����������
�A��F��~�~��$�$+��y�!����4�'�$/��y�!�$'�N�N��y�!�&-�d�n�n�&=��{�#�(-��}�%�
'-��{�#��Z�Z��,�V�,�F��F��D�I��{�{�����d�+���>����A�SW�X�a�A�H�H�w�t�'9�'9�!�'<�=�=��	�	�I�X�D�X�W�C�$(�)�q�C��F�)�D�)��	�	�!����d�#��I�I�a�L�!�!�#���
�
�6�"�#�"�
�c�r�F���J�J�t�$�Q�Z�Z��-=�>�=��
�
�4�;�;��D��)��	�	�!����a� ��	�	�!����!���Y��*s�
8G3�G8c�l��|r�jsy�fd�}n�fd�}|D�cgc]
}||���}}dg}|D];}|jd|�|j|�|jd|��=|jd��j�jdj	|��ycc}w)	zHTML table styleNc����jj�j|�z�jjzSr�)r�r3r�r��r�rRs �rr�z#Shell.output_html.<locals>.<lambda>_s0���D�K�K�.�.��1C�1C�A�1F�F����I\�I\�\�rc�Z���jj|�j|��Sr�)r�r�r�r�s �rr�z#Shell.output_html.<locals>.<lambda>a�#���D�K�K�4�4�Q��8J�8J�1�8M�N�rz<TR>)z<TD>z<TH>)z</TD>
z</TH>
z</TR>
r)r3rPrwr=r��rRr3r�r�r��outs`     r�output_htmlzShell.output_htmlZs������;�;��\�C�N�C� $�%�1��A��%��%��h���	7�A��J�J�'��/�0��J�J�q�M��J�J�-�f�5�6�	7�	�
�
�9���
�
�4�;�;������-��&s�B1c	����|ry�fd�}d�jzdzdj|D�cgc]
}||���c}�zdz}�j�j|�ycc}w)z�
        Lines as SQL insert statements.  The table name is "table"
        unless you specified a different one as the second parameter
        to the .mode command.
        Nc�b���jj|tj|��Sr�)r�r�r\�format_sql_valuer�s �rr�z%Shell.output_insert.<locals>.<lambda>ss#������0�0��D�4I�4I�!�4L�M�r�INSERT INTO � VALUES(r��);
)r8r�rwr=r�s`     r�
output_insertzShell.output_insertksc�����M���t�1�1�1�J�>����[_�J`�VW�3�q�6�J`�Aa�a�dj�j���
�
�4�;�;��$��Kas�A"
c
���|r|�_y�fd�}t�j�D��cgc]$\}}�j|��d|||�����&}}}�j�jddj|�zdz�ycc}}w)z�
        Each line as a JSON object with a trailing comma.  Blobs are
        output as base64 encoded strings.  You should be using UTF8
        output encoding.
        Nc�Z���jj|�j|��Sr�)r�r�r�r�s �rr�z#Shell.output_json.<locals>.<lambda>�s#������0�0��D�4H�4H��4K�L�r�: z{ �, z},
)�_output_json_cols�	enumerater�rwr=r�)rRr3r�r�r��krs`      r�output_jsonzShell.output_jsonws}����%)�D�"��L��NW�X\�Xn�Xn�No�p�d�a��4�/�/��2�C��Q��L�A�p��p��
�
�4�;�;��t�y�y��~� 5�� >�?��qs�)Bc�l��|r-d}|D]}t|�|kDs�t|�}�||f�_y�fd�}�jd}tt|��D]=}�j�jd|�jd||||�fz��?�j�jd�y)zi
        One value per line in the form 'column = value' with a blank
        line between rows.
        �Nc�Z���jj|�j|��Sr�r�r�s �rr�z#Shell.output_line.<locals>.<lambda>�s#������0�0��D�4F�4F�q�4I�J�rrz	%*s = %s
rrn)rO�
_line_infor�rwr=)rRr3r�r�r�r�r�s`      r�output_linezShell.output_line�s����
��A��
���q�6�A�:��A��A�
� !�$�i�D�O��J���O�O�A����s�4�y�!�	]�A��J�J�t�{�{�L�A�t���q�7I�!�7L�c�RV�WX�RY�l�3[�$[�\�	]��
�
�4�;�;��%rc����|r�jsy�j��fd�}n�fd�}�j�j�jj|D�cgc]
}||���c}�dz�ycc}w)z$All items on one line with separatorNc�<���j|z�jzSr�)r3r�)r�r�s �rr�z#Shell.output_list.<locals>.<lambda>�s���A�H�H�q�L�1�9�9�4�rc�Z���jj|�j|��Sr�r�r�s �rr�z#Shell.output_list.<locals>.<lambda>�r�rrn�r3r�rwr=r.r�)rRr3r�r�r�r�s`    @rr5zShell.output_list�s[�����;�;�����A�4�C�N�C��
�
�4�;�;���� 3� 3�T�4J��S��V�4J� K�d� R�S��4Js�A6c�����|r �jsy�j���fd�}n�fd�}�j�jddj	|D�cgc]
}||���c}�zdz�ycc}w)z)Tuples in Python source form for each rowNc�Z���j�j|�z�jzSr�)r3r�r��r�r�rRs ��rr�z%Shell.output_python.<locals>.<lambda>�s$���A�H�H�t�'7�'7��':�:�Q�Y�Y�F�rc�Z���jj|�j|��Sr�)r�r�r�r�s �rr�z%Shell.output_python.<locals>.<lambda>�s#���D�K�K�4�4�Q��8H�8H��8K�L�r�(rz),
)r3r�rwr=r��rRr3r�r�r�r�s`    @r�
output_pythonzShell.output_python�sZ�����;�;�����A�F�C�L�C��
�
�4�;�;��d�i�i��0F�A��Q��0F�&G� G�&� P�Q��0Fs�A0c����|r �jsy�j���fd�}n�fd�}�j�j�jj|D�cgc]
}||���c}�dz�ycc}w)z3Outputs TCL/C style strings using current separatorNc�Z���j�j|�z�jzSr�)r3r�r�rs ��rr�z"Shell.output_tcl.<locals>.<lambda>�s$���A�H�H�t�'9�'9�!�'<�<�q�y�y�H�rc�Z���jj|�j|��Sr�)r�r�r�r�s �rr�z"Shell.output_tcl.<locals>.<lambda>�r�rrnrrs`    @r�
output_tclzShell.output_tcl�s]�����;�;�����A�H�C�N�C��
�
�4�;�;���� 3� 3�T�4J��S��V�4J� K�d� R�S��4Js�A7c���|j��tjtjj
�}|jj�D��cic]<\}}|jtjjur|dvr
||j��>c}}|_|jj�}|j|j�|ddkr|jd�|d<|jd|j|j dk7i�|j"j%tjj
j&||fi|���ycc}}w)z2Outputs using line drawing and auto sizing columnsN>r)�queryr%r!rrr�rr)�_fqt_kwargs�inspect�	signaturer\�ext�format_query_table�
parameters�items�default�	Signature�empty�copy�updaterCrBr�r�r=rw�
_format_table)rR�column_names�rows�sigrr�r�s       rrzShell.output_box�s �����#��#�#�D�H�H�$?�$?�@�C� �N�N�0�0�2� ��A�q��9�9�G�$5�$5�$;�$;�;��Id�@d��1�9�9�� �D��
�!�!�&�&�(���
�
�d�&�&�'��,��!�#�#'�#7�#7��#;�F�<� ��
�
�x�����
�
�e�0D�!D�E�F������$�(�(�5�5�C�C�L�RV�a�Z`�a�b�� s�AE$Tc��ddzy)z<Outputs using ascii line drawing and strongly sanitized textrrNr
rXs r�output_tablezShell.output_table����	
�A�rc��ddzy)zAOutputs using line drawing and auto sizing columns quoting valuesrrNr
rXs r�output_qboxzShell.output_qbox�r9rc��|j|j|jj|z|jjz�yr�)rwr=r��summary�summary_)rRr=s  r�_output_summaryzShell._output_summary�s2���
�
�4�;�;���� 3� 3�g� =����@T�@T� T�Urc��|�=dtj��dtj��d�}|j�}|jr�|r�|j
}|j
|j|j|z|jz�|js<|xsd}|j
|j|j|z|jz�d}	|jr�|jtjur{ddl}|j!�}|j#|j$�|j'd�d	}	|j)t*j,j/|j0��		g|_|rd|_d	|_	|j=�}|��|jr|j
|jd
�	|r[j#�|j?d�|jAt*j,j/|j0��yy|jC|���#t2$rY��wxYw#t4$rY��wxYw#|jE�	|jG�n#tH$r|jG�YnwxYwY�dxYw#|r[j#�|j?d�|jAt*j,j/|j0��wwxYw)aRuns the main interactive command loop.

        :param intro: Initial text banner to display instead of the
           default.  Make sure you newline terminate it.
        :param transient: Additional message about being connected to
          a transient in memory database
        Nz
SQLite version z (APSW z!)
Enter ".help" for instructions
z-Connected to a transient in-memory database.
Frz
tab: completeTrn�)%r\rx�apswversionr�rDr�rwr=�intro�intro_r'�	transient�
transient_rr<�readline�
get_completer�
set_completer�complete�parse_and_bind�read_history_file�os�path�
expanduserr$�IOError�ImportErrorrL�_completion_cacherF�getcompleteline�set_history_length�write_history_filer��_append_input_descriptionrQ�UnicodeDecodeError)rRrCrEr��using_readlinerG�
old_completer�commands        r�cmdloopz
Shell.cmdloop�s����=���&�&�(�*�'�4�3C�3C�3E�1G�H��E��L�L�N�E��������A��J�J�t�{�{�A�G�G�e�O�a�h�h�$>�?��?�?�%�Y�)Y�	��
�
�4�;�;����i�(?�!�,�,�(N�O���	����D�J�J�#�)�)�$;�� (� 6� 6� 8�
��&�&�t�}�}�5��'�'��8�!%����.�.�r�w�w�/A�/A�$�BS�BS�/T�U�	S��+-��(�!�.2�D�*�+/�D�(�0�"�2�2�4�G����+�+� �J�J�t�{�{�D�9����&�&�}�5��+�+�C�0��+�+�B�G�G�,>�,>�t�?P�?P�,Q�R���.�.�w�7���
������	��	��&0��2�2�4�0��-�-�/��-�0��-�-�/�0�����&�&�}�5��+�+�C�0��+�+�B�G�G�,>�,>�t�?P�?P�,Q�R��s��A*I�8I�?J)�:I!�1I!�J)�	I�I�I�I�	I�I�!J&�4J�J&�J!�J&� J!�!J&�$J)�)ALc	��tj�\}}}t|t�rd|_�t|dd��sx|j
�|j|j|jj�t|t�r|j�d}nt|�}|jd�s|dz}t|j �rbt#t|j ��D]A}|dk(rd}nd|zd	z}|j|j||j |zdz��C|j|j|�|j$�r$g}|r*|j'|j(�|j*}|r�*|D]�}|j|jd
|j,j.|j,j0|j2fz�t5|j6j9��}	|	j;�|	D]7\}
}	t=|�dd}|j|j|
d�d|�d���9��|j|jd|�dt=|��d��|j|j|jj@�d|_|jBr�y#t>$rd
}Y��wxYw)z�Handles the current exception, printing a message to stderr as appropriate.
        It will reraise the exception if necessary (eg if bail is true)T�_handle_exception_saw_thisF�InterruptedrnrzAt � zFrom z
Frame %s in %s at line %d
N�Pz<Unable to convert to string>z>10z = r)"r<�exc_infor��
SystemExitr]rWr|rwr?r��error�KeyboardInterrupt�handle_interruptr�r�rOrLr�r#rP�tb_frame�tb_next�f_code�co_name�co_filename�f_lineno�list�f_localsr-�sortr�rN�error_r/)rR�eclass�eval�etbr�r��pref�stack�frame�varsrr�s            rrQzShell.handle_exception#sk�� �L�L�N����c��d�J�'�.2�D�+���t�9�5�A������J�J�t�{�{�D�K�K�$5�$5�6��$� 1�2��%�%�'�$���4�y���=�=��&��d�{���4�+�+�,��s�4�#;�#;�<�=�W�A��A�v�$��"�Q�w��0���J�J�t�{�{�D�4�3K�3K�A�3N�,N�QU�,U�V�W�
�J�J�t�{�{�D�)��������L�L����.��+�+�C��#�H�E��J�J����%D����-�-�u�|�|�/G�/G����X�&Y�Z� ���� 4� 4� 6�7�D��I�I�K� $�H���1�@� $�Q�����A��
�
�4�;�;��A�0F�G�H�
H��
�
�4�;�;���T�
�(K�L��J�J�t�{�{�D�K�K�$6�$6�7�*.��'��9�9���� )�@� ?�A�@�s�&K�K�Kc�����|jj�}|�d���fd�}||_	|j||�|dt��|t��ddd�fS#tj
$rY�4tj$r=}|dt��|t��dt|�|j|�fcYd}~Sd}~wt$r(}|jd}ddd|�d|�d�d|�fcYd}~Sd}~wwxYw)z+Internal routine to iterate over statementsNc�"��|�|j�y)NF)�
is_explain)�cursor�	statementr%�explain�saveds   ��r�etz Shell._query_details.<locals>.etds����E��'�'�G�rrzNo binding present for 'z' - use .parameter set z VALUE to provide oner�)r)rz�	exectrace�executer\�ExecTraceAbortrrOr��error_offset�KeyErrorrS)	rR�sqlr%�curr~�e�varr|r}s	       @@r�_query_detailszShell._query_details\s����g�g�n�n�������	���
�		$��K�K��X�&��K�S��Z� �#�c�%�j�k�"2�D�$��H�H���"�"�	���z�z�	\����U��$�c�#�e�*�+�&6��A�����PQ�SZ�[�[���	$��&�&��)�C��$�":�C�'�AX�Z]�X_�_t� u���7�$�
$��	$�s5�A � C3�5C3�2B?�9C3�?C3�C.�(C3�.C3c���|jj�}dtfd�}d�}|s|�|j}|j	��rT|j||�}|d}|s)|jr|j||d�dz�|dr�|j|d�d��|d	dk\r�|d	}	|djd
�}
||
d|	ddjd
��||
|	dddjd
��}}td
||z|j��tddt|�zzdz|j��d|d_
|d�|ddk(r9|j�d|_gd�|_d|_|j$|_n@|ddk(r8|j�d|_gd�|_d|_|j$|_|j)�}
d}t+|j&dd�rgnd}|jj-�}|jj.rd�|_|jj0rd�|_|j3|d|�D]�}|�W|j5�D��cgc]\}}|��	}}}|ddk(r|d=|r|j7|d�|�|j'd|�|ddk(rt9|�}|d=t;|�}|�|j'd|���|j=t9|����|r|r|j'||�|r|r|j7|d�|j>r |jA|
|j)��|dr|jC�|j	�r��T|jj�|z
}|s�|r�|jDr�d|jFjI|t|��zdzdz|jFjI|jj�t|jj���zdz}|jK|jL|�yyyycc}}w)a�Processes SQL text consisting of one or more statements

        :param sql: SQL to execute

        :param bindings: bindings for the *sql*

        :param internal: If True then this is an internal execution
          (eg the .tables or .database command).  When executing
          internal sql timings are not shown nor is the SQL echoed.

        :param summary: If not None then should be a tuple of two
          items.  If the ``sql`` returns any data then the first item
          is printed before the first row, and the second item is
          printed after the last row.  An example usage is the .find
          command which shows table names.
        r�c�P�tjdd|tj��S)N�\sr_rZ)r�r��UNICODE�r�s r�fixwsz Shell.process_sql.<locals>.fixws�s���6�6�%��a�r�z�z�:�:rc�R�|j�}t|�dkDr|dddz}|S)Nrz...)�striprOr�s r�fmt_sqlz"Shell.process_sql.<locals>.fmt_sql�s-�����	�A��1�v��}��e�t�H�u�$���HrNrrrnri��utf8i����#r�)�filez   r_z^--- error hereT�)����
r�r�r�r�rir�F)r�i������all_at_oncec��y�NTr
)rSs rr�z#Shell.process_sql.<locals>.<lambda>�s�rc��|Sr�r
�r��ys  rr�z#Shell.process_sql.<locals>.<lambda>�s��A�rz	changes: r�ztotal changes: )'r)�totalchangesr�r%r�r�r1�write_error�encoder��printr?rOr]rKr3r9r r�r6�get_resource_usagerWrzr�rowtracer��getdescriptionr?rl�tuplerPr2�display_timing�
pop_outputr0r�r�rwr=)rRr�r%�internalr=�
changes_startr�r��qd�offsetr&�before�after�timing_startr4r5r��row�h�dr0r�s                      r�process_sqlzShell.process_sqlxs��$���,�,�.�
�	;�S�	;�	��H�,��}�}�H��i�i�k��$�$�S�(�3�B��Q�%�C���9�9��$�$�W�R��U�^�d�%:�;��!�u�� � �R��U�9�B��0��a�5�A�:���U�F��q�E�L�L��0�E�$)�%���.���*>�*E�*E�f�*M�$N��e�F�G�n�S�b�1�8�8��@�A�"�F��$����T�[�[�A��%�3��V��#4�5�8I�I�PT�P[�P[�\�37��1��0���e���!�u��z�� � �"�"���:��� %��
�"�0�0����A��!��� � �"�"���*��� %��
�"�0�0����2�2�4�L��L� ����m�U�C�2��D��'�'�.�.�"�C��w�w� � � 2��
��w�w���-����{�{�2�a�5�(�3�
+���'�25�2D�2D�2F�#G�$�!�Q�A�#G�L�#G��!�u��z�(��O���,�,�W�Q�Z�8��|����D�,�7��a�5�A�:��s�)�C��A����*�C��<��K�K��s�+��K�K��S�	�*�!
+�$�����L�$�/����$�$�W�Q�Z�0��z�z��#�#�L�$�2I�2I�2K�L��!�u����!�M�i�i�k�P�'�'�&�&�(�=�8���G�����$�+�+�":�":�7�C��L�"Q�Q�TX�X�[l�l��K�K�,�,�T�W�W�-A�-A�-C�S����I]�I]�I_�E`�a�b�dh�i�D��J�J�t�{�{�D�)�)5�G�x��;$Hs�Q1c�r�|jr|j|j|dz�tj|�}|dddk(sJ�|ddd|d<t|d|dzd�}|s|j
d|d�d���t|�d	kDrU|dd
k(rM|ddk(rE|j|d|jd�d
z�t|d�zdz}|dd	||dgz}|ddvr=||j|d�t|d�zdj�}|r|d|g}||dd�}y)z�Processes a dot command.

        It is split into parts using :func:`shlex.split`
        which is roughly the same method used by Unix/POSIX
        shells.
        rnr�.rNrlzUnknown command "z".  Enter ".help" for helpr��	parameterr*rir�>�py�shell)
r1rwr?�shlex�splitrWrrO�indexr�)rRrZ�cmd�fn�pos�restr�s       r�process_commandzShell.process_command�sU���9�9��J�J�t�{�{�G�d�N�3��k�k�'�"���1�v�a�y�C�����Q������A��
�T�:��A��.��
5����*�*�TW�XY�TZ�]�^�^��s�8�a�<�C��F�k�1�c�!�f��o��-�-��A���
�
�e�(<�q�(@�A�C��A��K�O�RS�S�C��b�q�'�W�S�T�]�O�+�C��q�6�_�$��7�=�=��Q��0�3�s�1�v�;�>�?�@�F�F�H�D���1�v�t�n����Q�R��k�rc��t|�dk7s|dj�dvr|j|dz��|dj�dk(S)z"Parse and verify boolean parameterrr)�onrrz expected ON or OFFr�)rO�lowerr)rR�namer�s   r�_boolean_commandzShell._boolean_commandsH���s�8�q�=�C��F�L�L�N�-�?��*�*�T�$9�9�:�:��1�v�|�|�~��%�%rc���d}t|�dk(r|d}n*t|�dk(r|d}|d}n|jd��tj|�}|j	d|j
|�}	|js|j�|js�|j�|j�y#|j�|j�wxYw)a�backup ?DB? FILE: Backup DB (default "main") to FILE

        Copies the contents of the current database to FILE
        overwriting whatever was in FILE.  If you have attached databases
        then you can specify their name instead of the default of "main".

        The backup is done at the page level - SQLite copies the pages
        as is.  There is no round trip through SQL code.
        �mainrrriz"Backup takes one or two parametersN)
rOrr\r]�backupr)�done�step�finishrc)rRr��dbname�fnamer�bs      r�command_backupzShell.command_backup
s������s�8�q�=���F�E�
��X��]���V�F���F�E��*�*�A�B�B��o�o�e�$���J�J�v�t�w�w��/��	��f�f������f�f�
�H�H�J��I�I�K��
�H�H�J��I�I�K���4(B>�>"C c�2�|jd|�|_y)z�bail ON|OFF: Stop after hitting an error (default OFF)

        If an error is encountered while processing commands or SQL
        then exit.  (Note this is different than SQLite shell which
        only exits for errors in SQL.)
        r/N)r�r/�rRr�s  r�command_bailzShell.command_bail(s���)�)�&�#�6��	rc�(�t|�dkDr|jd��|xr|dxstjj	d�}tjj|�s|jd|�d���tj|�y)zccd ?DIR?: Changes current directory

        If no directory supplied then change to home directoryrzToo many directoriesr�~rtz' is not a directoryN)rOrrMrNrO�isdir�chdir)rRr�r�s   r�
command_cdzShell.command_cd1st���s�8�a�<��*�*�3�4�4��N�C��F�5�b�g�g�0�0��5���w�w�}�}�Q���*�*�q�!��%9�:�;�;�
����rc�2�|jd|�|_y)z�changes ON|OFF: Show changes from last SQL and total changes (default OFF)

        After executing SQL that makes changes, the number of affected
        rows is displayed as well as a running count of all changes.
        r0N)r�r0r�s  r�command_changeszShell.command_changes<s���,�,�Y��<��rc�p�t|�r|jd��|jj�y)z�close: Closes the current database

        Use .open to open a database, or .connection to switch to another
        connection
        zUnexpected argumentsN)rOrr)rcr�s  r�
command_closezShell.command_closeDs(���s�8��*�*�3�4�4����
�
�rc��|jj|j�g}tj�D] }	|j
|j|��"t|�dk(r�|j}|j|vr9|j|j|jdz|jzdz�t|�D]�\}}|j|urdnd}|j|j|j�|�|j�d|j�|d�|j �d|j"�d|j$�|j
�|j&�d	����yt|�d
k(r9|t)|d�}|j|ur||_|j
|_yy|j/d��#tj$rY���wxYw)
z�connection ?NUMBER?: List connections, or switch active connection

        This covers all connections, not just those started in this
        shell.  Closed connections are not shown.
        rz(Current connection is closed)rn�*r_z 2z - (z) "z"
rzToo many argumentsN)r+�addr)r\�connectionsr(�ConnectionClosedErrorrPrOr�rwr=�bold�bold_r�vnumber�vnumber_�open_vfs�vstring�vstring_�intr&r'r)rRr��dbsr��cor��sels       r�command_connectionzShell.command_connectionNs���	
�����t�w�w�'����!�!�#�	�A�
��
�
�
�J�J�q�M�	��s�8�q�=����B��w�w�c�!��
�
�4�;�;����2R�(R�UW�U]�U]�(]�`d�(d�e�!�#��
���1�!�W�W��\�c�s���
�
��K�K����j�#�����{�!�R�Z�Z�>�1�R��"�+�+��W[�]^�]g�]g�[i�im�oq�oy�oy�m{�}~�~H�~H�|J�LN�LW�LW�JY�Y]�^��
���X��]��C��A��K� �A��w�w�a�����"#�*�*��� ��*�*�1�2�2��)�-�-�
��
�s�G�G�Gc���t|�dkDr|jd��|xr|dxsd}||jvr|jd|z��||_|j	�y)acolour SCHEME: Selects a colour scheme

        If using a colour terminal in interactive mode then output is
        automatically coloured to make it more readable.  Use 'off' to
        turn off colour, and no name or 'default' for the default colour
        scheme.
        rzToo many colour schemesrr.zNo such colour scheme: N)rOrr�r{r|�rRr�r�s   rrEzShell.command_colourosf���s�8�a�<��*�*�6�7�7��N�C��F�'�i���D�M�M�!��*�*�6��:�;�;�������rc��t|�r|jd��|j�d|_|j|_d|_gd�|_	|jdd��|j�y#|j�wxYw)z@databases: Lists names and files of attached databases

        z-databases command doesn't take any parametersTF)r���:�pragma database_list�r�N)
rOrrKr3r�r6r r9r�r�r�s  r�command_databaseszShell.command_databases�sw���s�8��*�*�L�M�M���������(�(�����
�!���	����3�d��C��O�O���D�O�O��s�A:�:B>�SQLITE_DBCONFIG_MAX�SQLITE_DBCONFIG_LOOKASIDE�SQLITE_DBCONFIG_MAINDBNAME�SQLITE_DBCONFIG_STMT_SCANSTATUSc	�^�t|�dk(�r0i}tjD]k}t|�tus||j
vr�#|td�dj
�}|jjtt|�d�||<�mtd�|j�D��}|j�D]|\}}|j|jd|t|�z
z�|j|j|dz�|j|�|j|jd��~yt|�d	k7r|j!d
��d|dj#�z}|tjvr|j!d|����|jjtt|�t%|d��}|j|j|dj
�d
z�|j|�|j|jd�y)z�dbconfig ?NAME VALUE?: Show all dbconfig, or set a specific one

        With no arguments lists all settings.  Supply a name and integer value
        to change.  For example:

            .dbconfig enable_fkey 1
        r�SQLITE_DBCONFIG_Nr�c3�2K�|]}t|����y�wr��rO��.0rs  r�	<genexpr>z)Shell.command_dbconfig.<locals>.<genexpr>�s����3�q�C��F�3���r_�:  rnrizExpected zero or two parameterszUnknown config option rr)rOr\�mapping_db_config�typer��_dbconfig_ignorer�r)�configrWr��keysr-rwr=�write_valuerr�r�)rRr��outputsr�prettyr�r��keys        r�command_dbconfigzShell.command_dbconfig�s����s�8�q�=��G��+�+�
G����7�#�%��d�.C�.C�)C���3�1�2�3�4�:�:�<��"&�'�'�.�.���q�1A�2�"F����	
G�
�3�G�L�L�N�3�3�A��
�
��
.���1��
�
�4�;�;��q�3�q�6�z�(:�;��
�
�4�;�;��E�	�2�� � ��#��
�
�4�;�;��-�	
.�

�
��X��]��*�*�>�?�?� �3�q�6�<�<�>�1���d�,�,�,��*�*�5�s�W�=�>�>��G�G�N�N�7�4��-�s�3�q�6�{�;���
�
�4�;�;��A������ 5�6�������
�
�4�;�;��%rc���	�t|�dkDr�jd��|r|dnd�	�	�fd�}d|d�fd|d	�fd
|d�fd|d
�fdt�jj	d�	�d��j
�fg}t
tjj�j�	��D]�\}}|dk(r,|jd�jjd�f�|r:|jd�tj|�j�D���s|dk(r(|jd�jj f���|jd�jjd�dk(r�jj"n�jj$f���t'd�|D��}|D]|\}}�j)�j*d|t|�z
z��j)�j*|dz��j-|��j)�j*d��~y)a'dbinfo ?NAME?: Shows summary and file information about the database

        This includes the numbers of tables, indices etc, as well as fields from
        the files as returned by :func:`apsw.ext.dbinfo`.

        NAME defaults to 'main', and can be the attached name of a database.
        rztoo many parametersrr�c�\���jjd��d|�d��jS)Nzselect count(*) from [z].sqlite_schema where type='rt)r)r��get)r��schemarRs ��r�totalz#Shell.command_dbinfo.<locals>.total�s0����7�7�?�?�%;�V�:�Ea�cd�af�fg�#h�i�m�m�mrznumber of tablesrznumber of indexesr�znumber of triggers�triggerznumber of views�viewzschema sizez select total(length(sql)) from [�].sqlite_schemazjournal mode�journal_modec3� K�|]}|���y�wr�r
)rr�s  rrz'Shell.command_dbinfo.<locals>.<genexpr>�s����K�Q�q�K�s�r(�walc3�8K�|]\}}t|����y�wr�r�)rrr�s   rrz'Shell.command_dbinfo.<locals>.<genexpr>�s����+�4�1�a��A��+�s�r_rrnN)rOrr�r)r�rrr\r*�dbinforP�pragma�extend�dataclasses�asdictr-r(�filename_wal�filename_journalr�rwr=r	)
rRr�rr
r��infor�rr�rs
`        @r�command_dbinfozShell.command_dbinfo�s�����s�8�a�<��*�*�2�3�3���Q��F��	n� ��w��0�
 �%��.�1�
!�5��#3�4�
��f�
�.�
�C������2R�TZ�R\�\k�0l� m� q� q�r�s�
��!���������&�!A�B�	y�G�A�t��A�v����������~�0N�O�P�����K�+�*<�*<�T�*B�*H�*H�*J�K�K���6��N�N�J����0@�0@�#A�B��N�N�#�15������1O�SX�1X����-�-�^b�^e�^e�^v�^v�x�y�	y�
�+�7�+�+���	*�D�A�q��J�J�t�{�{�C�1�s�1�v�:�$6�7��J�J�t�{�{�A��I�.����Q���J�J�t�{�{�D�)�		*rc������ ��jdd��t�t�jdd��	t	j
����fd��	ddd�� � fd	�}t|�d
k(rdg}g}|D]G}�jjd|f�D]%\}}|||�s�||vs�|j|��'�I|s	�jd
d��yg}�jjd�D]l}|D]e}t�jjd�j|d
�zdz|f�j��s�P||vs�U|j|��g�n|j��fd�}	��fd�}
dj|D�cgc]}|df|dk(��c}�}|
dtj ��d��|
dtj"�z�|
d�t%j&d��z�|
d|z�|
d�jj(z�	d
dl}
d
dl}|
d�|
j/���d�|j1�����|	�|
d��j5�jd t�jj7d!��zd"z�|
d#�jj7d�zd$z�d%d&d'd(�}�jj7d)�}|
d*|j9|t|��zd"z�|
d+t�jj7d,��zd"z�|	�|D�cgc]}|j;�|f��}}|j�|D��cgc]\}}|��	}}}� d-}� d.}|r$|
d/��j5�jd0�|r$|
d1��j5�jd2�|s|r|	��j5�jd3�|	�d4�}�j<}	�j?��j@�_!|D�]�}�jjd5|f�D�]�}|
d6|z�|d
j;�jE�dd7gd8�k(r��j5�jd9tjF|�zd:z��j5�jd;tjF|��d<tjF|��d=tjF|d
��d>��n��j5�jd?�j|�zd"z��j5�j||d
���j|��_�jd�j|�zd��d}�jjd@|f�D]6\}}|r
|
dA|z�d}�j5�j||���8|	�������d}�jjdBd<j|D�cgc]}tjF|���c}�zdCz�D]b\}}|r
|
dD�d}�j5�jdE�j|��d"���j5�j||���d|s|	�t�jjdF�j��r�d}|D]�}�jjdG|f�j�� t� �s�:t� �dHk(sJ�|r
|
dI�d}�j5�jdJtjF|��d"���j5�jdKtjF|��d� d
d
�d>����|s|	��jI�|�_|rG|
dL�|D]3}�j5�jdM�j|�zd"z��5|	��jj7dN�}|r/|
dO��j5�jdP|fz�|	��j5�jdQ�|r+|	�|
dR��j5�jdS�|rV|	�|
dT��j5�jdU�|	�|
dV��j5�jdW��jd
d��y#t$rd�Y�	�-wxYwcc}w#t2$rY��%wxYwcc}wcc}}wcc}w#�jI�|�_wxYw#�jd
d��wxYw)Xa2dump ?TABLE? [TABLE...]: Dumps all or specified tables in SQL text format

        The table name is treated as like pattern so you can use % as
        a wildcard.  You can use dump to make a text based backup of
        the database.  It is also useful for comparing differences or
        making the data available to other databases.  Indices and
        triggers for the table(s) are also dumped.  Finally views
        matching the table pattern name are dumped (it isn't possible
        to work out which views access which table and views can
        access multiple tables anyway).

        Note that if you are dumping virtual tables such as used by
        the FTS5 module then they may use other tables to store
        information.  For example if you create a FTS5 table named
        *recipes* then it also creates *recipes_content*,
        *recipes_segdir* etc.  Consequently to dump this example
        correctly use:

           .dump recipes recipes_%

        If the database is empty or no tables/views match then there
        is no output.
        �BEGIN IMMEDIATETr�rr�c�D��t|��s|j�d�S|S)Nr�)r�r�)r��outputstrencoding�
outputstrtypes ��r�	unicodifyz%Shell.command_dump.<locals>.unicodify
s$����a��/��x�x� 1�9�=�=��HrF)�virtuals�foreignsc����|j�jd�ry|j�}tjd|�rd�d<tjd|�rd�d<y)N�sqlite_Fz^\s*create\s+virtual\s+.*Tr)z".*\b(foreign\s*key|references)\b.*r*)r�rur��match)r�r�r�s  �r�checkz!Shell.command_dump.<locals>.checksZ����:�:�<�*�*�9�5� ��i�i�k���8�8�8�#�>�$(�A�j�M��8�8�A�3�G�$(�A�j�M�rrr�zgSELECT name,sql FROM sqlite_schema WHERE sql NOT NULL AND type IN ('table','view') AND tbl_name LIKE ?1�ENDNzcselect name from sqlite_schema where sql not null and type='table' and tbl_name like 'sqlite_stat%'�select * from z WHERE tbl=?c�>���j�jd�y)Nrn)rwr=rXs�r�blankz!Shell.command_dump.<locals>.blank?s����
�
�4�;�;��-rc	����|�}�j�jtj|ddd��dz�y)N�Nz-- )�initial_indent�subsequent_indentrn)rwr=�textwrap�fill)r�rRr(s ��r�commentz#Shell.command_dump.<locals>.commentBs4����a�L���
�
�4�;�;��
�
�a��E�ej�(k�nr�(r�srrz(All)zSQLite dump (by APSW �)zSQLite version zDate: z%cz
Tables like: z
Database: zUser: z @ z+The values of various per-database settingszPRAGMA page_size=�	page_size�;
zPRAGMA encoding='z';
�NONE�FULL�INCREMENTAL�rrri�auto_vacuumzPRAGMA auto_vacuum=zPRAGMA max_page_count=�max_page_countr)r*z/This pragma is needed to restore virtual tableszPRAGMA writable_schema=ON;
z�This pragma turns off checking of foreign keys as tables would be inconsistent while restoring.  It was introduced in SQLite 3.6.19.zPRAGMA foreign_keys=OFF;
zBEGIN TRANSACTION;
c�H�d|jd�dvrd}nd}||zdzS)N�--rnr�rr<)r�)r��nls  r�sqldefz"Shell.command_dump.<locals>.sqldefvs1���1�7�7�4�=��,�,��B��B��2�v��~�%rz<SELECT sql FROM sqlite_schema WHERE name=?1 AND type='table'zTable  r�)�create�virtualrz%DELETE FROM sqlite_schema WHERE name=z AND type='table';
zJINSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql) VALUES('table',r�z,0,rzDROP TABLE IF EXISTS z�SELECT name,sql FROM sqlite_schema WHERE sql NOT NULL AND type IN ('index', 'trigger') AND tbl_name=?1 AND name NOT LIKE 'sqlite_%' ORDER BY lower(name)zTriggers and indices on  zTSELECT name,sql FROM sqlite_schema WHERE sql NOT NULL AND type='view' AND name IN ( z) ORDER BY _ROWID_�ViewszDROP VIEW IF EXISTS z8select * from sqlite_schema where name='sqlite_sequence'z2select seq from main.sqlite_sequence where name=?1rzNFor primary key autoincrements the next id to use is stored in sqlite_sequencez,DELETE FROM main.sqlite_sequence WHERE name=z)INSERT INTO main.sqlite_sequence VALUES (zRYou had used the analyze command on these tables before.  Rerun for this new data.zANALYZE �user_versionznYour database may need this.  It is sometimes used to keep track of the schema version (eg Firefox does this).zpragma user_version=%d;zCOMMIT TRANSACTION;
zRRestoring foreign key checking back on.  Note that SQLite 3.6.19 is off by defaultzPRAGMA foreign_keys=ON;
z)Restoring writable schema back to defaultzPRAGMA writable_schema=OFF;
z�We need to force SQLite to reread the schema because otherwise it doesn't know that the virtual tables we inserted directly into sqlite_schema exist.z4BEGIN;
CREATE TABLE no_such_table(x,y,z);
ROLLBACK;
)%r�r�rWr=�codecs�lookuprNrOr)r�rPr7�fetchallrnr�r\rBrx�time�strftimer(�getpass�socket�getuser�gethostnamerQrwrrr�r8rKrr6r�rr�)!rRr�r.�tables�patternr�r��analyze_needed�statr2r9r��patsrPrQ�vac�vacvalue�	dectablesr�r)r*rF�oldtabler�firstr�r�r��uvr&r'r(r�s!`                            @@@@r�command_dumpzShell.command_dump�sF	���:	
���*�T��:��
�$�D�K�K��W�E��	(��M�M�+�,�	�b	3�#��6�A�
��3�x�1�}��e���F��
,��!%�����/�18��"=�,�I�D�#��T�3�'�D��,>��
�
�d�+�,�
,���D
���U�T��2� �N������y��
8��#�8�D�� �G�G�O�O�,<�t�?W�?W�X\�]^�X_�?`�,`�cq�,q�-1�H�6�6>�h�j�B� �~�5�*�1�1�$�7�8�
8�
���!�
.�
t��9�9�c�B��q�'�l�1��8�4�B�C�D��$�2B�2B�2D�G�H��%��(=�(=�(?�?�@��H�y����t�)<�=�=�>��O�d�*�+��L�4�7�7�#3�#3�3�4�
����9�W�_�_�5F�+G��SY�Se�Se�Sg�Ih�i�j�
�G��A�B��J�J�t�{�{�$7�#�d�g�g�n�n�[�>Y�:Z�$Z�]b�$b�c��'�$�'�'�.�.��*D�D�v�M�N���M�:�C��w�w�~�~�m�4�H��)�C�G�G�H�c�(�m�,L�L�u�T�U��,�s�4�7�7�>�>�BR�3S�/T�T�W\�\�]��G�
28�8�A�!�'�'�)�Q��8�I�8��N�N��$-�.�D�A�q�a�.�F�.���}�H���}�H���I�J��
�
�4�;�;�(F�G���,�-��
�
�4�;�;�(D�E��8����J�J�t�{�{�$:�;��G�
&��)�)�H�K
.�� � �"�"�0�0���#�! �E�#�w�w���/m�05�y� :�  ���	�E� 1�2�
�q�6�<�<�>�/�/�1�"�1�5�9W�W� �J�J� $���-T�W[�Wl�Wl�mr�Ws�-s� 6�.7�8�!�J�J� $���#'�#8�#8��#?��AV�AV�W\�A]�#'�#8�#8��Q��#@�!B�C�!�J�J�t�{�{�4K�d�Nf�Nf�gl�Nm�4m�pu�4u�v� �J�J�t�{�{�F�3�q�6�N�C�15�1I�1I�%�1P�D�.� �,�,�-=��@X�@X�Y^�@_�-_�jn�,�o� $��)-�����!7�:?�	�	*C�A�I�D�#�
 %� '�(C�e�(K� L�(-�� �J�J�t�{�{�F�3�K�@�A���A  �! �H��!%�����2B�DG�H�H�W]�N_�RS�OS�Nc�Nc�de�Nf�N_�E`�2`�cw�2w�"x�9�I�D�#����(� %���J�J�t�{�{�4�Kc�Kc�dh�Ki�,l�m��J�J�t�{�{�F�3�K�8�9���G��t�w�w���'a�b�k�k�m�n� �E�#�
E�� �G�G�O�O�,`�cd�bg�h�q�q�s���q�6�#&�q�6�Q�;�.�;�$� '�)N�!O�(-�� �J�J� $���W[�Wl�Wl�mn�Wo� r�t�!�J�J� $���!%�!6�!6�q�!9�1�Q�4��7�.D�E�
E�!������!�%-��"���l�m�'�^�A��J�J�t�{�{�J��9Q�9Q�RS�9T�,T�W\�,\�]�^���������/�B���E���
�
�4�;�;�(A�R�F�(J�K���
�J�J�t�{�{�$;�<�����l�m��
�
�4�;�;�(C�D�����C�D��
�
�4�;�;�(G�H����\�]��
�
�4�;�;�(a�b�
���U�T��2��W�	(� '��	(��~C���
��
�� 9��.��VN_��>���!�%-��"��J
���U�T��2�s��e+�Af>�"f>�'f>�A1f>�f>�
?f>�	e=�Bf>�+>f�)C=f>�&f�?f>�f�"Bf>�9H1f"�*f�C-f"�4Bf"�
E
f>�+e:�9e:�=f>�	f�f>�f�f>�f"�"f;�;f>�>gc�2�|jd|�|_y)z�echo ON|OFF: If ON then each SQL statement or command is printed before execution (default OFF)

        The SQL statement or command is sent to error output so that
        it is not intermingled with regular output.
        r1N)r�r1r�s  r�command_echozShell.command_echo�s���)�)�&�#�6��	rc�T�|jdd�}t|�dkDr|\}}n|d}d}	tj|�	|�tj|�||f|_y#t$r|jd|�d���wxYw#t$r|jd|�d���wxYw)z�Saves *enc* as the default encoding, after verifying that
        it is valid.  You can also include :error to specify error
        handling - eg 'cp437:replace'

        Raises an exception on invalid encoding or error
        �:rrNzNo known encoding 'rtzNo known codec error handler ')r�rOrKrL�LookupErrorr�lookup_errorr)rR�enc�errorss   rr;zShell.set_encoding�s����i�i��Q����s�8�a�<��K�C���a�&�C��F�	A��M�M�#��	O��!��#�#�F�+��V���
���	A��*�*��?�@�@�	A��
�	O��*�*�F�M�N�N�	O�s�A&�B�&B�B'c�j�t|�dk7r|jd��|j|d�y)a�encoding ENCODING: Set the encoding used for new files opened via .output and imports

        SQLite and APSW work internally using Unicode and characters.
        Files however are a sequence of bytes.  An encoding describes
        how to convert between bytes and characters.  The default
        encoding is utf8 and that is generally the best value to use
        when other programs give you a choice.

        You can also specify an error handler.  For example
        `cp437:replace` will use code page 437 and any Unicode
        codepoints not present in cp437 will be replaced (typically
        with something like a question mark).  Other error handlers
        include `ignore`, `strict` (default) and `xmlcharrefreplace`.

        For the default input/output/error streams on startup the
        shell defers to Python's detection of encoding.  For example
        on Windows it asks what code page is in use and on Unix it
        looks at the LC_CTYPE environment variable.  You can set the
        PYTHONIOENCODING environment variable to override this
        detection.

        This command affects files opened after setting the encoding
        as well as imports.
        rzEncoding takes one argumentrN)rOrr;r�s  r�command_encodingzShell.command_encodings1��2�s�8�q�=��*�*�:�;�;����#�a�&�!rc�2�|jd|�|_y)a�exceptions ON|OFF: If ON then detailed tracebacks are shown on exceptions (default OFF)

        Normally when an exception occurs the error string only is
        displayed.  However it is sometimes useful to get a full
        traceback.  An example would be when you are developing
        virtual tables and using the shell to exercise them.  In
        addition to displaying each stack frame, the local variables
        within each frame are also displayed.
        r#N)r�r#r�s  r�command_exceptionszShell.command_exceptions1s���/�/��c�B��rc���t|�dkDr|jd��	|sdn
t|d�}t	j
|�y#t$r|j|d�d���wxYw)z6exit ?CODE?: Exit this program with optional exit coderzToo many parameters for exitrz isn't an exit codeN)rOrr��
ValueErrorr<ryr�s   r�command_exitzShell.command_exit=sl���s�8�a�<��*�*�;�<�<�	?���#�c�!�f�+�A�	�������	?��*�*��Q��z�)<�=�>�>�	?�s�A	�	!A*c	��
�t|�dkst|�dkDr|jd��d}t|�dk(r|d}g}g�
�
fd�}|d}d|vsd|vr*�
j|�|jd|�z��
j|�|jd	|�z�	t|�}�
j|�|jd	|�z�d
j|�}|jjd|f�D]�\}|j|�}d|�d
�}	g}
|jjd|�d��D]9\}}}}}}|
j||j|�ft�
�zz��;|	d
j|
�z}	|j|	�
dd|zdzdf����y#t$rY��wxYw)a�find value ?TABLE?: Searches all columns of all tables for a value

        The find command helps you locate data across your database
        for example to find a string or any references to an id.

        You can specify a like pattern to limit the search to a subset
        of tables (eg specifying CUSTOMER% for all tables beginning
        with CUSTOMER).

        The value will be treated as a string and/or integer if
        possible.  If value contains '%' or '_' then it is also treated as
        a like pattern.

        This command can take a long time to execute needing to scan
        all of the relevant tables.
        rriz7At least one argument required and at most two acceptedr�c�2��dtt���zS)N�?)r�rO)�queryparamss�r�qpzShell.command_find.<locals>.qp`s�����S��-�.�.�.rr�_z%s LIKE z%s = z OR zBSELECT name FROM sqlite_schema WHERE type='table' AND name LIKE ?1zSELECT * from z WHERE �pragma table_info(r:TzTable rn)r�r=N)
rOrrPr�rmr�r)r�r7r�)rRr��tablefilter�
querytemplatersr�r�rr�r&�colqrt�columnrrs             @r�command_findzShell.command_findGs����"�s�8�a�<�3�s�8�a�<��*�*�V�W�W����s�8�q�=��a�&�K��
���	/�
��F���!�8�s�a�x����q�!�� � ��b�d�!2�3����1�����W�r�t�^�,�	��A��A����q�!�� � ��2�4��0����M�2�
������)m�*5��:�	i�I�U��(�(��/�A�12�5�E��D�)-�����TU�9X�)Y�
g�%��6�1�a��A����M�d�.F�.F�v�.N�-Q�TW�Xc�Td�-d�e�f�
g��F�K�K��-�-�E����U�K�$��TY�IY�\`�I`�bf�Hg��h�	i���	��	�s�/5F?�?	G�
Gc�2�|jd|�|_y)zLheader(s) ON|OFF: Display the column names in output (default OFF)

        r3N)r�r3r�s  r�command_headerzShell.command_headerzs���+�+�H�c�:��rc
��|j�s�i|_t|�D�]�}|jd�s�t||�j}|s
J|dz��|td�d}|dvr�K|ddk(r|dd}|ddk(r�|j
dd�}|dj�j
dd�}t|�d	k(s
J|d
z��t|�dk(st|dj��dk(rd}ntj|d�}|dk(rH|dd
zd
j|j�z|d<|dzdj|j�z}|dk(rPt|jj��}|j!�|ddzdj|�z|d<t|j��dk(rd}n�|jd�j
d�}t#t|��D]}	||	j�r�d||	<�|dg}|ddD]>}
|dr&|
r$|
j%�|
k(r|dxxd
|
zz
cc<�.|j'|
��@d|dj�z|dj�|f|j|<���|j)|j*d�|j-d�}t|�dk(�rLt|jj��}|j!�d}
|D]<}t|j|d�|
kDs�"t|j|d�}
�>g}|D]�}|j|}|j'|d�|j'd
d	|
zt|d�z
z�|j'dd
d	|
zzzjtj.|d||
z
d	z
���|j'd���|j)|j*dj|���n�|ddk(r3t|jj��}|j!�d}
|jD]<}t|j|d�|
kDs�"t|j|d�}
�>|D�]m}|dk(rd}||jvr|j1d|�d���g}|j|}|j'|d�|j'd
d	|
zt|d�z
z�|j'dd
d	|
zzzjtj.|d||
z
d	z
��dz�|d	rO|j'd�t3|d	�D]-\}	}|j'tj4||�dz��/||dk7r%|j)|j*dd|zzdz�|j)|j*dj|����p|j)|j*d�y)z�help ?COMMAND?: Shows list of commands and their usage

        If COMMAND is specified then shows detail about that COMMAND.
        ``.help all`` will show detailed help about all commands.
        rlz  command must have documentationN)�headers�colorrrnrrcriz) command must have usage: description docr�moder_z

r�z from rr�r�r�allr~r3zNo such command "r��=)�
_help_info�dirrurWrrOr�r�r7�dedentr��
_output_modes�_output_modes_detailrlr�rrnr�r�rPrwr?rB�wraprrr8)rRr�r�r��parts�	firstline�multi�colours�linesr�r��tw�commandsr�rZr�hi�paras                  r�command_helpzShell.command_help�s������ �D�O���Y�-
_���|�|�J�/���D�!�$�,�,���@�!�@�@�@�q��c�*�o�&�'���,�,�h���d�d�l��!�"��A���d�d�l�����a�(��!�!�H�N�N�,�2�2�3��:�	��9�~��*�[�A�0[�,[�[�*��u�:��?�c�%��(�.�.�*:�&;�q�&@��E�$�O�O�E�!�H�5�E���;�#,�Q�<�#�#5�����AS�AS�8T�#T�I�a�L�!�F�N�V�[�[��9R�9R�-S�S�E���=�"�4�=�=�#5�#5�#7�8�G��L�L�N�#,�Q�<�(�#:�T�Y�Y�w�=O�#O�I�a�L��u�{�{�}�%��*� �E�"�K�K��-�3�3�D�9�E�"�3�u�:�.�*��$�Q�x�~�~�/�')�E�!�H�*�#�1�X�J�E�"�1�2�Y�,�� ��9��q�x�x�z�Q��!�"�I��q��0�I�!�L�L��O�	,�'*�I�a�L�,>�,>�,@�&@�)�A�,�BT�BT�BV�X]�%^�����"�[-
_�^	
�
�
�4�;�;��%�
�
!�
!�"�
%���s�8�q�=��D�O�O�0�0�2�3�H��M�M�O��A�#�
9���t���w�/��2�3�a�7��D�O�O�G�4�Q�7�8�A�
9��C�#�	
!���_�_�W�-���
�
�2�a�5�!��
�
�3�!�a�%�#�b��e�*�"4�5�6��
�
�D�3�!�a�%�=�0�6�6�x�}�}�R��U�B�QR�F�UV�J�7W�X�Y��
�
�4� �	
!�
�J�J�t�{�{�B�G�G�C�L�1��1�v����4�?�?�/�/�1�2�����
��A��?�?�
9���t���w�/��2�3�a�7��D�O�O�G�4�Q�7�8�A�
9��
6���i�'�8���$�/�/�1��*�*��%K�L�L����_�_�W�-���
�
�2�a�5�!��
�
�3�!�a�%�#�b��e�*�"4�5�6��
�
�D�3�!�a�%�=�0�6�6�x�}�}�R��U�B�QR�F�UV�J�7W�X�[_�_�`��a�5��J�J�t�$�#,�R��U�#3�C���4��
�
�8�=�=��r�#:�T�#A�B�C��c�!�f�$��J�J�t�{�{�D�3��8�O�d�,B�C��
�
�4�;�;������5�+
6�,	
�
�
�4�;�;��%rc	�"�t|�dk7r|jd��	d}|jjd�d}t|jjd|j	|d�zdz�j��}|dkr|jd	|d�d
���|jj
�}d|j	|d��dd
jd|z��d�}i}|jd
k(rd|d<nA|jdk(rd|d<n,tj|d<|j|d<d|d<d|d<d}|j|d|�D]H}t|�|k7r |jd|t|�|fz��	|j||�|dz
}�J|jjd�y#t$r|jd|����wxYw#t$rr|jj|��wxYw)a�import FILE TABLE: Imports separated data from FILE into TABLE

        Reads data from the file into the named table using the
        current separator and encoding.  For example if the separator
        is currently a comma then the file should be CSV (comma
        separated values).

        All values read in are supplied to SQLite as strings.  If you
        want SQLite to treat them as other types then declare your
        columns appropriately.  For example declaring a column 'REAL'
        will result in the values being stored as floating point if
        they can be safely converted.

        Another alternative is to create a temporary table, insert the
        values into that and then use casting.:

          CREATE TEMPORARY TABLE import(a,b,c);
          .import filename import
          CREATE TABLE final AS SELECT cast(a as BLOB), cast(b as INTEGER),
               cast(c as CHAR) from import;
          DROP TABLE import;

        You can also get more sophisticated using the SQL CASE
        operator.  For example this will turn zero length strings into
        null:

          SELECT CASE col WHEN '' THEN null ELSE col END FROM ...
        rizimport takes two parametersNr$�ROLLBACKrurr:zNo such table 'rtzinsert into z values(r�rqr�r�r�r�r�r�Fr�r�r�rz(row %d has %d columns but should have %dzError inserting row �COMMIT)rOrr)r�r7rMrzr�r.r�r��_csvin_wrapperrNr�)	rRr��final�ncolsr�r�r�r�r�s	         r�command_importzShell.command_import�s��:�s�8�q�=��*�*�:�;�;�(	��E�
�G�G�O�O�-�.��E�������(<�t�?W�?W�X[�\]�X^�?_�(_�be�(e�f�o�o�q�r�E��q�y��j�j��Q��!B�C�C��'�'�.�.�"�C�15�1I�1I�#�a�&�1Q�SV�S[�S[�\_�bg�\g�Sh�i�C��F��~�~��$�$+��y�!����4�'�$/��y�!�$'�N�N��y�!�&*�n�n��{�#�(-��}�%�&,��{�#��C��+�+�C��F�F�;�
���t�9��%��*�*�%O�SV�X[�\`�Xa�ch�Ri�%i�j�j���K�K��T�*��q���
�
�G�G�O�O�H�%��	!���$�$�';�S�7�%C�D�����	��������&��	�s$�E-G&�G�!"G&�G#�#G&�&(Hc#��K�tj|d|jd�}tj|fi|j���D]}|���|j
�y�w)N�rr)rK�openrr��readerr1rc)rRr(r��thefiler�s     rr�zShell._csvin_wrapper=sW�����+�+�h��T�]�]�1�-=�>���J�J�w�9�'�,�,�.�9�	�D��J�	��
�
���s�A#A%c�>��"�#�t|�dkst|�dkDr�jd��tjj	|d�s�jd|d�d���t|�dk(r|d}nd}	d}�j
j
�}|jd�d	}|sBtjjtjj|d��d}|jd
�j|��d��j�r�jd|�d
����#fd�}d4�fd�	�#�"fd�}d4�fd�	�"d�}ddiddig}gd�}	�j|	vr|	j�j�|	D]&}
|jtj|
ddd���(g}g}d}
|D�]4}d}d}	�j!|d|j#��D]�}|dk(r<d}t|�}g}t%|�D]}|j|�#|�"|g��dg|z}�Dt|�|k7rt'd|t|�fz��|dz
}t%|�D]A}||s�	d|<|s�g}||D]}	|||�|j|��!|||<�C��|dkDrC|dkDr>t%|�D]
}|s�	g|<�|j|j#�||f���7t|�dk(rj|
r"�jd�j2d�d���d}t|�r(|d d!j5|D�cgc]}d"|z��	c}�zz
}�j|��t|�dkDr�jd#��|d\}}}}|j7dd�}|�	d$|d%�d&�}�j9�j:d'|||fz��j!|d|�}|D]}nd(�}t%|�D]p}t||�dkDrG�jd)|dz|d*j5||D�cgc]}|j<��c}�fz��||r||d||<�l|||<�rd+�j|��d,d*j5D�cgc]}�j|���c}��d�}|j|�d-�j|��d.d/j5d0g|z��d�}|D]Y}g} t%|�D]5}||}!|!s| jd��| j|||!���7|j|| ��[|jd1��j9�j:d2|�d3��y#t&$rY��wxYw#t($rd}
Y���t*$r9t-t/j0�d�}||vr|j|�Y��$wxYwcc}wcc}wcc}w#t*$rr�j
j|��wxYw)5a$autoimport FILENAME ?TABLE?: Imports filename creating a table and automatically working out separators and data types (alternative to .import command)

        The import command requires that you precisely pre-setup the
        table and schema, and set the data separators (eg commas or
        tabs).  This command figures out the separator and csv dialect
        automatically.  There must be at least two columns and two rows.

        If the table is not specified then the basename of the file
        will be used.

        Additionally the type of the contents of each column is also
        deduced - for example if it is a number or date.  Empty values
        are turned into nulls.  Dates are normalized into YYYY-MM-DD
        format and DateTime are normalized into ISO8601 format to
        allow easy sorting and searching.  4 digit years must be used
        to detect dates.  US (swapped day and month) versus rest of
        the world is also detected providing there is at least one
        value that resolves the ambiguity.

        Care is taken to ensure that columns looking like numbers are
        only treated as numbers if they do not have unnecessary
        leading zeroes or plus signs.  This is to avoid treating phone
        numbers and similar number like strings as integers.

        This command can take quite some time on large files as they
        are effectively imported twice.  The first time is to
        determine the format and the types for each column while the
        second pass actually imports the data.
        rrizExpected one or two parametersrzFile "z" does not existNr$r�rur:zTable "z" already existsc����|d��S�NT)�switchdmr
)r��	DateWorlds �r�DateUSz(Shell.command_autoimport.<locals>.DateUSys��� ��T�2�2rFc�~���j|�\}}}|r||}}|dks|dkDs
|dks|dkDrt�d|||fzS)Nr��z%d-%02d-%02d)�_getdaterm)r�r�r��mr�rRs     �rr�z+Shell.command_autoimport.<locals>.DateWorld|sR����-�-��*���1�a��A�q��Q��q�5�A��F�a�!�e�q�2�v�$�$�%��A�q�	�1�1rc����|d��Sr�r
)r��
DateTimeWorlds �r�
DateTimeUSz,Shell.command_autoimport.<locals>.DateTimeUS�s���$�Q��6�6rc�����j|�\}}}}}}|r||}}|dks-|dkDs(|dks#|dkDs|dks|dkDs|dks|dkDs
|dks|dkDrt�d||||||fzS)	Nrr�r�r��;�Az%d-%02d-%02dT%02d:%02d:%02d)�_getdatetimerm)	r�r�r�r�r�r��Mr�rRs	        �rr�z/Shell.command_autoimport.<locals>.DateTimeWorld�s����#'�#4�#4�Q�#7� ��1�a��A�q��A�q��Q��q�5�A��F�a�!�e�q�2�v��Q��!�b�&�A�PQ�E�UV�Y[�U[�_`�cd�_d�hi�ln�hn�$�$�4��1�a��A�q�7I�I�Irc��tjd|�rt�|dk(ry|ddk(rt�tjd|�r|ddk(rt�t	|�S|ddk(r|jd�st�t
|�S)Nr��0r�+z^[0-9]+$z0.)r��searchrmr-r�ru�float)r�s r�Numberz(Shell.command_autoimport.<locals>.Number�s|���9�9�U�A�&�$�$���8�A��Q�4�3�;�$�$��8�8�J��*���t�s�{�*�$4��q�6�M��Q�4�3�;�q�|�|�D�'9�$�$��Q�x�rr�r�r�)r�;rcr�)r�r�r�r�r�TzExpected %d columns - got %dz2The file is probably not in the current encoding "z&" and didn't match a known file formatz*File doesn't appear to match a known type.z  Errors reported:
rnr�z File matches more than one type!z(delimited by "r�z")z(Detected Format %s  Columns %d  Rows %d
c��|Sr�r
r�s rr�z*Shell.command_autoimport.<locals>.<lambda>�s���rz.Column #%d "%s" has ambiguous data format - %srz
CREATE TABLE rrrr�rqr�zAuto-import into table "z" complete
)F)rOrrMrN�existsr)rzr��splitext�basenamer7rMr.rPr�r�r�r1r�rmrWrNr�r<rarr�rrwr=r	)$rRr��	tablenamer�r�r�r�r��formats�seps�sep�	possiblesrg�
encodingissue�formatr�r�r��datasr��	allblanksr��ddr�r�r�r�r�r3�identityr�r��valsr�r�r�s$`                                 @@r�command_autoimportzShell.command_autoimportFsV���<�s�8�a�<�3�s�8�a�<��*�*�=�>�>��w�w�~�~�c�!�f�%��*�*�S��V�F�G�G��s�8�q�=��A��I��I�\	��E������ �A�
�I�I�'�(��E���G�G�,�,�R�W�W�-=�-=�c�!�f�-E�F�q�I�	��y�y�D�4L�4L�Y�4W�Z�[�d�d�f��j�j�)�!N�O�O�
3�
2�
7�
J�
 �"�7�+�i��-E�F�G�"�D��~�~�T�)����D�N�N�+��
y�����3�>�>��\a�pv�w�x�
y��I��F�!�M�"�+
)������()� $� 3� 3�C��F�F�K�K�M� J�)�� �A�:�$%�E�$'��I�E�$&�E�%*�5�\�e�� %���f�i��]�\b�-c� d�e�)-����I�$��t�9��-�",�-K�u�VY�Z^�V_�N`�-`�"a�a���
��!&�u��)�A�#'��7� (�+0�I�a�L�#(��8� (� "�A�&+�A�h�)��!)�$&�t�A�w�K�$%�H�H�R�L�)�()�E�!�H�)�)�8�q�y�U�Q�Y�!&�u��.�A�(��|�+-��a��.�"�(�(�&�+�+�-���u�)M�N��K+
)�Z�9�~��"� ��*�*����q�)�-�.�.�A���v�;��/�$�)�)�v�<V�!�T�A�X�<V�2W�W�W�A��j�j��m�#��9�~��!��j�j�!C�D�D�*3�A�,�'�F�E�5�%��*�*�Y��-�C��{�17��1D�G���J�J�t�{�{�$O�SV�X]�_d�Re�$e�f��(�(��Q���8�F� �
���
�#�H��5�\�
(���u�Q�x�=�1�$��*�*�%W�&'�!�e�V�A�Y��	�	�W\�]^�W_�B`�RS�1�:�:�B`�8a�%b�&c�d�d���8�$�Q�x��{�E�!�H�'�E�!�H�
(�,0�+C�+C�I�+N�PT�PY�PY�6<�=���)�)�!�,�=�Q?�@�C�
�I�I�c�N�15�1I�1I�)�1T�VY�V^�V^�`c�_d�gl�_l�Vm�n�C��
%�����u��1�A��Q��A�����D�)����H�E�!�H�Q�K�0�1��	�	�#�t�$�
%�
�I�I�h���J�J�t�{�{�R[�$^�_��(2�!)�$(�!)��*�)�$(�M� �)��C�L�L�N�1�-�.�A�����
�
�a�(��)��=W��$Ca��>�� �	��������&��	�s��EW4�B<V�V�(V�*V�2AW4�W%�C)W4�:W*�
AW4�W/�-CW4�	V�V�V�V�W"�W4�!=W"�W4�!W"�"W4�4(Xc��tjd|�}|st�t|j	d��t|j	d��t|j	d��}}}|dkDr|||}}}|dks|dkDrt�|||fS)Nz&^([0-9]+)[^0-9]([0-9]+)[^0-9]([0-9]+)$rrir����')r�r-rmr��group)rRr�r�r�r�s     rr�zShell._getdate
s���H�H�>��B������a�g�g�a�j�/�3�q�w�w�q�z�?�C�����
�O�a�1���t�8���A�!�q�A��t�8�q�4�x����!�Q�w�rc
�f�tjd|�}|st�t|j	dddddd��}tt
|��D]
}||��	d||<�|D�cgc]
}t|���}}|dd	kDr|d|d|dg|ddz}|dd	ks|dd
kDrt�|Scc}w)NzT^([0-9]+)[^0-9]([0-9]+)[^0-9]([0-9]+)[^0-9]+([0-9]+)[^0-9]([0-9]+)([^0-9]([0-9]+))?$rrir�r�r�rr�r�)r�r-rmrlr�r�rOr�)rRr�r�r-r�s     rr�zShell._getdatetimes����H�H�l�no�p������Q�W�W�Q��1�a��A�.�/���s�5�z�"�	�A��Q�x����a��	�"'�'�A��Q��'��'���8�d�?��1�X�u�Q�x��q��2�U�1�2�Y�>�E���8�d�?�e�A�h��o������(s�&B.c��t|�dk7r|jd��|j�d|_|j|_	|j
d|d��|j�y#|j�wxYw)z9indices TABLE: Lists all indices on table TABLE

        rzindices takes one table nameFz�SELECT name FROM sqlite_schema WHERE type='index' AND tbl_name LIKE ?1 UNION ALL SELECT name FROM sqlite_temp_schema WHERE type='index' AND tbl_name LIKE ?1 ORDER by nameTr�N)rOrrKr3r5r6r�r�r�s  r�command_indiceszShell.command_indices&s{���s�8�q�=��*�*�;�<�<���������&�&���	����#���
�
�
�O�O���D�O�O��s�	A.�.Bc��t|�dkst|�dkDr|jd��	|jjd�|jj
|�y#t$r|jd��wxYw)a�load FILE ?ENTRY?: Loads a SQLite extension library

        Note: Extension loading may not be enabled in the SQLite
        library version you are using.

        By default sqlite3_extension_init is called in the library but
        you can specify an alternate entry point.

        If you get an error about the extension not being found you
        may need to explicitly specify the directory.  For example if
        it is in the current directory then use:

          .load ./extension.so
        rriz load takes one or two parametersTz"Extension loading is not supportedN)rOrr)�enableloadextensionrN�
loadextensionr�s  r�command_loadzShell.command_load9sz���s�8�a�<�3�s�8�a�<��*�*�?�@�@�	C��G�G�'�'��-�	������s�#���	C��*�*�A�B�B�	C�s�A$�$A?c��d|�dtjj|d��d�}|j||zdz�y)Nz( � - �unknownz ) rn)r\�mapping_result_codesrr�)rR�code�messages   r�log_handlerzShell.log_handlerQsB���T�8�3�� 9� 9� =� =�d�I� N�P�PS�T��������$�.�/rc��|jd|�}tjtj|r|j�yd�y)z3log ON|OFF: Shows SQLite log messages (default off)�logN)r�r\r�SQLITE_CONFIG_LOGr�)rRr��settings   r�command_logzShell.command_logUs5���'�'��s�3�����D�*�*��D�,<�,<�R�T�Rrc	�Z�|s|jd��|d}|dk(rd}t|d|z�s-|jddj|j�z��t	|d|z�}|dk(rWt|�d	vr|jd
|dz��t|�dk(r|dnd
}|j
|�|_||_y|dvrSt|�dk7r|jd
|dz��|ddk(rd|_	n|ddk(rd|_	d|_
||_y|dvdddd�|ddddd�||jrdnddddd�|dd�}tjdd|��d��}t|d �rd|_|jdBi|��|j!d!d"d#d$�%�|j!d&d"d'd(�%�|j!d)t"d*d+�,�|j!d-d.�/�|j!d0t"d1�2�|j!d3t"d4d5�6�|j!d7d#d8d9�:�|j!d;d#d8d<�:�|j!d=d#d>d?�:�|j!d@d'd>dA�:�t%j&�}	t)j*|�5t)j,|�5t/|j1|dd��|_ddd�ddd�|j8|_y#1swY�#xYw#1swY�'xYw#t4j|j7���xYw)Cz/mode MODE ?OPTIONS?: Sets output mode to one ofzSpecify an output moder�tabsrlrszExpected a valid output mode: r�insert�rriz&Output mode %s doesn't take parametersrirrN>�box�qboxrr�r�r�T>r��r�rr�riirr`F)rrrr r!r"�	word_wrapz.mode r)�allow_abbrevrz�prog�
exit_on_errorz--quoter�
store_truez'Show values in SQL syntax [%(default)s])�dest�actionroz
--no-quote�store_falsezShow values as stringsz--string-sanitizer@z[How much to clean up string characters (0 - none, 1 - medium, 2 - everything) [%(default)s])r�choicesroz--nullzHow to show NULL [%(default)s])roz
--truncatez<How many characters to truncate long output at [%(default)s])rroz--widthr!zDMaximum width of the table [Screen width if terminal, else 80 chars])rr�roz	--unicoder"z&Use unicode line drawing [%(default)s])r�r�roz--no-unicodez!Use ascii line drawing like +=-+ z--word-wrapr�z*Wrap text at word boundaries [%(default)s]z--no-word-wrapz#Wrap at column width ignoring wordsr
)rrAr�r�rWrOr7r8r6r.r rD�argparse�ArgumentParserr��set_defaults�add_argumentr�r�r��
contextlib�redirect_stderr�redirect_stdoutrv�
parse_argsrCrr�r)rRr�r�r��
table_name�defaults�pr�s        rr}zShell.command_mode\s�����*�*�5�6�6���F����;��A��t�Y��]�+��*�*�=��	�	�$�J\�J\�@]�]�^�^��D�)�a�-�(��
��=��3�x�v�%��j�j�!I�S�QR�V�!T�U�U�#&�s�8�q�=��Q��g�J�!%�!9�!9�*�!E�D���D�K���,�,��3�x�1�}��j�j�!I�S�QR�V�!T�U�U��1�v���!$����Q��6�!�!%��� �D�M��D�K���(�]���� ��	 �
������	�
 $�/�/�!�R������	�
�'
��0
�#�#����e�n�SU�V���1�o�&�#�A�O�����"��"�	���y�w�|�Js��t�	���|�'�-�Nf��g�	������n�		�	p�
	
���x�&F��G�	���|�#�4r��s�	���y��(�b�	�	d�	
���{�*�)�D�	�	F�	
���~�*�)�?�	�	A�	
���}�*�'�H�	�	J�	
���'�+�'�A�	�	C��{�{�}��	/��+�+�D�1�
C��/�/��5�C�'+�A�L�L��Q�R��,A�'B�D�$�C�
C��o�o���C�C��
C�
C��	/��+�+�d�m�m�o�.�.�s<�=L�K9�(#K-�K9�L�-K6	�2K9�9L�>L�%L*c���t|�D�cgc]"}|jd�s�|td�d��$}}|jd�|j	�||_g}|D]�}|dvr�t
|d|z�j}|s
Jd|zdz��|jdd�j�}d|vr|jdd�}d|vr�|j|d	z|z���||_
ycc}w)
Nrsr�>r�r�ryzoutput mode z
 needs docrnr_r�r)r�rurOrPrnr�rWrr�r�r�)rRr��modes�detailr�s     rrIzShell._calculate_output_modes�s���-0��Y�R��!�,�,�y�:Q��3�y�>�?�#�R��R�
���V��
�
�
��"������	(�A��.�.����i�!�m�,�4�4�A��7�n�q�(�<�7�7�1��	�	�$��$�*�*�,�A��!�)��I�I�d�C�(���!�)��M�M�!�d�(�Q�,�'�	(�%+��!��!Ss
�C/�C/c�t�t|�dk7r|jd��|j|d�|_y)anullvalue STRING: Print STRING in place of null values

        This affects textual output modes like column and list and
        sets how SQL null values are shown.  The default is a zero
        length string.  Insert mode and dumps are not affected by this
        setting.  You can use double quotes to supply a zero length
        string.  For example:

          .nullvalue ""         # the default
          .nullvalue <NULL>     # rather obvious
          .nullvalue " \t "     # A tab surrounded by spaces
        rz%nullvalue takes exactly one parameterrN)rOr�fixup_backslashesr4r�s  r�command_nullvaluezShell.command_nullvalue�s5���s�8�q�=��*�*�D�E�E��/�/��A��7��rc��d}d}d}|}|rp|jd�}|jd�r3|dk(rd}�,|dk(r|jd�}�C|jd|z��|�|jd	|z��|}|r�p|r�|s|jd
��tj�D]I}	|j
r:tjj|j
|�r|j��KdD]}	t
j||z��|jj|j �|�|nd|_tj$|j"|tj&tj(ztj*z�
�|_y#tjtf$rY��wxYw#t$rY��wxYw)a�open ?OPTIONS? ?FILE?: Opens a database connection

        Options are:

        --wipe     Closes any existing connections in this process referring to
                   the same file  and deletes the database file, journals etc
                   before opening

        --vfs VFS  Which vfs to use when opening

        If FILE is omitted then a memory database is opened
        FNrrDz--wipeTz--vfszUnknown open param: zToo many arguments: z'You must specify a filename with --wipe)rz-journalz-walz-shmr)�vfsr[)�poprurr\r�r(rMrN�samefilercr��FileNotFoundError�remove�OSErrorr+r�r)r'r]r^r_r`r&)rRr��wiperr�r�r��suffixs        r�command_openzShell.command_open�s���������������a��A��|�|�D�!���=��D����<��%�%��(�C���j�j�!7�!�!;�<�<��!��j�j�!7�!�!;�<�<��F�����j�j�!J�K�K��%�%�'�
����z�z�b�g�g�&6�&6�q�z�z�6�&J����	��
�9�
����I�I�f�v�o�.�
�
	
�����t�w�w�'�$*�$6�&�B����?�?�4�?�?�'*�)-�)=�)=��@Z�@Z�)Z�%)�%<�%<�*=�>�����2�2�4E�F�����
����s%�(AF�6F8�F5�4F5�8	G�Gc�(�|jj�|jj�t|jd�r	|jj�t
|�dk7r|jd��	|d}|dk(r\d}|j|jk7r|j}|j|_|�|j�	|j�ytj|d|jd|jd�}d}|j|jk7r|j}||_|�|j�|j�y#t
$rY��wxYw#|j�wxYw)aoutput FILENAME: Send output to FILENAME (or stdout)

        If the FILENAME is 'stdout' then output is sent to standard
        output from when the shell was started.  The file is opened
        using the current encoding (change with 'encoding' command).
        �flushrzYou must specify a filenamerr=Nr�)r=rr?rArrPrOrr>rcr|rKr�r)rRr�r��old�newfs     r�command_outputzShell.command_output	sR��	
�������������4�:�:�w�'�
��
�
� � �"��s�8�q�=��*�*�:�;�;�	���F�E��� ����;�;�$�"7�"7�7��+�+�C�"�3�3����?��I�I�K��
�����;�;�u�c�4�=�=��+;�T�]�]�1�=M�N�D��C��{�{�d�3�3�3��k�k���D�K����	�	�������9�
��
��8
����s&�E/�AE?�,A2E?�/	E<�;E<�?Fc
���|�r�t|�dk(r|ddvri|_yt|�dk(r�|ddk(r�|js|j|jd�yt	dt	d�|jD��dz�}t|jj
��D]`\}}|j|j|d	|t|�z
zz�|j|�|j|jd
��byt|�dk(r|ddk(r	|j|d=yt|�dk(rH|ddk(r@	|jjd|d�d��j}||j|d<y|jd��#t$r|jd
|d�d���wxYw#t$r|jd|d����wxYw)a}parameter CMD ...:  Maintain named bindings you can use in your queries.

        Specify a subcommand:

           list            -- shows current bindings
           clear           -- deletes all bindings
           unset NAME      -- deletes named binding
           set NAME VALUE  -- sets binding to VALUE

        The value must be a valid SQL literal or expression.  For example
        `3` will be an integer 3 while '3' will be a string.

        Example::

          .parameter set floor 10.99
          .parameter set text 'Acme''s Glove'
          SELECT * FROM sales WHERE price > $floor AND description != $text;
        rr>rh�clearNrlzNo parameters set
r�c3�2K�|]}t|����y�wr�r�r�s  rrz*Shell.command_parameter.<locals>.<genexpr>^	s����>�1��A��>�rr_rnri�unsetrtz' is not in parametersr�r*zselect (r:z,Does not appear to be a valid SQLite value: zD.parameter command not understood.  Use .help parameter to get usage)rOr%rwr=r��sortedr-r	r�rr)r�rrN)rRr�r�rr�s     r�command_parameterzShell.command_parameterC	s���&��3�x�1�}��Q��+<�!<� "��
���3�x�1�}��Q��6�!1��}�}��J�J�t�{�{�,A�B����C�>��
�
�>�>��B�C��"�4�=�=�#6�#6�#8�9�2�D�A�q��J�J�t�{�{�A��q�3�q�6�z�0B�,B�C��$�$�Q�'��J�J�t�{�{�D�1�2���3�x�1�}��Q��7�!2�K��
�
�c�!�f�-���3�x�1�}��Q��5��`������(�C��F�*�A�(>�?�C�C�A�)*��
�
�c�!�f�%���j�j�_�`�`�� �K��*�*�q�#�a�&�
�2H�%I�J�J�K��
!�`��*�*�'S�UX�YZ�U[�S]�%^�_�_�`�s�'F�,G�"G�!G%c��|j|jdj|D�cgc]}|j|���c}�dz�ycc}w)z�print STRING: print the literal STRING

        If more than one argument is supplied then they are printed
        space separated.  You can use backslash escapes such as \n
        and \t.
        r_rnN)rwr=r�r)rRr�r�s   r�
command_printzShell.command_prints	s>��	
�
�
�4�;�;����S�)Q��$�*@�*@��*C�)Q� R�UY� Y�Z��)Qs�A
c���t|�dkst|�dkDr|jd��|j|d�|_t|�dk(r|j|d�|_yy)a�prompt MAIN ?CONTINUE?: Changes the prompts for first line and continuation lines

        The default is to print 'sqlite> ' for the main prompt where
        you can enter a dot command or a SQL statement.  If the SQL
        statement is not complete (eg not ; terminated) then you are
        prompted for more using the continuation prompt which defaults
        to ' ..> '.  Example:

          .prompt "command> " "more command> "

        You can use backslash escapes such as \n and \t.
        rriz!prompt takes one or two argumentsrN)rOrrr,r-r�s  r�command_promptzShell.command_prompt|	se���s�8�a�<�3�s�8�a�<��*�*�@�A�A��,�,�S��V�4����s�8�q�=�"�4�4�S��V�<�D�O�rc�J�|jj�|jj�|t|jd�}|r�t|�dk(sJ�t
j|��}	tj}tjt_	|j|d�}|t_	|r|jd�yyt
j||jjdz|jj z��y#t_	wxYw)	abpy ?PYTHON?: Starts a python REPL or runs the Python statement provided

        The namespace provided includes ``apsw`` for the module, ``shell`` for this
        shell and ``db`` for the current database.

        Using the .output command does not affect output from this command.  You
        can write to `shell.stdout` and `shell.stderr`.
        )r�r\r)r)�localsrzIncomplete Python statement
zReturning to APSW shell)�local�exitmsgN)r=rr?r\r)rOr��InteractiveInterpreterr<�
excepthook�__excepthook__�	runsourcer��interactr�rCrD)rRr�rv�interp�hookr�s      r�
command_pyzShell.command_py�	s���	
�������������t�4�7�7�;����s�8�q�=� �=��0�0��=�F�
&��~�~��!$�!3�!3����&�&�s�1�v�.��!%����� � �!@�A��
�M�M��d�k�k�.?�.?�B[�.[�^b�^i�^i�^p�^p�.p�q��"&���s�2=D�
D"c�>�t|�dk7r|jd��|dj�jd�roi}|j	t
||jd��t|dd�}	tt|j�|dd�||�|j�y
tj|dd|jd�}		|j�||_d	|_d|_	|j%�}|�n|j'|��%	|j-�|j�y
#|j�wxYw#t($r|j+��wxYw#|j-�|j�wxYw)a�read FILENAME: Processes SQL and commands in FILENAME (or Python if FILENAME ends with .py)

        Treats the specified file as input (a mixture or SQL and/or
        dot commands).  If the filename ends in .py then it is treated
        as Python code instead.

        For Python code the symbol 'db' refers to the current database,
        'shell' refers to the instance of the shell and 'apsw' is the
        apsw module.
        rzread takes a single filenamerz.py)r\r�r)�rb�execr�FN)rOrr�r�r2r\r)r�r+�compile�readrcrKrrJrrDrHrSr�rNrV�	pop_input)rRr��gr�r�s     rrzShell.command_read�	sb���s�8�q�=��*�*�;�<�<��q�6�<�<�>�"�"�5�)��A�
�H�H�d�T����A�B��S��V�T�"�A�
��W�Q�V�V�X�s�1�v�v�6��1�=����	����C��F�C����q�)9�:�A�
���O�O�%�!"�D�J�',�D�$�-.�D�*��#�3�3�5���<�!��2�2�4�8�	�"���� ����	��)���	��!���2�2�4����
��� ����	�s%�7)E�AE�E�E7�7E:�:"Fc���d}t|�dk(r|d}n*t|�dk(r|d}|d}n|jd��tj|�}|jj||d�}	|js|j�|js�|j�|j�y#|j�|j�wxYw)arestore ?DB? FILE: Restore database from FILE into DB (default "main")

        Copies the contents of FILE to the current database (default "main").
        The backup is done at the page level - SQLite copies the pages as
        is.  There is no round trip through SQL code.
        r�rrriz#Restore takes one or two parametersN)
rOrr\r]r)r�r�r�r�rc)rRr�r�r��inputr�s      r�command_restorezShell.command_restore�	s������s�8�q�=���F�E�
��X��]���V�F���F�E��*�*�B�C�C�����&���G�G�N�N�6�5�&�1��	��f�f������f�f�
�H�H�J��K�K�M��
�H�H�J��K�K�M�r�c��|j�|j|_d|_	t	|�dk(rdg}|D]}|jd|fd���	|j
�y#|j
�wxYw)aschema ?TABLE? [TABLE...]: Shows SQL for table

        If you give one or more tables then their schema is listed
        (including indices).  If you don't specify any then all
        schemas are listed. TABLE is a like pattern so you can % for
        wildcards.
        Frr�aSELECT sql||';' FROM (SELECT sql sql, type type, tbl_name tbl_name, name name FROM sqlite_schema UNION ALL SELECT sql, type, tbl_name, name FROM sqlite_temp_schema) WHERE tbl_name LIKE ?1 AND type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' ORDER BY substr(type,2,1), nameTr�N�rKr5r6r3rOr�r��rRr�r�s   r�command_schemazShell.command_schema�	s���	
�����&�&������
	��3�x�1�}��e���
#��� � �6�
9:�u�!�!�#�
#�
�O�O���D�O�O����-A)�)A;c�t�t|�dk7r|jd��|j|d�|_y)a�separator STRING: Change separator for output mode and .import

        You can use quotes and backslashes.  For example to set the
        separator to space tab space you can use:

          .separator " \t "

        The setting is automatically changed when you switch to csv or
        tabs output mode.  You should also set it before doing an
        import (ie , for CSV and \t for TSV).
        rz%separator takes exactly one parameterrN)rOrrr.r�s  r�command_separatorzShell.command_separator
s5���s�8�q�=��*�*�D�E�E��/�/��A��7��r)
r1r~r�r0r4r6r.�widthr#rc���t|�dk(r|jd��t|�dk(sJ�tj|d�}|dk7r|j	d|�d��yy)z�shell CMD ARGS...: Run CMD ARGS in a system shell

        Note that output goes to the process standard output, not
        whatever the shell .output command has configured.
        rz$Specify command and arguments to runrz
Exit code rnN)rOrrM�systemr�)rRr�r�s   r�
command_shellzShell.command_shell
sd���s�8�q�=��*�*�C�D�D��3�x�1�}��}��i�i��A�����!�8����z�3���3�4�rc	��t|�dkDr|jd��t|�r(|d}||jvr|jd|�d���d}g}|jD�]G}|}|r||k7r�|dvr|dk(rd	}d
}t||��r
d}�n	|dvr|j	t||��}n�|d
k(r6|j
D] }|jt|d|z�k(s� n�Jd��|dk(r3|j|jurd}n�t|jdd�}nv|dk(r.dj|jD�cgc]}d|fz��
c}�}nC|dk(r7|jd}|jdr |d|jdzdzz
}nJd��|j||f���Jd}|D]\}}t|�|kDs�t|�}�!|D](\}}|j|jd||||fz��*ycc}w)z3show: Show the current values for various settings.rz show takes at most one parameterrzUnknown show: 'rtN)r1r~r#r0r~r3rrr�)r4r.r�rszBug: didn't find output moder6r=r�z<unknown stdout>r:r_z%drz	 (Errors r:zBug: unknown show handlingz
%*.*s: %s
)rOr�_showsrWr�r�r6r=r>r�r9rrPrwr?)rRr��what�outsr�rr�r�s        r�command_showzShell.command_show,
s&���s�8�a�<��*�*�?�@�@��s�8��q�6�D��4�;�;�&��j�j��!@�A�A��D������	 �A��A���T�	���@�@��	�>�x�1����4��#��A��0�0��&�&�w�t�Q�'7�8���f���+�+�A�A��{�{�g�d�I��M�&B�B��A�A�"@�@�5��h���;�;�$�"7�"7�7� �A�����V�5G�H�A��g���H�H�D�K�K�@�q�d�a�U�l�@�A���j���M�M�!�$���=�=��#���t�}�}�Q�'7�7�#�=�=�A�:�:�:�u��K�K��A���?	 �D
���	�D�A�q��1�v��z���F��	��	B�D�A�q��J�J�t�{�{�M�Q��1�a�L�$@�A�	B��As�
H
c��|j�|j|_d|_	t	|�dk(rdg}|D]}|jd|fd���	|j
�y#|j
�wxYw)zhtables ?PATTERN?: Lists names of tables matching LIKE pattern

        This also returns views.
        Frr�z�SELECT name FROM sqlite_schema WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%' AND name like ?1 UNION ALL SELECT name FROM sqlite_temp_schema WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%' ORDER BY 1Tr�Nr4r5s   r�command_tableszShell.command_tablesb
s���
	
�����&�&������	��3�x�1�}��e���	
#��� � �!�$%�%�!�!�#�	
#�
�O�O���D�O�O��r7c���t|�dk7r|jd��	t|d�}|jj|�y#t$r|j|d�d���wxYw)a<timeout MS: Try opening locked tables for MS milliseconds

        If a database is locked by another process SQLite will keep
        retrying.  This sets how many thousandths of a second it will
        keep trying for.  If you supply zero or a negative number then
        all busy handlers are disabled.
        rztimeout takes a numberrz is not a numberN)rOrr�rmr)�setbusytimeout)rRr�r�s   r�command_timeoutzShell.command_timeout
so���s�8�q�=��*�*�5�6�6�	@��C��F��A�	
�����q�!���	@��*�*�S��V�>�?�?�	@�s�A�!A,c��|jd|�r	|j�d|_yd|_y#t$r|jd��wxYw)aStimer ON|OFF: Control printing of time and resource usage after each query

        The values displayed are in seconds when shown as floating
        point or an absolute count.  Only items that have changed
        since starting the query are shown.  On non-Windows platforms
        considerably more information can be shown.
        r2z4Timing not supported by this Python version/platformTFN)r�r�rNrr2r�s  r�
command_timerzShell.command_timer�
sY��� � ��#�.�
Y��'�'�)��D�J��D�J��	�
Y��j�j�!W�X�X�
Y�s	�4�Ac	���|r|jd��tj��dtj���tj
�dtj��tj�tjtjd�}td�|D��}|j�D]9\}}|j|jd|t|�z
z|�d|�d�z��;y)	z>version: Displays SQLite, APSW, and Python version information�No parameters takenr_r�)�SQLite�Python�APSWz	APSW file�Amalgamationc3�2K�|]}t|����y�wr�r�r�s  rrz(Shell.command_version.<locals>.<genexpr>�
s����,�a�3�q�6�,�rr�rnN)rr\rx�sqlite3_sourceidr<rm�
executablerB�__file__�using_amalgamationr�r-rwr=rO)rRr��versions�maxwrr�s      r�command_versionzShell.command_version�
s�����*�*�2�3�3��/�/�1�3�1�d�6K�6K�6M�4O�P��+�+��s�C�N�N�*<�=��$�$�&���� �3�3�
���,�8�,�,���N�N�$�	N�D�A�q��J�J�t�{�{�C�4�#�a�&�=�$9��e�2�q�T��<L�$L�M�	Nrc��|r|jd��|j|j|jjdz�y)z/vfsname: VFS name used to open current databaserKrnN)rrwr=r)r�r�s  r�command_vfsnamezShell.command_vfsname�
s6����*�*�2�3�3��
�
�4�;�;���� 0� 0�4� 7�8rc	��td�|j�D��}|j�D]�\}}|j|jd|t|�z
z�|j|j|dz�|j
d�rd|zn
t|�}|j|�|j|jd���y)Nc3�2K�|]}t|����y�wr�r�r�s  rrz$Shell._format_vfs.<locals>.<genexpr>�
s����+�1��A��+�rr_rr�z0x%xrn)	r�rr-rwr=rOrur�r	)rRrr�rr��vouts      r�_format_vfszShell._format_vfs�
s����+����
�+�+���I�I�K�	*�D�A�q��J�J�t�{�{�C�1�s�1�v�:�$6�7��J�J�t�{�{�A��I�.�!"���c�!2�6�A�:��A��D����Q���J�J�t�{�{�D�)�	*rc��|r|jd��tj�D]0}|d|jjk(s� |j|��2y)zBvfsinfo: Shows detailed information about the VFS for the databaserK�zNameN)rr\�vfs_detailsr)r�r])rRr�rs   r�command_vfsinfozShell.command_vfsinfo�
sQ����*�*�2�3�3��#�#�%�	&�C��7�|�t�w�w�/�/�/�� � ��%�	&rc���|r|jd��ttj��D]4\}}|r|j	|j
d�|j
|��6y)z?vfslist: Shows detailed information about all the VFS availablerKrnN)rrr\r`rwr=r])rRr�r�rs    r�command_vfslistzShell.command_vfslist�
sY����*�*�2�3�3��� 0� 0� 2�3�	"�F�A�s���
�
�4�;�;��-����S�!�	"rc���t|�dk(r|jd��g}|D]}	|jt|���||_y#t$r|jd|�d���wxYw)a#width NUM NUM ...: Set the column widths for "column" mode

        In "column" output mode, each column is a fixed width with values truncated to
        fit.  Specify new widths using this command.  Use a negative number
        to right justify and zero for default column width.
        rz You need to specify some widths!rtz' is not a valid numberN)rOrrPr�rmr9)rRr�r�r�s    r�
command_widthzShell.command_width�
sy���s�8�q�=��*�*�?�@�@����	G�A�
G�����Q�� �	G�
�����
G��j�j��!E�F�F�
G�s�A�A+c���d}	|jj�r7tj|jj	��j
}t||�S#t$rY�wxYw)z[Works out the terminal width which is used for word wrapping
        some output (eg .help)r`)r=rVrM�get_terminal_size�fileno�columnsrNr�)rR�minimumr�s   rrBzShell._terminal_width�
se��
��	��{�{�!�!�#��(�(����);�);�)=�>�F�F���1�g�����	��	�s�AA!�!	A-�,A-c�j�i}dD]}t||�||<�|jj|�y)z�Saves the current output settings onto a stack.  See
        :meth:`pop_output` for more details as to why you would use
        this.)r.r3r4r6r9r N)rWr:rP)rRr�rs   rrKzShell.push_output�
s<��
��S�	$�A��4��#�A�a�D�	$����!�!�!�$rc��t|j�sJ�t|j�dk(r|jd}n|jj�}|j�D]\}}t	|||��y)a#Restores most recently pushed output.  There are many
        output parameters such as nullvalue, mode
        (list/tcl/html/insert etc), column widths, header etc.  If you
        temporarily need to change some settings then
        :meth:`push_output`, change the settings and then pop the old
        ones back.

        A simple example is implementing a command like .dump.  Push
        the current output, change the mode to insert so we get SQL
        inserts printed and then pop to go back to what was there
        before.

        rrN)rOr:rr-rv)rRr�rr�s    rr�zShell.pop_output�
st���4�%�%�&�&�&��t�!�!�"�a�'��"�"�1�%�A��"�"�&�&�(�A��G�G�I�	 �D�A�q��D�!�Q��	 rc��|jryg}|jd|jfz�|jdt|jdd�z�|j
jdj
|��y)z�When displaying an error in :meth:`handle_exception` we
        want to give context such as when the commands being executed
        came from a .read command (which in turn could execute another
        .read).
        NzLine %drr��<stdin>r_)rDrPrHrWrrLr�)rRr�s  rrVzShell._append_input_descriptionsi���������
�
�9�� 6� 6�9�9�:��
�
�4�'�$�*�*�f�i�@�@�A�� � �'�'�����
�6rc��d|vr|Sg}d}|t|�kr�||dk7r|j||�|dz
}�0|dz
}|t|�k\r|jd��||}|jddddd�j|d	��|dz
}|d
�|jd|z��|t|�kr��dj	|�S)
z�Implements the various backlash sequences in s such as
        turning backslash t into a tab.

        This function is needed because shlex does not do it for us.
        r�rrz Backslash with nothing followingr�rnr�)r�r�r�r�Nr�zUnknown backslash sequence \r)rOrPrrr�)rRr�r�r�r�s     rrzShell.fixup_backslashess����q�=��(���
���#�a�&�j���t�t�|��
�
�1�Q�4� ��Q����
��F�A��C��F�{��j�j�!C�D�D��!��A��J�J�d��D�t�D�H�H��D�Q�R�
��F�A��2�w���j�j�!@�1�!D�E�E��#�a�&�j��w�w�s�|�rc�&�|j|�y)zOWrites text to dest.  dest will typically be one of self.stdout or self.stderr.N)rw)rRr�r�s   rrwzShell.write4s���
�
�4�rc��|j|j|jj|z|jjz�y)z'Writes text to self.stderr colouring itN)rwr?r�rcro)rRr�s  rr�zShell.write_error8s2���
�
�4�;�;���� 1� 1�D� 8�4�;�;�;M�;M� M�Nrc	�|�|j|j|jj|||���y)zBWrites colourized value to self.stdout converting to text with fmtN)rwr=r�r�)rR�valuer�s   rr	zShell.write_value<s)���
�
�4�;�;���� 8� 8���E�
� K�Lrc��|jj�|jj�	|jr�|jt
juro|jj|jjf}|jrd|dzdzd|dzdzf}|j|d|z|dz�dz}nQ|j|j|�|jj�}n|jj�}|xjdz
c_
t|�dk(ry|ddk(r|dd}|S#t$rYywxYw)z�Returns a single line of input (may be incomplete SQL) from self.stdin.

        If EOF is reached then return None.  Do not include trailing
        newline in return.
        �r�rrnNr�)r=rr?rDrr<r�r,�prompt_rF�
_raw_inputrwrGrH�EOFErrorrO)rRr,r�r�s    r�getlinez
Shell.getlineBs8��	
������������	�����:�:����*����*�*�D�K�K�,?�,?�?�A��+�+�"�Q�q�T�M�F�2�F�Q�q�T�M�F�4J�K���?�?�1�Q�4�&�=�1�Q�4�+?�@�4�G�D��J�J�t�{�{�F�3��:�:�.�.�0�D��z�z�*�*�,���"�"�a�'�"��t�9��>����8�t�����9�D����
�	��	�s�C=E�	E�Ec	�2�	d|_|j|j�}|�yt|j	��dk(ry|ddk(rd|ddz}|ddk7r�tj|�s�d	|_|j|j�}|�6|jd
|jt|jdd�|fz��|d
vr	|S|dz|z}|ddk7rtj|�s��|S#t$r|j�YywxYw)z�Returns a complete input.

        For dot commands it will be one line.  For SQL statements it
        will be as many as is necessary to have a
        :meth:`~apsw.complete` statement (ie semicolon terminated).
        Returns None on end of file.TNrrrqz.help rr�Fz#Incomplete SQL (line %d of %s): %s
r�rn)�gor�rn)�_completion_firstrzr,rOr�r\rJr-rrHrWrrdre)rRrZr�s   rrSzShell.getcompleteline`s*��	�%)�D�"��l�l�4�;�;�/�G�����7�=�=�?�#�q�(���q�z�S� �H�w�q�r�{�,B�'��!�*��#�D�M�M�'�,B�).��&��|�|�D�O�O�4���<��*�*�%K�&*�&<�&<�g�d�j�j�RX�Zc�>d�fm�%n�&o�p�p��;�&���N�"�D�.�4�/���!�*��#�D�M�M�'�,B��N�� �	��!�!�#��	�s)�$C:�C:�B
C:�%C:�8C:�:D�Dc��|jj�|js)|jr|j	|j
d�y�)z�Deal with keyboard interrupt (typically Control-C).  It
        will :meth:`~apsw.Connection.interrupt` the database and print"^C" if interactive.z^C
N)r)�	interruptr/rDrwr?rXs rrezShell.handle_interrupt~s;��	
�������y�y�T�-�-��J�J�t�{�{�F�+��
rc���	t|j��dk(ry|ddk(r|j|�y|j|�y#t$r|j�YywxYw)zzGiven some text will call the appropriate method to process
        it (eg :meth:`process_sql` or :meth:`process_command`)rNr�)rOr�r�r�rdre)rRrZs  rr�zShell.process_complete_line�s`��	$��7�=�=�?�#�q�(���q�z�S� ��$�$�W�-�� � ��)�� �	$��!�!�#�	$�s�A�A�A�A'�&A'c�j�i}dD]}t||�||<�|jj|�y)zFSaves the current input parameters to a stack.  See :meth:`pop_input`.)rDrrHN)rWrGrP)rRr�r�s   rrJzShell.push_input�s:����<�	$�A��4��#�A�a�D�	$���� � ��#rc��t|j�dkDsJ�|jj�}|j�D]\}}t	|||��y)z�Restore most recently pushed input parameters (interactive,
        self.stdin, linenumber etc).  Use this if implementing a
        command like read.  Push the current input, read the file and
        then pop the input to go back to before.
        rN)rOrGrr-rv)rRr�rr�s    rr.zShell.pop_input�sV���D�%�%�&�!�+�+�+����!�!�#���G�G�I�	 �D�A�q��D�!�Q��	 rc��|dk(r�ddl}|j�}|j�}|j�}	|jr+|jd�r|j
||||�|_n|j||||�|_|t|j�kDry|j|S#t$rtj��wxYw)a#Return a possible completion for readline

        This function is called with state starting at zero to get the
        first completion, then one/two/three etc until you return None.  The best
        implementation is to generate the list when state==0, save it,
        and provide members on each increase.

        The default implementation extracts the current full input
        from readline and then calls :meth:`complete_command` or
        :meth:`complete_sql` as appropriate saving the results for
        subsequent calls.
        rNr�)
rG�get_line_buffer�
get_begidx�
get_endidxr}ru�complete_command�completions�complete_sqlrN�	traceback�	print_excrO)rR�token�staterGr��beg�ends       rrJzShell.complete�s����A�:���+�+�-�D��%�%�'�C��%�%�'�C�	
��)�)�d�o�o�c�.B�'+�'<�'<�T�5�#�s�'S�D�$�'+�'8�'8��u�c�3�'O�D�$��3�t�'�'�(�(������&�&���
��#�#�%��	
�s�AB3�3C)r_r)�VALUES�CASTz:_ROWID_ OID ROWID sqlite_schema
           SQLITE_SEQUENCE)�yes�truer��no�falserrzanalysis_limit=�application_idzauto_vacuum=)r=r>r?zautomatic_index=z
busy_timeout=zcache_size=zcase_sensitive_like=zcache_spill=zcell_size_check=zcheckpoint_fullfsync=�collation_list�compile_options�data_version�
database_listzdefer_foreign_keys=z	encoding=)zUTF-8zUTF-16zUTF-16lez
UTF16-16be�foreign_key_checkzforeign_key_list(�foreign_keys�freelist_countz
fullfsync=�
function_listzhard_heap_limit=�ignore_check_constraintszincremental_vacuum(zindex_info(zindex_list(zindex_xinfo(�integrity_checkz
journal_mode=)�DELETE�TRUNCATE�PERSIST�MEMORY�OFF�WALzjournal_size_limit=zlegacy_alter_table=zlegacy_file_format=z
locking_mode=)�NORMAL�	EXCLUSIVEzmax_page_count=z
mmap_size=�module_listz	optimize(zpage_count;z
page_size=zquery_only=�quick_checkzread_uncommitted=zrecursive_triggers=zreverse_unordered_selects=�schema_versionzsecure_delete=�
shrink_memoryzsoft_heap_limit=zsynchronous=)r�r�r>ztable_info()�DEFAULT�FILEr�)	�
table_listztable_xinfo(ztemp_store=zthreads=�trusted_schemaz
user_version=zwal_autocheckpoint=�wal_checkpoint�writable_schemac�4�tjd|d|�S)z/Returns the tokens prior to pos end in the linez"?\w+"?N)r��findall)rRr�r�s   r�_get_prev_tokenszShell._get_prev_tokenss���z�z�*�d�4�C�j�1�1rc	�@�|j��B|jj�}|jd�D�cgc]}|d��	}}|jd�D�cgc]}|d��	}}|jd�D�cgc]}|d��	}	}|D�]^}
|
dk(rd}nd	|
�d
�}|jd|z�j	�D]�}dD]3}|||	vs�||jd
�r� |	j
||��5|ddk(s�D	|jd|
�d|d�d��j	�D]K}
|
d|	vr|	j
|
d�|
dj�D]}||	vs�|	j
|���M��i}|jd�D]+}|d}|d}t||j|d��||<�-d�}|j�D��cgc]\}}|||���}}}��a|j|j|||	g|_tt!|j��D]}|j|j#��!d|j%�v�r�|j'|j%�|�}t!|�dkDrm|ddk(re|j(D]V}|j+dd�|dk(s�|j(|}|sgcS|D�cgc]}|j|�s�|dz��c}cSt!|�dkDrn|ddk(rf|d|j+dd�j-d�rB|j(D]3}|j+dd�|dk(s�|j(|}|sgcS|cSt!|�dkDrS|ddk(rK|j(j/�D�cgc]}|j|�s�|��}}|j#�|St!|�r=|ddk(r5t1|j(j/��}|j#�|Sg}|j3�}|jD�] }|D�]}|j3�j|�s�$|j|�r||vs�:|j
|��L|j%�j|�r3|j%�|vs�~|j
|j%����|j3�j|�r3|j3�|vs��|j
|j3����||t!|�dz}||vs��|j
|�����#|Scc}wcc}wcc}w#tj$rY���wxYwcc}}wcc}wcc}w)aDProvide some completions for SQL

        :param line: The current complete input line
        :param token: The word readline is looking for matches
        :param beg: Integer offset of token in line
        :param end: Integer end of token in line
        :return: A list of completions, or an empty list if none
        Nzpragma collation_listrr�zpragma module_listr�temp�sqlite_temp_schemar�rr0r�r,rzpragma [z].table_info([z])rizpragma function_listr�r�c� �|dk(r|dzS|dzS)Nrz()rr
)r��nargss  r�fmtfuncz#Shell.complete_sql.<locals>.fmtfuncCs����z�#�d�{�*��#�:�%rzpragma ���rr�rr�r�r_)rRr)rzr�rMrurPr�r\�SQLErrorr�rr-�_sqlite_keywords�_sqlite_special_namesr�rOrnr�r��_pragmasr�r�rrlr�)rRr�r�r�r�r�r��
collations�	databases�otherr)�master�colr�item�	functionsr��nargr��	func_listr�r�r�r�r�r��ut�corpus�wordr�s                              rr�zShell.complete_sqls`���!�!�)��'�'�.�.�"�C�,/�K�K�8O�,P�Q�S�#�a�&�Q�J�Q�+.�;�;�7M�+N�O�C��Q��O�I�O�'*�{�{�3G�'H�I��S��V�I�E�I��"
V����<�1�F� �68�:�F��;�;�'7�&�'@�A�J�J�L�!�C�%�3���s�8�5�0��S��9L�9L�Y�9W�!�L�L��S��2�3��1�v��(�!�),���$&�$'��F�6�*� (�x�z�;��$)��8�5�#8�$)�L�L��q��$:�,1�!�H�N�N�,<�!;�D�'+�5�'8�(-���T�(:�!;�
;�
!�$�	��;�;�'=�>�I�C��q�6�D��q�6�D�&)�$�	�
�
�d�B�0G�&H�I�d�O�I�
&�
DM�?�?�CT�U�Z�T�4�W�T�4�0�U�	�U�E"
V�J�%�%�y�$�2L�2L�j�Zc�ej�&�D�"��3�t�5�5�6�7�
1���&�&�q�)�.�.�0�
1���
�
��$��%�%�d�j�j�l�C�8�A��1�v��z�a��e�x�/����N�A��y�y��b�)�Q�r�U�2�#�}�}�Q�/��#�#%�I�15�M�A����e�9L��C��M�M�N��1�v��z�a��e�x�/�D��#�J�4F�4F�s�B�4O�4X�4X�Y\�4]����$�A��y�y��b�)�Q�r�U�2�#�}�}�Q�/��#�#%�I�#��$��1�v��z�a��e�x�/�"&�-�-�"4�"4�"6�N�Q�!�,�,�u�:M�q�N��N����
��
��1�v�!�B�%�8�+��4�=�=�-�-�/�0�����
��
�
��
�[�[�]���,�,�	*�F��
*���:�:�<�*�*�2�.����u�-��s�?��J�J�t�,�����0�0��7��:�:�<�s�2��J�J�t�z�z�|�4�����0�0��7��:�:�<�s�2��J�J�t�z�z�|�4�"�D��U���$5�5���C�<��J�J�q�M�!
*�	*�$�
��KR��O��I��* $�}�}�!� �!��V��( N��OsH�U'�U,�=U1�A!U6�(U6�V�V�1V�,V�V�6V
�V
)r/r0r1r#r3r2r3r~c��|jsEt|�D�cgc]+}|jd�s�|dk7s�d|td�dz��-c}|_|j	||�}t|�dkr1|r/|jD�cgc]}|j|�s�|dz��c}Sg}|ddvr%t|jj��}�n`|dd	vr|j}�nK|dd
k(r#|jD�cgc]}|dd��	c}dgz}�n |ddk(rVtjD�cgc]<}t|t�r*||jvr|td
�dj���>}}n�|ddk(rmt|�dk(st|�dk(r|rgd�}n�t|�dk\r�|ddk(r�t|�dk(s|rqt|jj��}nM|j j#|dd�t$urgd�}n#|d|j vr|j |d}t'|�D�cgc]}|j|�s�||k7s�|��c}Scc}wcc}wcc}wcc}wcc}w)aMProvide some completions for dot commands

        :param line: The current complete input line
        :param token: The word readline is looking for matches
        :param beg: Integer offset of token in line
        :param end: Integer end of token in line
        :return: A list of completions, or an empty list if none
        rl�command_headersr�Nrr_r>rr�>r�ror��dbconfigr�r�ri)rrlzunset zset r)r�rr�ONr�)�_builtin_commandsr�rurOr�rlr�rr�r\rr�r�rr�r%�_command_paramsr�boolr)	rRr�r�r�r�r�r�r�r�s	         rr�zShell.complete_command�sO���%�%�36�t�9�&�./����Z�@X�]^�bs�]s��a��J��(�)�)�&�D�"�
�!�!�$��,���q�6�Q�;�5�%)�%;�%;�S��q�|�|�E�?R�A��G�S�S����Q�4�&�&��t�}�}�1�1�3�4�K�
�q�T�X�
��,�,�K�
�q�T�V�^�*.�*@�*@�A�Q�1�Q�R�5�A�U�G�K�K�
�q�T�Z�
�=A�=S�=S��89��a��%�!�4�3H�3H�*H��#�(�)�*�+�1�1�3��K���q�T�[�
 ��1�v��{�s�1�v��{�u�A���Q��1���1����c�!�f��k�U�"�4�=�=�#5�#5�#7�8��
�
!�
!�
%�
%�a��d�D�
1�T�
9�4�K�
�q�T�T�)�)�
)��.�.�q��t�4�K�!�+�.�U�a�!�,�,�u�2E�!�u�*��U�U��?&��T��B����Vs:�I"�I"�I"�I'�I'�<I,�+AI1�>I6�I6�I6c	��tjdk(�r�ddl}ddl}ddl}|j	�ddk(xr|j
xs|j|j|j|j|jg|jjj_|j�}|j�}|j�}|jjj|jjj�|j|�|j|�|j|�|j|��}|rA|j�t|j �dzt|j �dzd�SiSddl}ddl}|j%|j&�}	d|j�i}
dD]&\}}d	|z}
t)|	|
�s�t+|	|
�|
|<�(|
S)
z�Return a dict of various numbers (ints or floats).  The
        .timer command shows the difference between before and after
        results of what this returns by calling :meth:`display_timing`�win32rN�64biti���)�
Wall clock�	User time�System timer�))�utimer�)�stimer�)�maxrsszMax rss)�idrss�Memory)�isrss�Stack)�ixrssz
Shared Memory)�minfltzPF (no I/O))�majfltzPF (I/O))�inblockz	Blocks in)�oublockz
Blocks out)�nsignals�Signals)�nvcswzVoluntary context switches)�nivcswzInvolunary context switches)�msgrcvzMessages received)�msgsndz
Messages sent)�nswap�Swaps�ru_)r<�platform�ctypesrN�architecture�c_int64�c_int32�c_void_p�windll�kernel32�GetProcessTimes�argtypes�c_ulonglong�GetCurrentProcess�byrefr�rs�resource�	getrusage�RUSAGE_SELFrArW)rRr�rNr��dummyr�r��rcr�r�r�r��descr�s              rr�zShell.get_resource_usage�s����<�<�7�"�)�)��%�%�'��*�g�5�H�&�.�.�Z�F�N�N�\b�\k�\k�������&�/�/�?�F�M�M�"�"�2�2�;��&�&�(�E��&�&�(�E��&�&�(�E����'�'�7�7��
�
�&�&�8�8�:����U�#����U�#����U�#����U�#�%�B��"+�$�)�)�+�!&�u�{�{�!3�h�!>�#(����#5��#@���
�I�!��"�"�8�#7�#7�8�A�������-�C��
.���4�$�A�I���1�a�=� '��1�
�C��I�)
.�*�Jrc��t|j��}|D]}||vs�|j|��|j�|D]s}||vs�||vs�
||}||}||z
}|s�t	|�t
k(r"|j
|jd||fz��S|j
|jd||fz��uy)z�Writes the difference between b4 and after to self.stderr.
        The data is dictionaries returned from
        :meth:`get_resource_usage`.z+ %s: %.4f
z	+ %s: %d
N)rlrrPrnrr�rwr?)	rR�b4r�r�r�r�one�two�vals	         rr�zShell.display_timing�s���
�����O���	�A���z������	�	
�����		I�A��B�w�1��:���e���A�h���C�i����C�y�E�)��
�
�4�;�;��!�S��0I�J��
�
�4�;�;���3�x�0G�H�		Irc���t|jdd�r9|jj�r|j|j|_y|jd|_y)NrVFrr)rWr=rVr�r{r�rXs rr|zShell._out_colour
sI���4�;�;��%�0�T�[�[�5G�5G�5I��-�-��(:�(:�;�D�K��-�-��.�D�Krc�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�Shell._colourschemec�N�|j�D]\}}t|||��yr�)r-rv)rRr�rr�s    rrTzShell._colourscheme.__init__!
s'������
$���1���a��#�
$rc��yr�r
rXs r�__nonzero__zShell._colourscheme.__nonzero__%
s��rc�8�dt|j�zdzS)Nz_colourscheme(r:)r��__dict__rXs r�__str__zShell._colourscheme.__str__(
s��#�c�$�-�-�&8�8�3�>�>rc��y)Nrr
)rRrs  r�__getattr__zShell._colourscheme.__getattr__+
s��rc�>�|j}|�|j|z|jzSt|t�r|j
|z|jzSt|t�r|j|z|jzS|j|z|jzSr�)r��vnull�vnull_r�r�r�r�r��vblob�vblob_r�r�)rRr�	formattedr�s    rr�z Shell._colourscheme.colour_value.
s������A��{��z�z�I�-����;�;��#�s�#��|�|�i�/�$�-�-�?�?��#�u�%��z�z�I�-����;�;��<�<�)�+�d�m�m�;�;rN)r	r
rrTrrrr�r
rr�
_colourschemer	
s��	$�	�	?�	�		<rrr�resetrr�r��	underliner�r���
underline_r��inverse��inverse_��fg_blackr��fg_redr�fg_green�!�	fg_yellow�"�fg_bluer��
fg_magenta�$�fg_cyan�%�fg_white�'�fg_�(�bg_black�bg_red�bg_green�	bg_yellow�bg_blue�
bg_magenta�bg_cyan�bg_white�bg_)�)�*�+�,�-�.�/�1z�rrc��|Sr�r
r�s  rr�zShell.<lambda>X
s��q�r)r�r,rwrcrorCrDrErFr=r>r�rrr�r�rrr�r�r.)NNNr�NNr)NFN)rr
)�r	r
rrrNrrrr�rTr@rare�propertyr)rMr~rzr�r�r�r�r�r�r7r�r��output_columnsr�rrrr�output_linesr5r r$r'rr�r8r;r?r[rQr�r�r�r�r�r�r�r�r�r�rE�
command_colorr�rr
r"r_rar;rirkrnrzr|r�r�r�r�r�r�r�r�r�r�r�r�r�r}rIrr
rrrrr(rr2r6r9r?r=rBrDrGrIrWrYr]rarcrerBrKr�rVrrwr�r\rr	r1rxrzrSrer�rJr.rJ�keywordsr�r�r�r��
_pragmas_boolr�r�r�r�r�r�r�r�r�r|r�dictr-r�r�r�r�r"r.r'r#rrr%r(r�r�r�)rr�r�r�r�r�s000000rrrsN	��,�\
�	�
�,0���!'���
O8� ��(�O8��	O8�bv��%�
�*�g�t�-T�	U�B�s,�j��Nv�����A���J�""�H"�&�P �$
�
 �&+8�Z#�N�6�p.�"
%�@�&�$�L�	T�	R�
T��K�c�&"�J���
�
V�>S�@7�rI�8l*�\�>&��67�	�=��3�B"$�� #�M�� ��
&�@(*�TR3�h7�$�0"�:
C��1i�f;�%�O��J�m&�^H�T�B�H
�� �&$�00�S�
�M�a&�H+�&8�"2>�h)�V.a�`[�=�&r�@)�V�0�48� �F�5�4B�l�:"� �"
N�9�*�&�"��"�%� �.7��2�O�&*�%:�%:�M��J��<�<�$�$�	 �"'�H�}�}��(��IY�Z�A��J�q�,>�'>�?�?�Z���#�e�g��@�M�=��4�=��$�=�	�7�=�	�M�	=�
	��=�	�t�
=�	�
�=�	�
�=�	�M�=�	 ��=�	�$�=�	�4�=�	��=�	��=�	�}�=� 	�B�!=�"	�T�#=�$	�T�%=�&	�
�'=�(	�$�)=�*	�m�+=�,	��-=�.	�D�/=�0	#�M�1=�2	�t�3=�4	�t�5=�6	�t�7=�8	��9=�:	�4�;=�<	�R�==�>	�t�?=�@	�}�A=�B	�}�C=�D	�0�E=�F	�4�G=�H	�d�I=�J	�t�K=�L	�T�M=�N	�t�O=�P	�d�Q=�R	�}�S=�T	�t�U=�V	�]�W=�X	�}�Y=�Z	%�m�[=�\	�$�]=�^	�-�_=�`	��a=�b	�D�c=�d	�1�e=�f	�t�g=�h��4��'��#��(�y=�H�~2�p�n������
�O�"1��!:�O�I����)V�V6�pI�,/�<�<�:	�	��G�	�7�G�	�6�G�	
�;�G�	�G�	G�
	�L�G�	
�9�
G�	�J�G�	�J�G�	�H�G�	�J�G�	�K�G�	�I�G�	�L�G�	�I�G�	�J�G� 	�E�!G�"	�J�#G�$
��������3G�4�e�g�5��d�a��q�'�C��F�"2�S�"8�9���	�A�8�}�.�A�B�H�'�8�q�v�v�8�01���8�./�h�h����.?�8�01�w�w�����8�/0�i�i�!�&�&�.@�	8�
01�w�w�����8�34�*�*�
8�45�5�5�8�12�	�	�A�F�F�0B�8�23���1�5�5��8�01�{�{�8�12���8�/0�h�h�8�01�u�u�8�12���8�23���8� /0�i�i�!8�"01�u�u�#8�$12���%8�&23���'8�H�Y��*	
��
�
�
�
��]`��RS[��Z��r�
��
�s$�S�3S	�S�>S�S�Srr�rsr"c�p�	t�}|jtjdd�\}}}t	|�dk(r|j�yy#tj�d}t|t�r�t|dd�rntj�tjd�YyxYw)z�
    Call this to run the :ref:`interactive shell <shell>`.  It
    automatically passes in sys.argv[1:] and exits Python when done.

    rNrr]F)
rrMr<�argvrOr[rar�rbrWr�r�ry)r�rt�cmdsr�s    rr�r��
s�����G���^�^�C�H�H�Q�R�L�1�
��1�d��t�9��>�
�I�I�K���	��L�L�N�1����a��$���1�2�E�:��
���!������s
�AA�A!B5�__main__)�returnN)r<r\r�rMr�r(r�r�r7rNrKr�r�r�r�r��typingrrr�apsw.extrrQ�SyntaxErrorr��delattrr�r	r
rr�<module>rRs������	�	��
�	���
�
�����#�Y5
�Y5
�xj%����0�z���F���=	�[�!�%�
#�(�����!���'�(��E�#�$�%�s�A.�.#B�B

Youez - 2016 - github.com/yon3zu
LinuXploit