Skip to content

Commit f42ff32

Browse files
committed
Merge branch 'main' into SQLAlchemy-2.0
2 parents 0608340 + b3f0a0c commit f42ff32

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
"Topic :: Software Development :: Libraries :: Python Modules"
1111
],
1212
description="CS50 library for Python",
13-
install_requires=["Flask>=1.0", "SQLAlchemy<3", "sqlparse", "termcolor", "wheel"],
13+
install_requires=["Flask>=1.0", "packaging", "SQLAlchemy==1.4.46", "sqlparse", "termcolor", "wheel"],
1414
keywords="cs50",
1515
license="GPLv3",
1616
long_description_content_type="text/markdown",
1717
name="cs50",
1818
package_dir={"": "src"},
1919
packages=["cs50"],
2020
url="https://github.com/cs50/python-cs50",
21-
version="9.2.6"
21+
version="9.2.7"
2222
)

src/cs50/cs50.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import re
77
import sys
88

9-
from distutils.sysconfig import get_python_lib
109
from os.path import abspath, join
1110
from termcolor import colored
1211
from traceback import format_exception

src/cs50/flask.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ def _wrap_flask(f):
66
if f is None:
77
return
88

9-
from distutils.version import StrictVersion
9+
from packaging.version import Version, InvalidVersion
1010
from .cs50 import _formatException
1111

12-
if f.__version__ < StrictVersion("1.0"):
12+
try:
13+
if Version(f.__version__) < Version("1.0"):
14+
return
15+
except InvalidVersion:
1316
return
1417

1518
if os.getenv("CS50_IDE_TYPE") == "online":

src/cs50/sql.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ def execute(self, sql, *args, **kwargs):
149149
if len(args) > 0 and len(kwargs) > 0:
150150
raise RuntimeError("cannot pass both positional and named parameters")
151151

152-
# Infer command from (unflattened) statement
153-
for token in statements[0]:
154-
if token.ttype in [sqlparse.tokens.Keyword, sqlparse.tokens.Keyword.DDL, sqlparse.tokens.Keyword.DML]:
155-
token_value = token.value.upper()
156-
if token_value in ["BEGIN", "DELETE", "INSERT", "SELECT", "START", "UPDATE"]:
157-
command = token_value
158-
break
159-
else:
160-
command = None
152+
# Infer command from flattened statement to a single string separated by spaces
153+
full_statement = ' '.join(str(token) for token in statements[0].tokens if token.ttype in [sqlparse.tokens.Keyword, sqlparse.tokens.Keyword.DDL, sqlparse.tokens.Keyword.DML])
154+
full_statement = full_statement.upper()
155+
156+
# set of possible commands
157+
commands = {"BEGIN", "CREATE VIEW", "DELETE", "INSERT", "SELECT", "START", "UPDATE"}
158+
159+
# check if the full_statement starts with any command
160+
command = next((cmd for cmd in commands if full_statement.startswith(cmd)), None)
161161

162162
# Flatten statement
163163
tokens = list(statements[0].flatten())
@@ -393,6 +393,10 @@ def teardown_appcontext(exception):
393393
elif command in ["DELETE", "UPDATE"]:
394394
ret = result.rowcount
395395

396+
# If CREATE VIEW, return True
397+
elif command == "CREATE VIEW":
398+
ret = True
399+
396400
# If constraint violated
397401
except sqlalchemy.exc.IntegrityError as e:
398402
self._logger.error(termcolor.colored(_statement, "red"))

0 commit comments

Comments
 (0)