Skip to content

Commit

Permalink
Remove sqlite3 fallback imports and associated checks.
Browse files Browse the repository at this point in the history
sqlite3 was add to the stdlib in python2.5
  • Loading branch information
terrdavis authored and Carreau committed Feb 27, 2020
1 parent c1ce3a2 commit 7a0bdab
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions IPython/core/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
import datetime
import os
import re
try:
import sqlite3
except ImportError:
try:
from pysqlite2 import dbapi2 as sqlite3
except ImportError:
sqlite3 = None
import sqlite3
import threading

from traitlets.config.configurable import LoggingConfigurable
Expand Down Expand Up @@ -49,26 +43,8 @@ def __exit__(self, *args, **kwargs):
pass


@decorator
def needs_sqlite(f, self, *a, **kw):
"""Decorator: return an empty list in the absence of sqlite."""
if sqlite3 is None or not self.enabled:
return []
else:
return f(self, *a, **kw)


if sqlite3 is not None:
DatabaseError = sqlite3.DatabaseError
OperationalError = sqlite3.OperationalError
else:
@undoc
class DatabaseError(Exception):
"Dummy exception when sqlite could not be imported. Should never occur."

@undoc
class OperationalError(Exception):
"Dummy exception when sqlite could not be imported. Should never occur."
DatabaseError = sqlite3.DatabaseError
OperationalError = sqlite3.OperationalError

# use 16kB as threshold for whether a corrupt history db should be saved
# that should be at least 100 entries or so
Expand Down Expand Up @@ -302,7 +278,6 @@ def _run_sql(self, sql, params, raw=True, output=False):
return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur)
return cur

@needs_sqlite
@catch_corrupt_db
def get_session_info(self, session):
"""Get info about a session.
Expand Down Expand Up @@ -558,7 +533,6 @@ def _get_hist_file_name(self, profile=None):
profile_dir = self.shell.profile_dir.location
return os.path.join(profile_dir, 'history.sqlite')

@needs_sqlite
def new_session(self, conn=None):
"""Get a new session number."""
if conn is None:
Expand Down Expand Up @@ -769,7 +743,6 @@ def _writeout_output_cache(self, conn):
conn.execute("INSERT INTO output_history VALUES (?, ?, ?)",
(self.session_number,)+line)

@needs_sqlite
def writeout_cache(self, conn=None):
"""Write any entries in the cache to the database."""
if conn is None:
Expand Down Expand Up @@ -818,7 +791,6 @@ def __init__(self, history_manager):
self.enabled = history_manager.enabled
atexit.register(self.stop)

@needs_sqlite
def run(self):
# We need a separate db connection per thread:
try:
Expand Down

0 comments on commit 7a0bdab

Please sign in to comment.