File tree Expand file tree Collapse file tree 1 file changed +2
-24
lines changed
Expand file tree Collapse file tree 1 file changed +2
-24
lines changed Original file line number Diff line number Diff line change 11import os
22import sys
33
4-
5- class CustomImporter (object ):
6- """
7- Import cs50.SQL lazily for performance (and so that rest of library can be used without SQLAlchemy installed).
8- https://docs.python.org/3/library/imp.html
9- http://xion.org.pl/2012/05/06/hacking-python-imports/
10- http://dangerontheranger.blogspot.com/2012/07/how-to-use-sysmetapath-with-python.html
11- """
12-
13- def find_module (self , fullname , path = None ):
14- if fullname == "cs50.SQL" :
15- return self
16- return None
17-
18- def load_module (self , name ):
19- if name in sys .modules :
20- return sys .modules [name ]
21- from .sql import SQL
22- sys .modules [name ] = SQL
23- return SQL
24-
25-
264try :
275
286 # Save student's sys.path
@@ -41,8 +19,8 @@ def load_module(self, name):
4119 # Replace Flask's logger
4220 from . import flask
4321
44- # Lazily load CS50.SQL
45- sys . meta_path . append ( CustomImporter ())
22+ # Wrap SQLAlchemy
23+ from . sql import SQL
4624
4725finally :
4826
You can’t perform that action at this time.
0 commit comments