We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
SQLite Import Error on 7.3.0
I'm now getting a 
`ModuleNotFoundError: No module named '_sqlite3'`
error right upon import. Is there a way to catch this?



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `praw/util/token_manager.py`
Content:
```
1 """Token Manager classes.
2 
3 There should be a 1-to-1 mapping between an instance of a subclass of
4 :class:`.BaseTokenManager` and a :class:`.Reddit` instance.
5 
6 A few proof of concept token manager classes are provided here, but it is expected that
7 PRAW users will create their own token manager classes suitable for their needs.
8 
9 .. deprecated:: 7.4.0
10 
11     Tokens managers have been depreciated and will be removed in the near future.
12 
13 """
14 import sqlite3
15 from abc import ABC, abstractmethod
16 
17 
18 class BaseTokenManager(ABC):
19     """An abstract class for all token managers."""
20 
21     def __init__(self):
22         """Prepare attributes needed by all token manager classes."""
23         self._reddit = None
24 
25     @property
26     def reddit(self):
27         """Return the :class:`.Reddit` instance bound to the token manager."""
28         return self._reddit
29 
30     @reddit.setter
31     def reddit(self, value):
32         if self._reddit is not None:
33             raise RuntimeError(
34                 "``reddit`` can only be set once and is done automatically"
35             )
36         self._reddit = value
37 
38     @abstractmethod
39     def post_refresh_callback(self, authorizer):
40         """Handle callback that is invoked after a refresh token is used.
41 
42         :param authorizer: The ``prawcore.Authorizer`` instance used containing
43             ``access_token`` and ``refresh_token`` attributes.
44 
45         This function will be called after refreshing the access and refresh tokens.
46         This callback can be used for saving the updated ``refresh_token``.
47 
48         """
49 
50     @abstractmethod
51     def pre_refresh_callback(self, authorizer):
52         """Handle callback that is invoked before refreshing PRAW's authorization.
53 
54         :param authorizer: The ``prawcore.Authorizer`` instance used containing
55             ``access_token`` and ``refresh_token`` attributes.
56 
57         This callback can be used to inspect and modify the attributes of the
58         ``prawcore.Authorizer`` instance, such as setting the ``refresh_token``.
59 
60         """
61 
62 
63 class FileTokenManager(BaseTokenManager):
64     """Provides a single-file based token manager.
65 
66     It is expected that the file with the initial ``refresh_token`` is created prior to
67     use.
68 
69     .. warning::
70 
71         The same ``file`` should not be used by more than one instance of this class
72         concurrently. Doing so may result in data corruption. Consider using
73         :class:`.SQLiteTokenManager` if you want more than one instance of PRAW to
74         concurrently manage a specific ``refresh_token`` chain.
75 
76     """
77 
78     def __init__(self, filename):
79         """Load and save refresh tokens from a file.
80 
81         :param filename: The file the contains the refresh token.
82 
83         """
84         super().__init__()
85         self._filename = filename
86 
87     def post_refresh_callback(self, authorizer):
88         """Update the saved copy of the refresh token."""
89         with open(self._filename, "w") as fp:
90             fp.write(authorizer.refresh_token)
91 
92     def pre_refresh_callback(self, authorizer):
93         """Load the refresh token from the file."""
94         if authorizer.refresh_token is None:
95             with open(self._filename) as fp:
96                 authorizer.refresh_token = fp.read().strip()
97 
98 
99 class SQLiteTokenManager(BaseTokenManager):
100     """Provides a SQLite3 based token manager.
101 
102     Unlike, :class:`.FileTokenManager`, the initial database need not be created ahead
103     of time, as it'll automatically be created on first use. However, initial
104     ``refresh_tokens`` will need to be registered via :meth:`.register` prior to use.
105 
106     .. warning::
107 
108         This class is untested on Windows because we encountered file locking issues in
109         the test environment.
110 
111     """
112 
113     def __init__(self, database, key):
114         """Load and save refresh tokens from a SQLite database.
115 
116         :param database: The path to the SQLite database.
117         :param key: The key used to locate the ``refresh_token``. This ``key`` can be
118             anything. You might use the ``client_id`` if you expect to have unique
119             ``refresh_tokens`` for each ``client_id``, or you might use a Redditor's
120             ``username`` if you're manage multiple users' authentications.
121 
122         """
123         super().__init__()
124         self._connection = sqlite3.connect(database)
125         self._connection.execute(
126             "CREATE TABLE IF NOT EXISTS tokens (id, refresh_token, updated_at)"
127         )
128         self._connection.execute(
129             "CREATE UNIQUE INDEX IF NOT EXISTS ux_tokens_id on tokens(id)"
130         )
131         self._connection.commit()
132         self.key = key
133 
134     def _get(self):
135         cursor = self._connection.execute(
136             "SELECT refresh_token FROM tokens WHERE id=?", (self.key,)
137         )
138         result = cursor.fetchone()
139         if result is None:
140             raise KeyError
141         return result[0]
142 
143     def _set(self, refresh_token):
144         """Set the refresh token in the database.
145 
146         This function will overwrite an existing value if the corresponding ``key``
147         already exists.
148 
149         """
150         self._connection.execute(
151             "REPLACE INTO tokens VALUES (?, ?, datetime('now'))",
152             (self.key, refresh_token),
153         )
154         self._connection.commit()
155 
156     def is_registered(self):
157         """Return whether or not ``key`` already has a ``refresh_token``."""
158         cursor = self._connection.execute(
159             "SELECT refresh_token FROM tokens WHERE id=?", (self.key,)
160         )
161         return cursor.fetchone() is not None
162 
163     def post_refresh_callback(self, authorizer):
164         """Update the refresh token in the database."""
165         self._set(authorizer.refresh_token)
166 
167         # While the following line is not strictly necessary, it ensures that the
168         # refresh token is not used elsewhere. And also forces the pre_refresh_callback
169         # to always load the latest refresh_token from the database.
170         authorizer.refresh_token = None
171 
172     def pre_refresh_callback(self, authorizer):
173         """Load the refresh token from the database."""
174         assert authorizer.refresh_token is None
175         authorizer.refresh_token = self._get()
176 
177     def register(self, refresh_token):
178         """Register the initial refresh token in the database.
179 
180         :returns: ``True`` if ``refresh_token`` is saved to the database, otherwise,
181             ``False`` if there is already a ``refresh_token`` for the associated
182             ``key``.
183 
184         """
185         cursor = self._connection.execute(
186             "INSERT OR IGNORE INTO tokens VALUES (?, ?, datetime('now'))",
187             (self.key, refresh_token),
188         )
189         self._connection.commit()
190         return cursor.rowcount == 1
191
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/praw/util/token_manager.py b/praw/util/token_manager.py
--- a/praw/util/token_manager.py
+++ b/praw/util/token_manager.py
@@ -11,7 +11,6 @@
     Tokens managers have been depreciated and will be removed in the near future.
 
 """
-import sqlite3
 from abc import ABC, abstractmethod
 
 
@@ -121,6 +120,8 @@
 
         """
         super().__init__()
+        import sqlite3
+
         self._connection = sqlite3.connect(database)
         self._connection.execute(
             "CREATE TABLE IF NOT EXISTS tokens (id, refresh_token, updated_at)"

{"golden_diff": "diff --git a/praw/util/token_manager.py b/praw/util/token_manager.py\n--- a/praw/util/token_manager.py\n+++ b/praw/util/token_manager.py\n@@ -11,7 +11,6 @@\n     Tokens managers have been depreciated and will be removed in the near future.\n \n \"\"\"\n-import sqlite3\n from abc import ABC, abstractmethod\n \n \n@@ -121,6 +120,8 @@\n \n         \"\"\"\n         super().__init__()\n+        import sqlite3\n+\n         self._connection = sqlite3.connect(database)\n         self._connection.execute(\n             \"CREATE TABLE IF NOT EXISTS tokens (id, refresh_token, updated_at)\"\n", "issue": "SQLite Import Error on 7.3.0\nI'm now getting a \r\n`ModuleNotFoundError: No module named '_sqlite3'`\r\nerror right upon import. Is there a way to catch this?\r\n\r\n\n", "before_files": [{"content": "\"\"\"Token Manager classes.\n\nThere should be a 1-to-1 mapping between an instance of a subclass of\n:class:`.BaseTokenManager` and a :class:`.Reddit` instance.\n\nA few proof of concept token manager classes are provided here, but it is expected that\nPRAW users will create their own token manager classes suitable for their needs.\n\n.. deprecated:: 7.4.0\n\n    Tokens managers have been depreciated and will be removed in the near future.\n\n\"\"\"\nimport sqlite3\nfrom abc import ABC, abstractmethod\n\n\nclass BaseTokenManager(ABC):\n    \"\"\"An abstract class for all token managers.\"\"\"\n\n    def __init__(self):\n        \"\"\"Prepare attributes needed by all token manager classes.\"\"\"\n        self._reddit = None\n\n    @property\n    def reddit(self):\n        \"\"\"Return the :class:`.Reddit` instance bound to the token manager.\"\"\"\n        return self._reddit\n\n    @reddit.setter\n    def reddit(self, value):\n        if self._reddit is not None:\n            raise RuntimeError(\n                \"``reddit`` can only be set once and is done automatically\"\n            )\n        self._reddit = value\n\n    @abstractmethod\n    def post_refresh_callback(self, authorizer):\n        \"\"\"Handle callback that is invoked after a refresh token is used.\n\n        :param authorizer: The ``prawcore.Authorizer`` instance used containing\n            ``access_token`` and ``refresh_token`` attributes.\n\n        This function will be called after refreshing the access and refresh tokens.\n        This callback can be used for saving the updated ``refresh_token``.\n\n        \"\"\"\n\n    @abstractmethod\n    def pre_refresh_callback(self, authorizer):\n        \"\"\"Handle callback that is invoked before refreshing PRAW's authorization.\n\n        :param authorizer: The ``prawcore.Authorizer`` instance used containing\n            ``access_token`` and ``refresh_token`` attributes.\n\n        This callback can be used to inspect and modify the attributes of the\n        ``prawcore.Authorizer`` instance, such as setting the ``refresh_token``.\n\n        \"\"\"\n\n\nclass FileTokenManager(BaseTokenManager):\n    \"\"\"Provides a single-file based token manager.\n\n    It is expected that the file with the initial ``refresh_token`` is created prior to\n    use.\n\n    .. warning::\n\n        The same ``file`` should not be used by more than one instance of this class\n        concurrently. Doing so may result in data corruption. Consider using\n        :class:`.SQLiteTokenManager` if you want more than one instance of PRAW to\n        concurrently manage a specific ``refresh_token`` chain.\n\n    \"\"\"\n\n    def __init__(self, filename):\n        \"\"\"Load and save refresh tokens from a file.\n\n        :param filename: The file the contains the refresh token.\n\n        \"\"\"\n        super().__init__()\n        self._filename = filename\n\n    def post_refresh_callback(self, authorizer):\n        \"\"\"Update the saved copy of the refresh token.\"\"\"\n        with open(self._filename, \"w\") as fp:\n            fp.write(authorizer.refresh_token)\n\n    def pre_refresh_callback(self, authorizer):\n        \"\"\"Load the refresh token from the file.\"\"\"\n        if authorizer.refresh_token is None:\n            with open(self._filename) as fp:\n                authorizer.refresh_token = fp.read().strip()\n\n\nclass SQLiteTokenManager(BaseTokenManager):\n    \"\"\"Provides a SQLite3 based token manager.\n\n    Unlike, :class:`.FileTokenManager`, the initial database need not be created ahead\n    of time, as it'll automatically be created on first use. However, initial\n    ``refresh_tokens`` will need to be registered via :meth:`.register` prior to use.\n\n    .. warning::\n\n        This class is untested on Windows because we encountered file locking issues in\n        the test environment.\n\n    \"\"\"\n\n    def __init__(self, database, key):\n        \"\"\"Load and save refresh tokens from a SQLite database.\n\n        :param database: The path to the SQLite database.\n        :param key: The key used to locate the ``refresh_token``. This ``key`` can be\n            anything. You might use the ``client_id`` if you expect to have unique\n            ``refresh_tokens`` for each ``client_id``, or you might use a Redditor's\n            ``username`` if you're manage multiple users' authentications.\n\n        \"\"\"\n        super().__init__()\n        self._connection = sqlite3.connect(database)\n        self._connection.execute(\n            \"CREATE TABLE IF NOT EXISTS tokens (id, refresh_token, updated_at)\"\n        )\n        self._connection.execute(\n            \"CREATE UNIQUE INDEX IF NOT EXISTS ux_tokens_id on tokens(id)\"\n        )\n        self._connection.commit()\n        self.key = key\n\n    def _get(self):\n        cursor = self._connection.execute(\n            \"SELECT refresh_token FROM tokens WHERE id=?\", (self.key,)\n        )\n        result = cursor.fetchone()\n        if result is None:\n            raise KeyError\n        return result[0]\n\n    def _set(self, refresh_token):\n        \"\"\"Set the refresh token in the database.\n\n        This function will overwrite an existing value if the corresponding ``key``\n        already exists.\n\n        \"\"\"\n        self._connection.execute(\n            \"REPLACE INTO tokens VALUES (?, ?, datetime('now'))\",\n            (self.key, refresh_token),\n        )\n        self._connection.commit()\n\n    def is_registered(self):\n        \"\"\"Return whether or not ``key`` already has a ``refresh_token``.\"\"\"\n        cursor = self._connection.execute(\n            \"SELECT refresh_token FROM tokens WHERE id=?\", (self.key,)\n        )\n        return cursor.fetchone() is not None\n\n    def post_refresh_callback(self, authorizer):\n        \"\"\"Update the refresh token in the database.\"\"\"\n        self._set(authorizer.refresh_token)\n\n        # While the following line is not strictly necessary, it ensures that the\n        # refresh token is not used elsewhere. And also forces the pre_refresh_callback\n        # to always load the latest refresh_token from the database.\n        authorizer.refresh_token = None\n\n    def pre_refresh_callback(self, authorizer):\n        \"\"\"Load the refresh token from the database.\"\"\"\n        assert authorizer.refresh_token is None\n        authorizer.refresh_token = self._get()\n\n    def register(self, refresh_token):\n        \"\"\"Register the initial refresh token in the database.\n\n        :returns: ``True`` if ``refresh_token`` is saved to the database, otherwise,\n            ``False`` if there is already a ``refresh_token`` for the associated\n            ``key``.\n\n        \"\"\"\n        cursor = self._connection.execute(\n            \"INSERT OR IGNORE INTO tokens VALUES (?, ?, datetime('now'))\",\n            (self.key, refresh_token),\n        )\n        self._connection.commit()\n        return cursor.rowcount == 1\n", "path": "praw/util/token_manager.py"}], "after_files": [{"content": "\"\"\"Token Manager classes.\n\nThere should be a 1-to-1 mapping between an instance of a subclass of\n:class:`.BaseTokenManager` and a :class:`.Reddit` instance.\n\nA few proof of concept token manager classes are provided here, but it is expected that\nPRAW users will create their own token manager classes suitable for their needs.\n\n.. deprecated:: 7.4.0\n\n    Tokens managers have been depreciated and will be removed in the near future.\n\n\"\"\"\nfrom abc import ABC, abstractmethod\n\n\nclass BaseTokenManager(ABC):\n    \"\"\"An abstract class for all token managers.\"\"\"\n\n    def __init__(self):\n        \"\"\"Prepare attributes needed by all token manager classes.\"\"\"\n        self._reddit = None\n\n    @property\n    def reddit(self):\n        \"\"\"Return the :class:`.Reddit` instance bound to the token manager.\"\"\"\n        return self._reddit\n\n    @reddit.setter\n    def reddit(self, value):\n        if self._reddit is not None:\n            raise RuntimeError(\n                \"``reddit`` can only be set once and is done automatically\"\n            )\n        self._reddit = value\n\n    @abstractmethod\n    def post_refresh_callback(self, authorizer):\n        \"\"\"Handle callback that is invoked after a refresh token is used.\n\n        :param authorizer: The ``prawcore.Authorizer`` instance used containing\n            ``access_token`` and ``refresh_token`` attributes.\n\n        This function will be called after refreshing the access and refresh tokens.\n        This callback can be used for saving the updated ``refresh_token``.\n\n        \"\"\"\n\n    @abstractmethod\n    def pre_refresh_callback(self, authorizer):\n        \"\"\"Handle callback that is invoked before refreshing PRAW's authorization.\n\n        :param authorizer: The ``prawcore.Authorizer`` instance used containing\n            ``access_token`` and ``refresh_token`` attributes.\n\n        This callback can be used to inspect and modify the attributes of the\n        ``prawcore.Authorizer`` instance, such as setting the ``refresh_token``.\n\n        \"\"\"\n\n\nclass FileTokenManager(BaseTokenManager):\n    \"\"\"Provides a single-file based token manager.\n\n    It is expected that the file with the initial ``refresh_token`` is created prior to\n    use.\n\n    .. warning::\n\n        The same ``file`` should not be used by more than one instance of this class\n        concurrently. Doing so may result in data corruption. Consider using\n        :class:`.SQLiteTokenManager` if you want more than one instance of PRAW to\n        concurrently manage a specific ``refresh_token`` chain.\n\n    \"\"\"\n\n    def __init__(self, filename):\n        \"\"\"Load and save refresh tokens from a file.\n\n        :param filename: The file the contains the refresh token.\n\n        \"\"\"\n        super().__init__()\n        self._filename = filename\n\n    def post_refresh_callback(self, authorizer):\n        \"\"\"Update the saved copy of the refresh token.\"\"\"\n        with open(self._filename, \"w\") as fp:\n            fp.write(authorizer.refresh_token)\n\n    def pre_refresh_callback(self, authorizer):\n        \"\"\"Load the refresh token from the file.\"\"\"\n        if authorizer.refresh_token is None:\n            with open(self._filename) as fp:\n                authorizer.refresh_token = fp.read().strip()\n\n\nclass SQLiteTokenManager(BaseTokenManager):\n    \"\"\"Provides a SQLite3 based token manager.\n\n    Unlike, :class:`.FileTokenManager`, the initial database need not be created ahead\n    of time, as it'll automatically be created on first use. However, initial\n    ``refresh_tokens`` will need to be registered via :meth:`.register` prior to use.\n\n    .. warning::\n\n        This class is untested on Windows because we encountered file locking issues in\n        the test environment.\n\n    \"\"\"\n\n    def __init__(self, database, key):\n        \"\"\"Load and save refresh tokens from a SQLite database.\n\n        :param database: The path to the SQLite database.\n        :param key: The key used to locate the ``refresh_token``. This ``key`` can be\n            anything. You might use the ``client_id`` if you expect to have unique\n            ``refresh_tokens`` for each ``client_id``, or you might use a Redditor's\n            ``username`` if you're manage multiple users' authentications.\n\n        \"\"\"\n        super().__init__()\n        import sqlite3\n\n        self._connection = sqlite3.connect(database)\n        self._connection.execute(\n            \"CREATE TABLE IF NOT EXISTS tokens (id, refresh_token, updated_at)\"\n        )\n        self._connection.execute(\n            \"CREATE UNIQUE INDEX IF NOT EXISTS ux_tokens_id on tokens(id)\"\n        )\n        self._connection.commit()\n        self.key = key\n\n    def _get(self):\n        cursor = self._connection.execute(\n            \"SELECT refresh_token FROM tokens WHERE id=?\", (self.key,)\n        )\n        result = cursor.fetchone()\n        if result is None:\n            raise KeyError\n        return result[0]\n\n    def _set(self, refresh_token):\n        \"\"\"Set the refresh token in the database.\n\n        This function will overwrite an existing value if the corresponding ``key``\n        already exists.\n\n        \"\"\"\n        self._connection.execute(\n            \"REPLACE INTO tokens VALUES (?, ?, datetime('now'))\",\n            (self.key, refresh_token),\n        )\n        self._connection.commit()\n\n    def is_registered(self):\n        \"\"\"Return whether or not ``key`` already has a ``refresh_token``.\"\"\"\n        cursor = self._connection.execute(\n            \"SELECT refresh_token FROM tokens WHERE id=?\", (self.key,)\n        )\n        return cursor.fetchone() is not None\n\n    def post_refresh_callback(self, authorizer):\n        \"\"\"Update the refresh token in the database.\"\"\"\n        self._set(authorizer.refresh_token)\n\n        # While the following line is not strictly necessary, it ensures that the\n        # refresh token is not used elsewhere. And also forces the pre_refresh_callback\n        # to always load the latest refresh_token from the database.\n        authorizer.refresh_token = None\n\n    def pre_refresh_callback(self, authorizer):\n        \"\"\"Load the refresh token from the database.\"\"\"\n        assert authorizer.refresh_token is None\n        authorizer.refresh_token = self._get()\n\n    def register(self, refresh_token):\n        \"\"\"Register the initial refresh token in the database.\n\n        :returns: ``True`` if ``refresh_token`` is saved to the database, otherwise,\n            ``False`` if there is already a ``refresh_token`` for the associated\n            ``key``.\n\n        \"\"\"\n        cursor = self._connection.execute(\n            \"INSERT OR IGNORE INTO tokens VALUES (?, ?, datetime('now'))\",\n            (self.key, refresh_token),\n        )\n        self._connection.commit()\n        return cursor.rowcount == 1\n", "path": "praw/util/token_manager.py"}]}