Skip to content

Commit

Permalink
Merge pull request #67 from cs50/develop
Browse files Browse the repository at this point in the history
2019 version
  • Loading branch information
Kareem Zidane authored Dec 29, 2018
2 parents 5a89ecb + 242442d commit d731c45
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
package_dir={"": "src"},
packages=["cs50"],
url="https://github.com/cs50/python-cs50",
version="2.4.4"
version="3.0.0"
)
2 changes: 1 addition & 1 deletion src/cs50/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
sys.path = [p for p in sys.path if p not in ("", os.getcwd())]

# Import cs50_*
from .cs50 import eprint, get_char, get_float, get_int, get_string
from .cs50 import get_char, get_float, get_int, get_string
try:
from .cs50 import get_long
except ImportError:
Expand Down
12 changes: 0 additions & 12 deletions src/cs50/cs50.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ def read(self, size):
sys.stdout = flushfile(sys.stdout)


def eprint(*args, **kwargs):
"""
Print an error message to standard error, prefixing it with
file name and line number from which method was called.
"""
end = kwargs.get("end", "\n")
sep = kwargs.get("sep", " ")
(filename, lineno) = inspect.stack()[1][1:3]
print("{}:{}: ".format(filename, lineno), end="")
print(*args, end=end, file=sys.stderr, sep=sep)


def formatException(type, value, tb):
"""
Format traceback, darkening entries from global site-packages directories
Expand Down
19 changes: 9 additions & 10 deletions src/cs50/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ def _parse(self, e):
return str(e)

def execute(self, text, **params):
"""
Execute a SQL statement.
"""
"""Execute a SQL statement."""

class UserDefinedType(sqlalchemy.TypeDecorator):
"""
Add support for expandable values, a la https://bitbucket.org/zzzeek/sqlalchemy/issues/3953/expanding-parameter.
"""
"""Add support for expandable values, a la https://github.com/sqlalchemy/sqlalchemy/issues/3953."""

# Required class-level attribute
# https://docs.sqlalchemy.org/en/latest/core/custom_types.html#sqlalchemy.types.TypeDecorator
impl = sqlalchemy.types.UserDefinedType

def process_literal_param(self, value, dialect):
"""Receive a literal parameter value to be rendered inline within a statement."""

def process(value):
"""Render a literal value, escaping as needed."""

Expand Down Expand Up @@ -147,8 +147,7 @@ def process(value):
else:
return process(value)

# Allow only one statement at a time
# SQLite does not support executing many statements
# Allow only one statement at a time, since SQLite doesn't support multiple
# https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.execute
if len(sqlparse.split(text)) > 1:
raise RuntimeError("too many statements at once")
Expand Down Expand Up @@ -234,10 +233,10 @@ def process(value):
def _connect(dbapi_connection, connection_record):
"""Enables foreign key support."""

# Ensure backend is sqlite
# If back end is sqlite
if type(dbapi_connection) is sqlite3.Connection:
cursor = dbapi_connection.cursor()

# Respect foreign key constraints by default
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()

0 comments on commit d731c45

Please sign in to comment.