ó
    Ñ]je§  ã                  ó²  • S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJrJrJrJrJrJrJrJrJrJrJr  SS
KJr  SSK J!r!  SSK"J#r#  SSK$J%r%J&r&J'r'  SSK(J)r)  SSK$r$SSK$r*SSK$J+r+  SSK,J-r-  SSKJ.r.J/r/  \'(       a  SSK0J1r1  SSK2J3r3   SSK4J5r5J6r6  SSK4r4\4Rn                  " SS 5        Sr8\$R6                  \;\<\;\&\;   4   4   r=\# " S S5      5       r>\S 5       r?S r@\S! 5       rA " S" S#\5      rB " S$ S%\B5      rC\ " S& S'5      5       rD " S( S)\C5      rE\F" \S*5      (       a  \RŽ                  " \ER�                  S+9  SS,K(JIrIJJrJ  SS-KJKrK  \S4S. j5       rL " S/ S0\Rš                  5      rN\Rž                  " S1\R                   5      rQS5S2 jrRS6S3 jrSg! \9 a    Sr8 " S S\:5      r5 " S S\:5      r6 GNf = f)7z(History related magics and functionalityé    )ÚannotationsN)ÚPath)Údefaultdict)Úcontextmanager)Ú	dataclass)Ú	decorator)ÚAnyÚBoolÚDictÚInstanceÚIntegerÚListÚ
TraitErrorÚUnicodeÚUnionÚdefaultÚobserve)ÚLoggingConfigurable)Úlocate_profile)Úundoc)ÚTupleÚOptionalÚTYPE_CHECKING)ÚIterable)Úcast)Úwarn)ÚrefÚWeakSet)ÚInteractiveShell)ÚConfiguration)ÚDatabaseErrorÚOperationalErrorÚ	timestampc                ó\   • [         R                   R                  U R                  5       5      $ ©N)ÚdatetimeÚfromisoformatÚdecode)Úvals    ÚQ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/IPython/core/history.pyÚ<lambda>r+   9   s   € ¤×!2Ñ!2×!@Ñ!@ÀÇÁÃÔ!Nó    TFc                  ó   • \ rS rSrSrg)r!   é@   © N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r/   r,   r*   r!   r!   @   ó   † Úr,   r!   c                  ó   • \ rS rSrSrg)r"   éC   r/   Nr0   r/   r,   r*   r"   r"   C   r6   r,   r"   c                  ó:   • \ rS rSrSrS
S jrS rS rS rS r	Sr
g	)ÚDummyDBéN   zWDummy DB that will act as a black hole for history.

Only used in the absence of sqlitec                 ó   • / $ r%   r/   )ÚargsÚkwargss     r*   ÚexecuteÚDummyDB.executeT   s   € Øˆ	r,   c                ó   • g r%   r/   ©Úselfr=   r>   s      r*   ÚcommitÚDummyDB.commitW   ó   € Ør,   c                ó   • g r%   r/   rB   s      r*   Ú	__enter__ÚDummyDB.__enter__Z   rF   r,   c                ó   • g r%   r/   rB   s      r*   Ú__exit__ÚDummyDB.__exit__]   rF   r,   c                ó   • g r%   r/   rB   s      r*   ÚcloseÚDummyDB.close`   rF   r,   r/   N)r=   ú
typing.Anyr>   rP   ÚreturnÚlist)r1   r2   r3   r4   Ú__doc__r?   rD   rH   rK   rN   r5   r/   r,   r*   r:   r:   N   s    † ñ*ôòòòõr,   r:   c                ó@   • UR                   (       d  / $ U " U/UQ70 UD6$ )z9Decorator: return an empty list in the absence of sqlite.)Úenabled)ÚfrC   ÚaÚkws       r*   Úonly_when_enabledrY   d   s%   € ð �<�<Øˆ	á�Ð ˜Ò ˜RÑ Ð r,   i @  c                óŽ  •  U " U/UQ70 UD6$ ! [         [        4 Ga%  nU=R                  S-  sl        UR                  R	                  SUR
                  U5        UR
                  S:w  GaÒ  UR                  UR                  :”  a$  SUl        UR                  R	                  S5        GO}UR
                  R                  5       (       Ga]  [        UR
                  R                  UR
                  R                  -  5      nUR
                  R                  nUR
                  R                  5       R                  nU[        :¼  a¤  [        R                  R!                  [        R"                  R$                  5      R'                  5       R)                  SS5      nUS-   U-   U-   n	[+        S5       H4  n
[-        U	5      R/                  5       (       d    OUS-   U-   S	U
-  -   U-   n	M6     OUS
-   U-   n	UR
                  R1                  U	5        UR                  R	                  SU	5        UR3                  5         / s SnA$ e SnAff = f)a  A decorator which wraps HistoryAccessor method calls to catch errors from
a corrupt SQLite database, move the old database out of the way, and create
a new one.

We avoid clobbering larger databases because this may be triggered due to filesystem issues,
not just a corrupt file.
é   z&Failed to open SQLite history %s (%s).ú:memory:zAFailed to load history too many times, history will not be saved.Ú:Ú.z	-corrupt-éd   z-%iz-corruptz4History file was moved to %s and a new file created.N)r!   r"   Ú_corrupt_db_counterÚlogÚerrorÚ	hist_fileÚ_corrupt_db_limitÚis_fileÚstrÚparentÚstemÚsuffixÚstatÚst_sizeÚ_SAVE_DB_SIZEr&   ÚnowÚtimezoneÚutcÚ	isoformatÚreplaceÚranger   ÚexistsÚrenameÚinit_db)rV   rC   rW   rX   ÚeÚbaseÚextÚsizerm   ÚnewpathÚis              r*   Úcatch_corrupt_dbr|   r   sÝ  € ð*Ù�Ð ˜Ò ˜RÑ Ð øÜÔ+Ð,ô (Ø× Ò  AÑ%Õ Ø�‰�‰Ð?ÀÇÁÐQRÔSØ�>‰>˜ZÔ'Ø×'Ñ'¨$×*@Ñ*@Ó@Ø!+�”Ø—‘—‘ØWöð —‘×'Ñ'×)Ò)ä˜4Ÿ>™>×0Ñ0°4·>±>×3FÑ3FÑFÓG�Ø—n‘n×+Ñ+�Ø—~‘~×*Ñ*Ó,×4Ñ4�Øœ=Ó(ô !×)Ñ)×-Ñ-¬h×.?Ñ.?×.CÑ.CÓDß"™›ß ™  cÓ*ð ð
 # [Ñ0°3Ñ6¸Ñ<�Gä" 3žZ˜Ü# G›}×3Ñ3×5Ñ5Ù!à&*¨[Ñ&8¸3Ñ&>À%È!Á)Ñ&LÈsÑ&RšGò	 (ð # ZÑ/°#Ñ5�GØ—‘×%Ñ% gÔ.Ø—‘—‘ØJÈGôð �L‰LŒNØ�Ið ûðQ(ús!   ‚ ŽIŸHH?È8IÈ>H?È?Ic                  ó¾   • \ rS rSrSr    S	         S
S jjr      S             SS jjr    S           SS jjr S       SS jjrSr	g)ÚHistoryAccessorBaseé¨   z'An abstract class for History Accessorsc                ó   • [         er%   ©ÚNotImplementedError)rC   ÚnÚrawÚoutputÚinclude_latests        r*   Úget_tailÚHistoryAccessorBase.get_tail«   s
   € ô "Ð!r,   Nc                ó   • [         er%   r�   )rC   Úpatternr„   Ú
search_rawr…   rƒ   Úuniques          r*   ÚsearchÚHistoryAccessorBase.search´   s
   € ô "Ð!r,   c                ó   • [         er%   r�   )rC   ÚsessionÚstartÚstopr„   r…   s         r*   Ú	get_rangeÚHistoryAccessorBase.get_range¿   s
   € ô "Ð!r,   c                ó   • [         er%   r�   )rC   Úrangestrr„   r…   s       r*   Úget_range_by_strÚ$HistoryAccessorBase.get_range_by_strÉ   s
   € ô "Ð!r,   r/   ©é
   TFF©
rƒ   Úintr„   Úboolr…   r�   r†   r�   rQ   ú$Iterable[tuple[int, int, InOrInOut]]©Ú*TTFNF©rŠ   rf   r„   r�   r‹   r�   r…   r�   rƒ   úOptional[int]rŒ   r�   rQ   rž   ©r[   NTF©r�   rœ   r‘   rœ   r’   r¢   r„   r�   r…   r�   rQ   rž   ©TF©r–   rf   r„   r�   r…   r�   rQ   rž   )
r1   r2   r3   r4   rS   r‡   r�   r“   r—   r5   r/   r,   r*   r~   r~   ¨   s"  † Ù1ð ØØØ$ð"àð"ð ð"ð ð	"ð
 ð"ð 
.õ"ð ØØØØØð	"àð	"ð ð	"ð ð		"ð
 ð	"ð ð	"ð ð	"ð 
.õ	"ð Ø"ØØð"àð"ð ð"ð ð	"ð
 ð"ð ð"ð 
.õ"ð ?Dð"Øð"Ø"&ð"Ø7;ð"à	-÷"ð "r,   r~   c                  ó„  ^ • \ rS rSrSrSrSr\" \" \	5      \
" 5       /SS9R                  SS9r\" \S	S9R                  SS9r\" S
S9R                  SS9r\" S5      SS j5       r\" 5       r\" S5      \S 5       5       r S       SU 4S jjjrSSS jjr\S S j5       rS S jr   S!           S"S jjr\\    S#S j5       5       r\S$S j5       r \    S%         S&S jj5       r!\      S'             S(S jj5       r"\    S)           S*S jj5       r# S+       S,S jjr$Sr%U =r&$ )-ÚHistoryAccessoréÏ   z¯Access the history database without adding to it.

This is intended for use by standalone history tools. IPython shells use
HistoryManager, below, which is a subclass of this.r   é   a¹  Path to file to use for SQLite history database.

        By default, IPython will put the history database in the IPython
        profile directory.  If you would rather share one history among
        profiles, you can set this value in each, so that they are consistent.

        Due to an issue with fcntl, SQLite is known to misbehave on some NFS
        mounts.  If you see IPython hanging, try setting this to something on a
        local disk, e.g::

            ipython --HistoryManager.hist_file=/tmp/ipython_hist.sqlite

        you can also use the specific value `:memory:` (including the colon
        at both end but not the back ticks), to avoid creating an history file.

        ©ÚhelpT©Úconfiga*  enable the SQLite history

        set enabled=False to disable the SQLite history,
        in which case there will be no stored history, no SQLite connection,
        and no background saving thread.  This may be necessary in some
        threaded environments where IPython is embedded.
        z«Options for configuring the SQLite connection

        These options are passed as keyword args to sqlite3.connect
        when establishing database connections.
        Úconnection_optionsc                ó   • [        SS9$ )NF)Úcheck_same_thread)Údict©rC   s    r*   Ú_default_connection_optionsÚ+HistoryAccessor._default_connection_options  s   € ä eÑ,Ð,r,   Údbc                óª   • US   n[         [        R                  4n[        X#5      (       d(  U R                  R
                  < SU< 3n[        U5      eg)zCvalidate the db, since it can be an Instance of two different typesÚnewz/.db must be sqlite3 Connection or DummyDB, not N)r:   Úsqlite3Ú
ConnectionÚ
isinstanceÚ	__class__r1   r   )rC   Úchanger¸   Úconnection_typesÚmsgs        r*   Ú_db_changedÚHistoryAccessor._db_changed	  sQ   € ð �U‰mˆÜ#¤W×%7Ñ%7Ð8ÐÜ˜#×0Ñ0à—‘×'Ô'ÚðˆCô ˜S“/Ð!ð 1r,   c                óÎ   >• [         [        U ]
  " S0 UD6  U(       a  X l         U R                    U R                  5         g! [         a    U R                  U5      U l         N3f = f)ab  Create a new history accessor.

Parameters
----------
profile : str
    The name of the profile from which to open history.
hist_file : str
    Path to an SQLite history database stored by IPython. If specified,
    hist_file overrides profile.
config : :class:`~traitlets.config.loader.Config`
    Config object. hist_file can also be set through this.
Nr/   )Úsuperr¨   Ú__init__rc   r   Ú_get_hist_file_nameru   )rC   Úprofilerc   Útraitsr¼   s       €r*   rÄ   ÚHistoryAccessor.__init__  s[   ø€ ô 	Œo˜tÒ-Ñ7°Ò7ö Ø&ŒNð	?Ø�NŠNð
 	�‰�øô	 ó 	?à!×5Ñ5°gÓ>ˆDŽNð	?ús   ¤A Á A$Á#A$c                ó0   • [        [        U5      5      S-  $ )zâFind the history file for the given profile name.

This is overridden by the HistoryManager subclass, to use the shell's
active profile.

Parameters
----------
profile : str
    The name of a profile which has a history file.
úhistory.sqlite)r   r   )rC   rÆ   s     r*   rÅ   Ú#HistoryAccessor._get_hist_file_name4  s   € ô ”N 7Ó+Ó,Ð/?Ñ?Ð?r,   c                óÆ  • U R                   (       d8  [        5       U l        [        R                  " U S U R                  5      U l        g[        [        R                  [        R                  -  S9nUR                  U R                  5        [        R                  " [        U R                  5      40 UD6U l        [        R                  " U S U R                  5      U l        U R                     U R                  R                  S5        U R                  R                  S5        U R                  R                  S5        SSS5        SU l        g! , (       d  f       N= f)	z8Connect to the database, and create tables if necessary.c                ó"   • U R                  5       $ r%   ©rN   ©r¶   s    r*   r+   Ú)HistoryAccessor.init_db.<locals>.<lambda>F  s
   € ÀÇÁÄ
r,   N)Údetect_typesc                ó"   • U R                  5       $ r%   rÎ   rÏ   s    r*   r+   rÐ   M  s
   € ¸B¿H¹H¼Jr,   zÆCREATE TABLE IF NOT EXISTS sessions (session integer
                            primary key autoincrement, start timestamp,
                            end timestamp, num_cmds integer, remark text)z¥CREATE TABLE IF NOT EXISTS history
                    (session integer, line integer, source text, source_raw text,
                    PRIMARY KEY (session, line))z«CREATE TABLE IF NOT EXISTS output_history
                            (session integer, line integer, output text,
                            PRIMARY KEY (session, line))r   )rU   r:   r¶   ÚweakrefÚfinalizeÚ
_finalizerr²   r¹   ÚPARSE_DECLTYPESÚPARSE_COLNAMESÚupdater¯   Úconnectrf   rc   r?   r`   )rC   r>   s     r*   ru   ÚHistoryAccessor.init_dbA  sü   € ð �|�|Ü“iˆDŒGÜ%×.Ò.¨tÑ5JÈDÏGÉGÓTˆDŒOØô ¤7×#:Ñ#:¼W×=SÑ=SÑ#SÑTˆØ�‰�d×-Ñ-Ô.Ü—/’/¤# d§n¡nÓ"5Ñ@¸Ñ@ˆŒÜ!×*Ò*¨4Ñ1FÈÏÉÓPˆŒØ�W‹WØ�G‰G�O‰OðMôð
 �G‰G�O‰Oð4ôð �G‰G�O‰Oð<ô÷ ð& $%ˆÕ ÷' �Wús   Ã0AEÅ
E c                ó   • g)zOOverridden by HistoryManager to dump the cache before certain
database lookups.Nr/   r³   s    r*   Úwriteout_cacheÚHistoryAccessor.writeout_cachec  s   € ð 	r,   c                óæ   • U(       a  SOSnSnU(       a  SnSU-  nU(       a  US-  nSU< SU< S	3U-   nU R                   R                  X‚5      n	U(       a	  S
 U	 5       n	U(       a	  S U	 5       $ U	$ )ap  Prepares and runs an SQL query for the history database.

Parameters
----------
sql : str
    Any filtering expressions to go after SELECT ... FROM ...
params : tuple
    Parameters passed to the SQL query (to replace "?")
raw, output : bool
    See :meth:`get_range`
latest : bool
    Select rows with max (session, line)

Returns
-------
Tuples as :meth:`get_range`
Ú
source_rawÚsourceÚhistoryz6history LEFT JOIN output_history USING (session, line)z!history.%s, output_history.outputz", MAX(session * 128 * 1024 + line)zSELECT session, line, z FROM Ú c              3  ó*   #   • U  H	  oS S v •  M     g 7f)Néÿÿÿÿr/   )Ú.0Úrows     r*   Ú	<genexpr>Ú+HistoryAccessor._run_sql.<locals>.<genexpr>Ž  s   é € Ð+¢s �s˜•8¢sùs   ‚c              3  ó2   #   • U  H  u  pp4XX444v •  M     g 7fr%   r/   )rå   ÚsesÚlinÚinpÚouts        r*   rç   rè   �  s   é € ÐIÂSÑ/A¨s¸�S ˜zÕ*ÂSùs   ‚)r¶   r?   )
rC   ÚsqlÚparamsr„   r…   ÚlatestÚtogetÚsqlfromÚthis_querryÚcurs
             r*   Ú_run_sqlÚHistoryAccessor._run_sqlk  st   € ö2 !$‘¨ˆØˆÞØNˆGØ7¸%Ñ?ˆEÞØÐ9Ñ9ˆEøÛ=BÃGÐLÈsÑRˆØ�g‰g�o‰o˜kÓ2ˆÞÙ+¡sÓ+ˆCÞÙIÁSÓIÐIØˆ
r,   c                óZ   • SnU R                   R                  X!45      R                  5       $ )a�  Get info about a session.

Parameters
----------
session : int
    Session number to retrieve.

Returns
-------
session_id : int
    Session ID number
start : datetime
    Timestamp for the start of the session.
end : datetime
    Timestamp for the end of the session, or None if IPython crashed.
num_cmds : int
    Number of commands run, or None if IPython crashed.
remark : str
    A manually set description.
z)SELECT * from sessions where session == ?)r¶   r?   Úfetchone)rC   r�   Úquerys      r*   Úget_session_infoÚ HistoryAccessor.get_session_info“  s'   € ð2 <ˆØ�w‰w�‰˜u jÓ1×:Ñ:Ó<Ð<r,   c                ó<   • U R                  SSS9 H  nUS   s  $    g)zšGet the last session ID currently in the database.

Within IPython, this should be the same as the value stored in
:attr:`HistoryManager.session_number`.
r[   T)rƒ   r†   r   N)r‡   )rC   Úrecords     r*   Úget_last_session_idÚ#HistoryAccessor.get_last_session_id¯  s(   € ð —m‘m a¸�mÓ=ˆFØ˜!‘9Òñ >àr,   c                óÂ   • U R                  5         U(       d  US-  nU R                  SU4X#S9nU(       d  [        [        U5      SS 5      $ [        [        U5      5      $ )až  Get the last n lines from the history database.

Parameters
----------
n : int
    The number of lines to get
raw, output : bool
    See :meth:`get_range`
include_latest : bool
    If False (default), n+1 lines are fetched, and the latest one
    is discarded. This is intended to be used where the function
    is called by a user command, which it should not return.

Returns
-------
Tuples as :meth:`get_range`
r[   z(ORDER BY session DESC, line DESC LIMIT ?©r„   r…   N)rÜ   rõ   ÚreversedrR   )rC   rƒ   r„   r…   r†   rô   s         r*   r‡   ÚHistoryAccessor.get_tailº  sa   € ð2 	×ÑÔÞØ�‰FˆAØ�m‰mØ6¸¸À#ð ð 
ˆö ÜœD ›I a b˜MÓ*Ð*Üœ˜S›	Ó"Ð"r,   c                ó  • U(       a  SOSnU(       a  SU-   nU R                  5         SU-  nU4n	U(       a  USR                  U5      -  nUb  US-  nX•4-  n	OU(       a  US-  nU R                  X‰X$US9n
Ub  [        [	        U
5      5      $ U
$ )	aä  Search the database using unix glob-style matching (wildcards
* and ?).

Parameters
----------
pattern : str
    The wildcarded pattern to match when searching
search_raw : bool
    If True, search the raw input, otherwise, the parsed input
raw, output : bool
    See :meth:`get_range`
n : None or int
    If an integer is given, it defines the limit of
    returned entries.
unique : bool
    When it is true, return only unique entries.

Returns
-------
Tuples as :meth:`get_range`
rß   rà   zhistory.zWHERE %s GLOB ?z GROUP BY {0}z) ORDER BY session DESC, line DESC LIMIT ?z ORDER BY session, line)r„   r…   rð   )rÜ   Úformatrõ   r  rR   )rC   rŠ   r„   r‹   r…   rƒ   rŒ   ÚtosearchÚsqlformrï   rô   s              r*   r�   ÚHistoryAccessor.searchÝ  s£   € ö> $.‘<°8ˆÞØ! HÑ,ˆHØ×ÑÔØ# hÑ.ˆØ*1¨ˆÞØ�×-Ñ-¨hÓ7Ñ7ˆGØ‰=ØÐBÑBˆGØ�d‰N‰FÞØÐ0Ñ0ˆGØ�m‰m˜G°ÈFˆmÐSˆØ‰=ÜœD ›IÓ&Ð&Øˆ
r,   c                óP   • U(       a  SnXU4nOSnX4nU R                  SU-  XtUS9$ )aê  Retrieve input by session.

Parameters
----------
session : int
    Session number to retrieve.
start : int
    First line to retrieve.
stop : int
    End of line range (excluded from output itself). If None, retrieve
    to the end of the session.
raw : bool
    If True, return untranslated input
output : bool
    If True, attempt to include output. This will be 'real' Python
    objects for the current session, or text reprs from previous
    sessions if db_log_output was enabled at the time. Where no output
    is found, None is used.

Returns
-------
entries
    An iterator over the desired lines. Each line is a 3-tuple, either
    (session, line, input) if output is False, or
    (session, line, (input, output)) if output is True.
zline >= ? AND line < ?zline>=?zWHERE session==? AND %sr  )rõ   )rC   r�   r‘   r’   r„   r…   Ú
lineclauserï   s           r*   r“   ÚHistoryAccessor.get_range  sF   € öH Ø1ˆJØ dÐ+‰Fà"ˆJØÐ%ˆFà�}‰}Ø%¨
Ñ2°FÈFð ð 
ð 	
r,   c           	   #  ól   #   • [        U5       H  u  pEnU R                  XEXbUS9 Sh  v•N   M!     g N	7f)a²  Get lines of history from a string of ranges, as used by magic
commands %hist, %save, %macro, etc.

Parameters
----------
rangestr : str
    A string specifying ranges, e.g. "5 ~2/1-4". If empty string is used,
    this will return everything from current session's history.

    See the documentation of :func:`%history` for the full details.

raw, output : bool
    As :meth:`get_range`

Returns
-------
Tuples as :meth:`get_range`
r  N)Úextract_hist_rangesr“   )rC   r–   r„   r…   ÚsessÚsrv   s          r*   r—   Ú HistoryAccessor.get_range_by_str=  s5   é € ô* .¨hÖ7‰JˆD�QØ—~‘~ d¨qÀ&�~ÐI×IÒIò 8ÙIùs   ‚&4¨2©
4)r`   rÕ   r¶   rc   )rQ   zdict[str, bool])r   Ú )rÆ   rf   rc   rf   rÇ   rP   rQ   ÚNone)r   )rÆ   rf   rQ   r   ©rQ   r  )TFF)rî   rf   rï   Útupler„   r�   r…   r�   rð   r�   rQ   rž   ©r�   rœ   rQ   zNtuple[int, datetime.datetime, Optional[datetime.datetime], Optional[int], str])rQ   r¢   r™   r›   rŸ   r¡   r£   r¤   r¥   r¦   )'r1   r2   r3   r4   rS   r`   rd   r   r   r   r   Útagrc   r
   Úsqlite3_foundrU   r   r¯   r   r´   r	   r¶   r   rY   rÀ   rÄ   rÅ   r|   ru   rÜ   rõ   rú   rþ   r‡   r�   r“   r—   r5   Ú__classcell__©r¼   s   @r*   r¨   r¨   Ï   sû  ø† ñ;ð ÐàÐñ Ù	�$‹™›Ð#ðñ÷$ 
�c�€cÐð% ñ( Øðñ	÷ 
�c�€cÐð ñ ðñ÷ 
�c�€cÐð ñ Ð!Ó"ó-ó #ð-ñ 
‹€BáˆTƒ]Øñ	"ó ó ð	"ð :<ðØðØ36ðØGQðà	÷ð ö<@ð ó%ó ð%ôBð ØØð&àð&ð ð&ð ð	&ð
 ð&ð ð&ð 
.õ&ðP Øð=Øð=à	Wó=ó ó ð=ð4 óó ðð ð ØØØ$ð #àð #ð ð #ð ð	 #ð
 ð #ð 
.ô #ó ð #ðD ð ØØØØØð.àð.ð ð.ð ð	.ð
 ð.ð ð.ð ð.ð 
.ô.ó ð.ð` ð Ø"ØØð,
àð,
ð ð,
ð ð	,
ð
 ð,
ð ð,
ð 
.ô,
ó ð,
ð^ ?DðJØðJØ"&ðJØ7;ðJà	-÷Jó Jr,   r¨   c                  ó*   • \ rS rSr% S\S'   S\S'   Srg)ÚHistoryOutputiV  zLtyping.Literal['out_stream', 'err_stream', 'display_data', 'execute_result']Úoutput_typez!typing.Dict[str, str | list[str]]Úbundler/   N)r1   r2   r3   r4   Ú__annotations__r5   r/   r,   r*   r  r  V  s   ‡ ðó ð .Ö-r,   r  c                  óÂ  ^ • \ rS rSr% Sr\" SSS9r\" S/5      r\" S/5      r	\" 5       r
S\S'   \" S5      S7S	 j5       r\" 5       r\" 5       rS
\S'   \" \5      rS\S'   \" 5       rS\S'   \" 5       rS\S'   \" SSS9R1                  SS9r\" SSS9R1                  SS9r\" 5       rS\S'   \" 5       rS\S'   \" SSS9r\S8S j5       r\ " S5      r!\ " S5      r"\ " S5      r#\ " S5      r$\%RL                  " S5      r'\(" 5       r)S\S '   \*" S!5      r+S"\S#'    S9     S:U 4S$ jjjr,S;S% jr-\.S;S& j5       r/S;S' jr0S9S<S( jjr1\2S9S=S) jj5       r3S;S* jr4S>S+ jr5S?S@S, jjr6 SA   SBU 4S- jjjr7\8    SC         SDS. jj5       r9    SE         SFS/ jjr:     SG           SHU 4S0 jjjr; S9       SIS1 jjr<SJS2 jr=SKS3 jr>SKS4 jr?\2S9S=S5 jj5       r@S6rAU =rB$ )LÚHistoryManageri^  zCA class to organize all history-related functionality in one place.z1IPython.core.interactiveshell.InteractiveShellABCF)Ú
allow_noner  r   Údir_histc                óT   •  [         R                  " 5       /$ ! [         a    / s $ f = fr%   )r   ÚcwdÚOSErrorr³   s    r*   Ú_dir_hist_defaultÚ HistoryManager._dir_hist_defaultn  s)   € ð	Ü—H’H“J�<ÐøÜó 	ØŠIð	ús   ‚ ˜'¦'ztyping.Dict[int, str]Úoutput_hist_reprsz,typing.Dict[int, typing.List[HistoryOutput]]Úoutputsz'typing.Dict[int, typing.Dict[str, Any]]Ú
exceptionsrœ   Úsession_numberz9Should the history database include output? (default: no)r«   Tr­   r   z}Write to database every x commands (higher values save disk access & power).
Values of 1 or less effectively disable caching.zList[tuple[int, str, str]]Údb_input_cachezList[tuple[int, str]]Údb_output_cachez(IPython.core.history.HistorySavingThreadc                óJ   • U R                   b  U R                   R                  $ g r%   )Úsave_threadÚ	save_flagr³   s    r*   r0  ÚHistoryManager.save_flag‘  s#   € à×ÑÑ'Ø×#Ñ#×-Ñ-Ð-Ør,   z(exit|quit)(\s*\(.*\))?$zWeakSet[HistoryManager]Ú
_instancesÚinfzint | floatÚ	_max_instc                ó,  >• [         TU ]  " S	XS.UD6  [        R                  " 5       U l        [        R                  " 5       U l         U R                  5         SU l        U R                  (       aB  U R                  S:w  a2  [        U 5      U l         U R                  R                  5         SU l        U R"                  R%                  U 5        ['        [(        R"                  5      [(        R*                  ::  d.   ['        [(        R"                  5      [(        R*                  45       eg! [         a0    U R                  R                  SU R                  SS9  SU l
         GNf = f! [          a$    U R                  R                  SSS9  SU l
         Nßf = f)
z>Create a new history manager associated with a shell instance.)Úshellr®   zBFailed to create history session in %s. History will not be saved.T)Úexc_infor\   FzAFailed to start history saving thread. History will not be saved.Nr/   )rÃ   rÄ   Ú	threadingÚLockÚdb_input_cache_lockÚdb_output_cache_lockÚnew_sessionr"   ra   rb   rc   Úusing_threadrU   ÚHistorySavingThreadr/  r‘   ÚRuntimeErrorr2  ÚaddÚlenr   r4  )rC   r6  r®   rÇ   r¼   s       €r*   rÄ   ÚHistoryManager.__init__¨  sX  ø€ ô 	‰ÒÐ>˜uÑ>°vÒ>Ü#,§>¢>Ó#3ˆÔ Ü$-§N¢NÓ$4ˆÔ!ð	(Ø×ÑÔð "ˆÔØ�<�<˜DŸN™N¨jÓ8Ü2°4Ó8ˆDÔð	)Ø× Ñ ×&Ñ&Ô(ð %)�Ô!Ø�‰×Ñ˜DÔ!Ü”>×,Ñ,Ó-´×1IÑ1IÓIð 	
Ü”×)Ñ)Ó*Ü×$Ñ$ðL
ó 	
ÑIøô-  ó 	(Ø�H‰H�N‰NØTØ—‘Øð ñ ð
 (ˆD�Nð	(ûô  ó ,Ø—‘—‘ØWØ!ð ñ ð ",�–ð,ús$   Á	D( ÂE% Ä(6E"Å!E"Å%+FÆFc                óT   • U R                   b  U R                   R                  5         g g r%   )r/  r’   r³   s    r*   Ú__del__ÚHistoryManager.__del__Ð  s%   € Ø×ÑÑ'Ø×Ñ×!Ñ!Õ#ð (r,   c                óŠ   • U R                    H3  nUR                  c  M  UR                  R                  5         S Ul        M5     g r%   )r2  r/  r’   )ÚclsÚinsts     r*   Ú_stop_threadÚHistoryManager._stop_threadÔ  s8   € ð —N”NˆDØ×ÑÓ+Ø× Ñ ×%Ñ%Ô'Ø#'�Ö ò #r,   c                ó˜   • U R                   c=  U R                  (       a+  [        U 5      U l         U R                   R                  5         g g g r%   )r/  r=  r>  r‘   r³   s    r*   Ú_restart_thread_if_stoppedÚ)HistoryManager._restart_thread_if_stoppedÜ  s=   € à×ÑÑ#¨×(9×(9Ü2°4Ó8ˆDÔØ×Ñ×"Ñ"Õ$ð ):Ð#r,   c                ó^   • U R                   R                  R                  n[        U5      S-  $ )z–Get default history file name based on the Shell's profile.

The profile parameter is ignored, but must exist for compatibility with
the parent class.rÊ   )r6  Úprofile_dirÚlocationr   )rC   rÆ   rO  s      r*   rÅ   Ú"HistoryManager._get_hist_file_nameâ  s*   € ð
 —j‘j×,Ñ,×5Ñ5ˆÜ�KÓ Ð#3Ñ3Ð3r,   c                ó:  • Uc  U R                   nU   UR                  S[        R                  R                  5       R	                  S5      45      n[        UR                  [        5      (       d   eUR                  U l        SSS5        g! , (       d  f       g= f)zGet a new session number.NzRINSERT INTO sessions VALUES (NULL, ?, NULL,
                            NULL, '') râ   )	r¶   r?   r&   rm   rp   r»   Ú	lastrowidrœ   r+  )rC   Úconnrô   s      r*   r<  ÚHistoryManager.new_sessionê  sw   € ð ‰<Ø—7‘7ˆDâØ—,‘,ð*ä×"Ñ"×&Ñ&Ó(×2Ñ2°3Ó7Ð9óˆCô
 ˜cŸm™m¬S×1Ñ1Ð1Ð1Ø"%§-¡-ˆDÔ÷ �TŽTús   ’A1BÂ
Bc                ó„  • U R                  5         U R                     U R                  R                  S[        R                  R	                  [        R
                  R                  5      R                  S5      [        U R                  5      S-
  U R                  45        SSS5        SU l
        g! , (       d  f       N= f)zCClose the database session, filling in the end time and line count.zRUPDATE sessions SET end=?, num_cmds=? WHERE
                            session==?râ   r[   Nr   )rÜ   r¶   r?   r&   rm   rn   ro   rp   rA  Úinput_hist_parsedr+  r³   s    r*   Úend_sessionÚHistoryManager.end_sessionù  s�   € à×ÑÔØ�W‹WØ�G‰G�O‰Oð*ô ×%Ñ%×)Ñ)¬(×*;Ñ*;×*?Ñ*?Ó@×JÑJÈ3ÓOÜ˜×.Ñ.Ó/°!Ñ3Ø×'Ñ'ðô÷ ð  ˆÕ÷ �Wús   �BB1Â1
B?c                ó¼   • [        S[        SS9  U R                     U R                  R                  SXR                  45        SSS5        g! , (       d  f       g= f)z8Give the current session a name in the history database.zPname_session is deprecated in IPython 9.0 and will be removed in future versionsrª   )Ú
stacklevelz-UPDATE sessions SET remark=? WHERE session==?N)r   ÚDeprecationWarningr¶   r?   r+  )rC   Únames     r*   Úname_sessionÚHistoryManager.name_session  sE   € äØ^ÜØò	
ð
 �W‹WØ�G‰G�O‰OØ?Ø×*Ñ*Ð+ô÷ �WŽWús   œ(AÁ
Ac                ó˜  • U R                   R                  5         U R                  R                  5         U R                  R                  5         [        R
                  " 5       /U R                  SS& U(       aR  U R                  (       a  U R                  5         S/U R                  SS& S/U R                  SS& U R                  5         gg)z^Clear the session history, releasing all object references, and
optionally open a new session.Nr  )Úoutput_histÚclearr)  r*  r   r$  r"  r+  rX  rW  Úinput_hist_rawr<  )rC   r<  s     r*   ÚresetÚHistoryManager.reset  s›   € ð 	×Ñ×ÑÔ Ø�‰×ÑÔØ�‰×ÑÔô !ŸHšH›J˜<ˆ�‰‘aÐæØ×"×"Ø× Ñ Ô"Ø)+¨ˆD×"Ñ"¡1Ð%Ø&( TˆD×Ñ¡Ð"Ø×ÑÕð r,   c                óN   >• US::  a  XR                   -  n[        [        U ]  US9$ )a  Get info about a session.

Parameters
----------
session : int
    Session number to retrieve. The current session is 0, and negative
    numbers count back from current session, so -1 is the previous session.

Returns
-------
session_id : int
    Session ID number
start : datetime
    Timestamp for the start of the session.
end : datetime
    Timestamp for the end of the session, or None if IPython crashed.
num_cmds : int
    Number of commands run, or None if IPython crashed.
remark : str
    A manually set description.
r   )r�   )r+  rÃ   r   rú   )rC   r�   r¼   s     €r*   rú   ÚHistoryManager.get_session_info)  s/   ø€ ð0 �a‹<Ø×*Ñ*Ñ*ˆGä”^ TÑ;ÀGÐ;ÐLÐLr,   c           	     ó:  • U R                  5         U(       d  US-  n[        U R                  SU R                  U4UUS95      n[        U R                  SU R                  U4UUS95      nXV-   nUSU nU(       d  [        U5      SSS2   $ [        U5      SSS2   $ )a  Get the last n lines from the history database.

Most recent entry last.

Completion will be reordered so that that the last ones are when
possible from current session.

Parameters
----------
n : int
    The number of lines to get
raw, output : bool
    See :meth:`get_range`
include_latest : bool
    If False (default), n+1 lines are fetched, and the latest one
    is discarded. This is intended to be used where the function
    is called by a user command, which it should not return.

Returns
-------
Tuples as :meth:`get_range`
r[   z/WHERE session == ? ORDER BY line DESC LIMIT ?  r  z;WHERE session != ? ORDER BY session DESC, line DESC LIMIT ?Nr   rä   )rÜ   rR   rõ   r+  )rC   rƒ   r„   r…   r†   Úthis_curÚ	other_curÚ
everythings           r*   r‡   ÚHistoryManager.get_tailF  sÅ   € ð< 	×ÑÔÞØ�‰FˆAäØ�M‰MØAØ×$Ñ$ aÐ(ØØð	 ð ó
ˆô Ø�M‰MØMØ×$Ñ$ aÐ(ØØð	 ð ó
ˆ	ð 8@Ñ7Kˆ
à  �^ˆ
æÜ˜
Ó# E Q r EÑ*Ð*Ü�JÓ¡ " Ñ%Ð%r,   c              #  ó,  #   • U(       a  U R                   OU R                  n[        U5      nUS:  a  X-  nU(       a  X&:”  a  UnO
US:  a  X&-  n[        X5       H4  nU(       a   XW   U R                  R                  U5      4nOXW   nSXx4v •  M6     g7f)ziGet input and output history from the current session. Called by
get_range, and takes similar parameters.r   N)rc  rW  rA  rr   r(  Úget)	rC   r‘   r’   r„   r…   Ú
input_histrƒ   r{   Úlines	            r*   Ú_get_range_sessionÚ!HistoryManager._get_range_session�  s�   é € ö -0�T×(Ò(°T×5KÑ5Kˆ
ä�
‹OˆØ�1‹9Ø‰JˆEÞ˜›Ø‰DØ�A‹XØ‰IˆDä�uÖ#ˆAÞØ"™ t×'=Ñ'=×'AÑ'AÀ!Ó'DÐE‘à!‘}�Ø�a�,Ôò $ùs   ‚BBc                ó˜   >• US::  a  XR                   -  nXR                   :X  a  U R                  X#XE5      $ [        [        U ]  XX4U5      $ )aY  Retrieve input by session.

Parameters
----------
session : int
    Session number to retrieve. The current session is 0, and negative
    numbers count back from current session, so -1 is previous session.
start : int
    First line to retrieve.
stop : int
    End of line range (excluded from output itself). If None, retrieve
    to the end of the session.
raw : bool
    If True, return untranslated input
output : bool
    If True, attempt to include output. This will be 'real' Python
    objects for the current session, or text reprs from previous
    sessions if db_log_output was enabled at the time. Where no output
    is found, None is used.

Returns
-------
entries
    An iterator over the desired lines. Each line is a 3-tuple, either
    (session, line, input) if output is False, or
    (session, line, (input, output)) if output is True.
r   )r+  rq  rÃ   r   r“   )rC   r�   r‘   r’   r„   r…   r¼   s         €r*   r“   ÚHistoryManager.get_range›  sQ   ø€ ðF �a‹<Ø×*Ñ*Ñ*ˆGØ×)Ñ)Ó)Ø×*Ñ*¨5¸ÓDÐDÜ”^ TÑ4°WÀTÐPVÓWÐWr,   c                ó¦  • Uc  UnUR                  S5      nUR                  S5      nU R                  R                  UR                  5       5      (       a  gU R                  R                  U5        U R                  R                  U5        U R                     U R                  R                  XU45        [        U R                  5      U R                  :¼  aH  U R                  (       a7  U R                  5         U R                  b  U R                  R                  5         SSS5        U R                  U l        U R"                  U l        U R$                  U l        X0l        SU-  nSU R"                  SU R                  SU R                   X@R$                  0nU R&                  b  U R&                  R)                  USS9  gg! , (       d  f       N¦= f)	aS  Store source and raw input in history and create input cache
variables ``_i*``.

Parameters
----------
line_num : int
    The prompt number of this input.
source : str
    Python input.
source_raw : str, optional
    If given, this is the raw input without any IPython transformations
    applied to it.  If not given, ``source`` is used.
NÚ
z_i%sÚ_iÚ_iiÚ_iiiF)Úinteractive)ÚrstripÚ_exit_reÚmatchÚstriprW  Úappendrc  r:  r,  rA  Údb_cache_sizer=  rL  r0  Úsetrx  ry  rw  Ú_i00r6  Úpush)rC   Úline_numrà   rß   Únew_iÚto_mains         r*   Ústore_inputsÚHistoryManager.store_inputsÇ  sk  € ð  ÑØˆJØ—‘˜tÓ$ˆØ×&Ñ& tÓ,ˆ
ð �=‰=×Ñ˜z×/Ñ/Ó1×2Ñ2Øà×Ñ×%Ñ% fÔ-Ø×Ñ×"Ñ" :Ô.à×%Ó%Ø×Ñ×&Ñ&¨¸*Ð'EÔFä�4×&Ñ&Ó'¨4×+=Ñ+=Ó=Ø×$×$Ø×3Ñ3Ô5Ø—~‘~Ñ1ØŸ™×*Ñ*Ô,÷ &ð —H‘HˆŒ	Ø—7‘7ˆŒØ—)‘)ˆŒØŒ	ð ˜Ñ!ˆØ˜Ÿ™ %¨¯©°6¸4¿9¹9ÀeÏYÉYÐWˆà�:‰:Ñ!Ø�J‰J�O‰O˜G°ˆOÒ7ð "÷' &Õ%ús   ÂB	GÇ
Gc                ó¢  • U R                   (       a  XR                  ;  a  gUnU R                  U   nU R                     U R                  R	                  X45        SSS5        U R
                  S::  aK  U R                  (       a9  U R                  5         U R                  b  U R                  R                  5         gggg! , (       d  f       Nj= f)zÿIf database output logging is enabled, this saves all the
outputs from the indicated prompt number to the database. It's
called by run_cell after code has been executed.

Parameters
----------
line_num : int
    The line number from which to save outputs
Nr[   )
Údb_log_outputr(  r;  r-  r  r€  r=  rL  r0  r�  )rC   r„  Úlnumr…   s       r*   Ústore_outputÚHistoryManager.store_outputù  s§   € ð ×"×"¨×8NÑ8NÓ(NØØˆØ×'Ñ'¨Ñ1ˆà×&Ó&Ø× Ñ ×'Ñ'¨Ð(:Ô;÷ 'à×Ñ Ó" t×'8×'8Ø×+Ñ+Ô-Ø�~‰~Ñ)Ø—‘×"Ñ"Õ$ð *ð (9Ð"÷ 'Õ&ús   ¿C Ã 
Cc                ó¢   • U   U R                    H#  nUR                  SU R                  4U-   5        M%     S S S 5        g ! , (       d  f       g = f)Nz'INSERT INTO history VALUES (?, ?, ?, ?))r,  r?   r+  ©rC   rT  rp  s      r*   Ú_writeout_input_cacheÚ$HistoryManager._writeout_input_cache  s?   € ÚØ×+Ô+�Ø—‘Ø=Ø×(Ñ(Ð*¨TÑ1öñ ,÷ �TŽTúó   ƒ4A Á 
Ac                ó¢   • U   U R                    H#  nUR                  SU R                  4U-   5        M%     S S S 5        g ! , (       d  f       g = f)Nz+INSERT INTO output_history VALUES (?, ?, ?))r-  r?   r+  r�  s      r*   Ú_writeout_output_cacheÚ%HistoryManager._writeout_output_cache  s?   € ÚØ×,Ô,�Ø—‘ØAØ×(Ñ(Ð*¨TÑ1öñ -÷ �TŽTúr’  c                ó|  • Uc  U R                   nU R                      U R                  U5        / U l         SSS5        U R                      U R                  U5        / U l         SSS5        g! [        R                   aX    U R                  U5        [        SSU R                  5         U R                  U5         N�! [        R                   a      N§f = ff = f! / U l        f = f! , (       d  f       N¹= f! [        R                   a    [        SS5         N¿f = f! / U l        f = f! , (       d  f       g= f)z/Write any entries in the cache to the database.Nz,ERROR! Session/line number was not unique inz.database. History logging moved to new sessionz0!! Session/line number for output was not uniquez'in database. Output will not be stored.)r¶   r:  r�  r¹   ÚIntegrityErrorr<  Úprintr+  r,  r;  r”  r-  )rC   rT  s     r*   rÜ   ÚHistoryManager.writeout_cache  s"  € ð ‰<Ø—7‘7ˆDà×%Ó%ð)Ø×*Ñ*¨4Ô0ð ')�Õ#÷# &ð& ×&Ó&ð*Ø×+Ñ+¨DÔ1ð (*�Õ$÷ 'Ð&øô! ×)Ñ)ó Ø× Ñ  Ô&ÜØBØDØ×'Ñ'ôð
ð ×.Ñ.¨tÖ4øÜ×-Ñ-ó Úðúðûð ')�Õ#ú÷# &Õ%ûô, ×)Ñ)ó ÜØFØ=öðûð (*�Õ$ú÷ 'Õ&ús“   œC*žA/¯C*ÁD-ÁC;ÁD-Á/<CÂ,B?Â=CÂ?CÃCÃCÃCÃCÃCÃ	C'Ã'C*Ã*
C8Ã; DÄD!ÄDÄD!Ä!	D*Ä*D-Ä-
D;)rw  r‚  rx  ry  r,  r:  r-  r;  rc   r/  r+  r=  )rQ   z
list[Path])rQ   zthreading.Event | Noner%   )r6  r   r®   zOptional[Configuration]rÇ   rP   r  )rÆ   úOptional[str]rQ   r   )rT  zOptional[sqlite3.Connection]rQ   r  )r]  rf   rQ   r  )T)r<  r�   rQ   r  )r   r  r™   r›   r£   )
r‘   rœ   r’   r¢   r„   r�   r…   r�   rQ   rž   )r   r[   NTFr¤   )r„  rœ   rà   rf   rß   rš  rQ   r  )r„  rœ   rQ   r  )rT  zsqlite3.ConnectionrQ   r  )Cr1   r2   r3   r4   rS   r   r6  r   rW  rc  r"  r  r   r&  r   ra  r(  r   rR   r)  r*  r   r+  r
   r  rŠ  r€  r,  r-  r/  Úpropertyr0  r   r‚  rw  rx  ry  ÚreÚcompiler|  r   r2  Úfloatr4  rÄ   rD  ÚclassmethodrI  rL  rÅ   rY   r<  rX  r^  rd  rú   r|   r‡   rq  r“   r‡  rŒ  r�  r”  rÜ   r5   r  r  s   @r*   r   r   ^  sB  ø‡ ÙMñ
 Ø;Èñ€Eñ
 ˜b˜T›
ÐÙ˜2˜$“Z€Ná“V€HˆdÓáˆZÓóó ðñ “&€Ká/3«vÐÐ,Ó5á<GÈÓ<M€GÐ9ÓMá:>»&€JÐ7Ó@ñ "›)€N�CÓ#áØÐOñç	�c�€cÐð ñ Ø	ð;ñ÷ 
�c�€cÐð	 ñ 26³€NÐ.Ó7Ù-1«V€OÐ*Ó3ñ ÐEÐRVÑW€Kàóó ðñ �2‹;€DÙ	�‹€BÙ
�"‹+€CÙ�2‹;€Dð
 �zŠzÐ5Ó6€Há*1«)€JÐ'Ó3Ù" 5›\€Iˆ{Ó)ð
 +/ð&
àð&
ð (ð&
ð ÷	&
ð &
ôP$ð ó(ó ð(ô%ö4ð õ0ó ð0ô ôöð* ðMØðMà	W÷Mð Mð: ð ØØØ$ð8&àð8&ð ð8&ð ð	8&ð
 ð8&ð 
.ô8&ó ð8&ðx Ø"ØØðàðð ðð ð	ð
 ðð 
.õð8 ØØ"ØØð'Xàð'Xð ð'Xð ð	'Xð
 ð'Xð ð'Xð 
.÷'Xð 'XðZ GKð08Øð08Ø%(ð08Ø6Cð08à	õ08ôd%ô,ôð õ!*ó ö!*r,   r   Úregister_at_fork)Úbefore)ÚCallableÚIterator)ÚReferenceTypec              #  ó$   #   • U " 5       nU v •  Ag7f)ze
Context manger that hold a reference to a weak ref to make sure it
is not GC'd during it's context.
Nr/   )r   Úrs     r*   Úholdr§  L  s   é € ñ 	‹€AØ
‚IÙ	ùs   ‚c                  óœ   ^ • \ rS rSr% SrS\S'   SrS\S'   SrS\S	'   SrS\S
'   S\S'   Sr	SU 4S jjr
\SS j5       rSS jrSS jrSrU =r$ )r>  iW  a+  This thread takes care of writing history to the database, so that
the UI isn't held up while that happens.

It waits for the HistoryManager's save_flag to be set, then writes out
the history cache. The main thread is responsible for setting the flag when
the cache size reaches a defined threshold.zthreading.Eventr0  Tr�   ÚdaemonFÚ	_stop_nowrU   zref[HistoryManager]Úhistory_managerc                óž   >• [         [        U ]  SS9  [        U5      U l        UR
                  U l        [        R                  " 5       U l        g )NÚIPythonHistorySavingThread)r]  )	rÃ   r>  rÄ   r   r«  rU   r8  ÚEventr0  )rC   r«  r¼   s     €r*   rÄ   ÚHistorySavingThread.__init__f  s?   ø€ ÜÔ! 4Ñ1Ð7SÐ1ÑTÜ" ?Ó3ˆÔØ&×.Ñ.ˆŒÜ"ŸšÓ*ˆ�r,   c           
     óN  • [         R                  " U R                  5         [        U R                  5       nU" 5       bh  [
        R                  " [        U" 5       R                  5      40 [        [        [        [        R                  4   U" 5       R                  5      D6U l        S S S 5         U R                  R!                  5         [        U R                  5       nU" 5       c  SU l        U R"                  (       aD  U R                  R%                  5          S S S 5        [         R&                  " U R                  5        g U R                  R)                  5         U" 5       b   U" 5       R+                  U R                  5        S S S 5        Mà  ! , (       d  f       Nï= f! , (       d  f       N!= f! [,         a!  n[/        S[1        U5      -  5         S nAOS nAff = f[         R&                  " U R                  5        g ! [         R&                  " U R                  5        f = f)NTzcThe history saving thread hit an unexpected error (%s).History will not be written to the database.)ÚatexitÚregisterr’   r§  r«  r¹   rÙ   rf   rc   r   r²   Útr	   r¯   r¶   r0  Úwaitrª  rN   Ú
unregisterrb  rÜ   Ú	Exceptionr˜  Úrepr)rC   Úhmrv   s      r*   ÚrunÚHistorySavingThread.runl  s|  € ä�Š˜Ÿ	™	Ô"ð	)ä�d×*Ñ*Ô+¨rÙ“4Ñ#Ü%ŸošoÜ™B›DŸN™NÓ+ñäœt¤C¬¯© JÑ/±³×1HÑ1HÓIñ�D”G÷ ,ð Ø—‘×#Ñ#Ô%Ü˜$×.Ñ.Ô/°2Ù“t‘|Ø)-˜œØ—~—~ØŸ™Ÿ™œØ÷ 0ô& ×Ò˜dŸi™iÕ(ð —N‘N×(Ñ(Ô*Ù“tÑ'Ù›×+Ñ+¨D¯G©GÔ4÷ 0ñ ÷ ,Õ+ú÷ 0Õ/ûô ó 	ÜðCô �q“'ñ	÷ñ ûð	úô ×Ò˜dŸi™iÕ(øŒF×Ò˜dŸi™iÕ(úsf   ¢F3 ·A1FÂ(8F3 Ã <F"ÄF3 ÅAF"Æ
F3 Æ
FÆF3 Æ"
F0Æ,F3 Æ3
GÆ=GÇH ÇGÇH È"H$c                óÌ   • U R                   (       a  gSU l        U R                  R                  5         SU l         U [        R
                  " 5       :w  a  U R                  5         gg)zÙThis can be called from the main thread to safely stop this thread.

Note that it does not attempt to write out remaining history before
exiting. That should be done by calling the HistoryManager's
end_session method.NT)Ú_stoppedrª  r0  r�  r8  Úcurrent_threadÚjoinr³   s    r*   r’   ÚHistorySavingThread.stop�  sK   € ð �=�=ØØˆŒà�‰×ÑÔØˆŒØ”9×+Ò+Ó-Ó-Ø�I‰I�Kð .r,   c                ó$   • U R                  5         g r%   )r’   r³   s    r*   rD  ÚHistorySavingThread.__del__ž  s   € Ø�	‰	�r,   )rª  r¼  r¶   rU   r«  r0  )r«  r   rQ   r  r  )r1   r2   r3   r4   rS   r  r©  rª  rU   r¼  rÄ   rY   r¹  r’   rD  r5   r  r  s   @r*   r>  r>  W  sb   ø‡ ñ3ð ÓØ€FˆDÓØ€IˆtÓØ€GˆTÓØ(Ó(Ø€H÷+ð ó )ó ð )ôD÷ò r,   r>  zk
((?P<startsess>(?:~?\d+/)))?
(?P<start>\d+)?
((?P<sep>[\-:])
 ((?P<endsess>(?:~?\d+/)))?
 (?P<end>\d*))?
$c              #  ó^  #   • U S:X  a  Sv •  gU R                  5        GH‰  n[        R                  U5      nU(       d  M"  UR                  S5      nUR                  S5      nU(       aR  [	        U5      nUR                  S5      nUS:X  a  U(       a  [	        U5      S-   OSnO4U(       a  [	        U5      OUS-   nOUR                  S	5      (       d  Mµ  SnSnUR                  S	5      =(       d    S
nUR                  S5      =(       d    UnUR                  S5      nUR                  S5      n[	        UR                  SS5      5      n[	        UR                  SS5      5      nXv:¼  d   S5       eXv:X  a	  XcU4v •  GM_  XcS4v •  [        US-   U5       H
  nUSS4v •  M     USU4v •  GMŒ     g7f)a¤  Turn a string of history ranges into 3-tuples of (session, start, stop).

Empty string results in a `[(0, 1, None)]`, i.e. "everything from current
session".

Examples
--------
>>> list(extract_hist_ranges("~8/5-~7/4 2"))
[(-8, 5, None), (-7, 1, 5), (0, 2, 3)]
>>> list(extract_hist_ranges("~4/"))
[(-4, 1, None)]
>>> list(extract_hist_ranges("4-"))
[(0, 4, None)]
>>> list(extract_hist_ranges("~4/4-"))
[(-4, 4, None)]
r  )r   r[   NNr‘   ÚsepÚendÚ-r[   Ú	startsessÚ0ÚendsessÚ/Ú~z.start session must be earlier than end session)ÚsplitÚrange_rer}  Úgrouprœ   r{  rq   rr   )	Ú
ranges_strÚ	range_strÚrmatchr‘   rÃ  rÄ  rÆ  rÈ  r  s	            r*   r  r  ²  sŠ  é € ð" �RÓØÒØà×%Ñ%×'ˆ	Ü—‘ 	Ó*ˆÞÙØ—‘˜WÓ%ˆØ�l‰l˜5Ó!ˆÞÜ˜“JˆEØ—,‘,˜uÓ%ˆCØ�c‹zÞ(+”s˜3“x !’|°‘æ"%”c˜#”h¨5°1©9‘à—<‘< ×,Ñ,ÙØˆEØˆCØ—L‘L Ó-×4°ˆ	Ø—,‘,˜yÓ)×6¨YˆØ×$Ñ$ SÓ)ˆ	Ø—.‘. Ó%ˆÜ˜	×)Ñ)¨#¨sÓ3Ó4ˆ	Ü�g—o‘o c¨3Ó/Ó0ˆØÓ#ÐUÐ%UÓUÐ#àÓØ SÐ)Ò)Úà Ð&Ò&Ü˜) a™-¨Ö1ˆDØ˜˜D�/Ô!ñ 2à˜˜3ÐÕòC (ùs   ‚F+F-c                ó6   • U S:X  a  [        U5      $ U < SU< 3$ )z0Helper function to format line numbers properly.r   Ú#)rf   )r�   rp  s     r*   Ú_format_linenorÓ  ë  s   € à�!ƒ|Ü�4‹yÐÛštÐ$Ð$r,   )r   zReferenceType[HistoryManager]rQ   z'Iterator[ReferenceType[HistoryManager]])rÎ  rf   rQ   z(Iterable[tuple[int, int, Optional[int]]])r�   rœ   rp  rœ   rQ   rf   )TrS   Ú
__future__r   r±  r&   Úosrœ  rÓ   r8  Úpathlibr   Úcollectionsr   Ú
contextlibr   Údataclassesr   r   Ú	traitletsr	   r
   r   r   r   r   r   r   r   r   r   Útraitlets.config.configurabler   ÚIPython.pathsr   ÚIPython.utils.decoratorsr   Útypingr   r   r   Úcollections.abcr   r³  r   Úwarningsr   r   r   ÚIPython.core.interactiveshellr   ÚIPython.config.Configurationr    r¹   r!   r"   Úregister_converterr  ÚModuleNotFoundErrorr¶  rf   r  Ú	InOrInOutr:   rY   rl   r|   r~   r¨   r  r   Úhasattrr   rI  r¢  r£  r¤  r§  ÚThreadr>  r�  ÚVERBOSErÌ  r  rÓ  r/   r,   r*   Ú<module>ré     s÷  ðÙ .å "ó Û Û 	Û 	Û ó Ý å #Ý %Ý !Ý ÷÷ ÷ ñ õ >å (Ý *ß 1Ñ 1Ý $Û Û Ý Ý ß  æÝ>Ý:ðß7Ûà×ÒØÑNôð €Mð �L‰L˜˜e C¨°#©Ð$6Ñ7Ð7Ñ8€	ð ÷ð ó ðð* ñ!ó ð!ð €ð ñ2ó ð2ôj$"Ð-ô $"ôNDJÐ)ô DJðN ÷.ð .ó ð.ôc*�_ô c*ñL ˆ2Ð!×"Ñ"Ø×Ò˜~×:Ñ:Ò;÷ /Ý !ð ó
ó ð
ôH˜)×*Ñ*ô Hð^ �:Š:ðð ‡J�Jó	€ô6 õr%øð]% ó Ø€Mô˜	ô ô˜9÷ ðús   Â+"F4 Æ4GÇG