55
66
77import atexit
8- import datetime
98import re
109import sqlite3
1110import threading
1211from pathlib import Path
12+ from datetime import datetime
1313
1414from decorator import decorator
1515from traitlets import (
3030from IPython .paths import locate_profile
3131from IPython .utils .decorators import undoc
3232
33+
34+ # get rid of :
35+ # Python/core/tests/test_history.py::test_timestamp_type
36+ # IPython/core/history.py:335: DeprecationWarning:
37+ # The default timestamp converter is deprecated as of Python 3.12;
38+ # see the sqlite3 documentation for suggested replacement recipes
39+ # return self.db.execute(query, (session,)).fetchone()
40+ #
41+ #
42+ def convert_timestamp (val ):
43+ """Convert Unix epoch timestamp to datetime.datetime object."""
44+ return datetime .fromtimestamp (val )
45+
46+
47+ sqlite3 .register_converter ("timestamp" , convert_timestamp )
48+
3349#-----------------------------------------------------------------------------
3450# Classes and functions
3551#-----------------------------------------------------------------------------
@@ -90,8 +106,8 @@ def catch_corrupt_db(f, self, *a, **kw):
90106 size = self .hist_file .stat ().st_size
91107 if size >= _SAVE_DB_SIZE :
92108 # if there's significant content, avoid clobbering
93- now = datetime .datetime . now ().isoformat ().replace (':' , '.' )
94- newpath = base + ' -corrupt-' + now + ext
109+ now = datetime .now ().isoformat ().replace (":" , "." )
110+ newpath = base + " -corrupt-" + now + ext
95111 # don't clobber previous corrupt backups
96112 for i in range (100 ):
97113 if not Path (newpath ).exists ():
@@ -583,7 +599,7 @@ def new_session(self, conn=None):
583599 cur = conn .execute (
584600 """INSERT INTO sessions VALUES (NULL, ?, NULL,
585601 NULL, '') """ ,
586- (datetime .datetime . now ().isoformat (" " ),),
602+ (datetime .now ().isoformat (" " ),),
587603 )
588604 self .session_number = cur .lastrowid
589605
@@ -595,7 +611,7 @@ def end_session(self):
595611 """UPDATE sessions SET end=?, num_cmds=? WHERE
596612 session==?""" ,
597613 (
598- datetime .datetime . now ().isoformat (" " ),
614+ datetime .now ().isoformat (" " ),
599615 len (self .input_hist_parsed ) - 1 ,
600616 self .session_number ,
601617 ),
0 commit comments