Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cs50/python-cs50
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v9.2.3
Choose a base ref
...
head repository: cs50/python-cs50
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Dec 2, 2022

  1. Copy the full SHA
    3ccbd99 View commit details

Commits on Jan 29, 2023

  1. Respect pep8 and revert 659c8f4

    As described in pep8: "Object type comparisons should always use isinstance() instead of comparing types directly:"
    
    Ref. https://peps.python.org/pep-0008/
    up-n-atom authored Jan 29, 2023
    Copy the full SHA
    777b4da View commit details
  2. Fix order of datetime type checks

    datetime.datetime inherits datetime.date and will prematurely evaluate as an instance of datetime.date.
    up-n-atom authored Jan 29, 2023
    Copy the full SHA
    6096c7e View commit details
  3. bumped version number

    rongxin-liu committed Jan 29, 2023
    Copy the full SHA
    53cf4d2 View commit details
  4. Merge pull request #172 from up-n-atom/type-checking

    Respect pep8 and revert 659c8f4
    rongxin-liu authored Jan 29, 2023
    Copy the full SHA
    5c06978 View commit details
  5. Copy the full SHA
    464f237 View commit details

Commits on Sep 13, 2023

  1. Copy the full SHA
    f807f1e View commit details
  2. Copy the full SHA
    ca09441 View commit details

Commits on Sep 15, 2023

  1. Copy the full SHA
    2ed4803 View commit details

Commits on Sep 23, 2023

  1. Fix method delegation in _flushfile

    Required when the faked stream is already faked and the original fake also uses method delegation.
    aivarannamaa authored Sep 23, 2023
    Copy the full SHA
    b8581fe View commit details
  2. Merge pull request #1 from aivarannamaa/aivarannamaa-flushfile-getattr

    Fix method delegation in _flushfile
    aivarannamaa authored Sep 23, 2023
    Copy the full SHA
    c5b093f View commit details

Commits on Sep 29, 2023

  1. Copy the full SHA
    4424e65 View commit details
  2. Merge pull request #176 from cs50/create-view

    Adds support for 'CREATE VIEW' statement
    rongxin-liu authored Sep 29, 2023
    Copy the full SHA
    955637c View commit details

Commits on Oct 4, 2023

  1. Copy the full SHA
    0608340 View commit details

Commits on Oct 17, 2023

  1. Copy the full SHA
    b3f0a0c View commit details

Commits on Oct 24, 2023

  1. Copy the full SHA
    f42ff32 View commit details
  2. Copy the full SHA
    bb72634 View commit details
  3. Copy the full SHA
    3ddef31 View commit details
  4. Merge pull request #174 from cs50/SQLAlchemy-2.0

    Support SQLAlchemy 2.0
    rongxin-liu authored Oct 24, 2023
    Copy the full SHA
    fcc8cb9 View commit details

Commits on Dec 17, 2023

  1. Merge pull request #175 from aivarannamaa/main

    Fix method delegation in `_flushfile`
    dmalan authored Dec 17, 2023
    Copy the full SHA
    62ad33c View commit details
  2. Copy the full SHA
    1b644dd View commit details
  3. fixes #178

    dmalan committed Dec 17, 2023
    Copy the full SHA
    e18486c View commit details
  4. increments version

    dmalan committed Dec 17, 2023
    Copy the full SHA
    781c1c2 View commit details
  5. increments version

    dmalan committed Dec 17, 2023
    Copy the full SHA
    14a9741 View commit details
  6. Copy the full SHA
    d981368 View commit details
  7. Merge pull request #180 from cs50/updates

    updated IO wrapper, style, version
    dmalan authored Dec 17, 2023
    Copy the full SHA
    c73d1d2 View commit details

Commits on Dec 18, 2023

  1. updated style

    dmalan committed Dec 18, 2023
    Copy the full SHA
    fc6647a View commit details
  2. fixed YAML

    dmalan committed Dec 18, 2023
    Copy the full SHA
    128f498 View commit details
  3. fixed merge

    dmalan committed Dec 18, 2023
    Copy the full SHA
    3b90369 View commit details
  4. updated for MySQL tests

    dmalan committed Dec 18, 2023
    Copy the full SHA
    e47cc35 View commit details
  5. updated SQLAlchemy versioning

    dmalan committed Dec 18, 2023
    Copy the full SHA
    dc6a43f View commit details

Commits on Mar 4, 2024

  1. updated workflow actions

    rongxin-liu committed Mar 4, 2024
    Copy the full SHA
    688af68 View commit details

Commits on May 2, 2024

  1. Copy the full SHA
    d67a26b View commit details

Commits on Oct 15, 2024

  1. adds support for VACUUM

    dmalan committed Oct 15, 2024
    Copy the full SHA
    2d5fd94 View commit details
  2. fixes raw strings

    dmalan committed Oct 15, 2024
    Copy the full SHA
    f81a0a3 View commit details
  3. Merge pull request #186 from cs50/vacuum

    Adds support for `VACUUM`, fixes raw strings
    rongxin-liu authored Oct 15, 2024
    Copy the full SHA
    e75afaf View commit details
Showing with 248 additions and 117 deletions.
  1. +4 −4 .github/workflows/main.yml
  2. +1 −0 .gitignore
  3. +2 −2 docker-compose.yml
  4. +2 −2 setup.py
  5. +1 −0 src/cs50/__init__.py
  6. +34 −18 src/cs50/cs50.py
  7. +13 −4 src/cs50/flask.py
  8. +184 −86 src/cs50/sql.py
  9. +7 −1 tests/sql.py
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -20,15 +20,15 @@ jobs:
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.7'
check-latest: true
- name: Setup databases
run: |
pip install .
pip install mysqlclient psycopg2-binary
pip install mysqlclient psycopg2-binary SQLAlchemy
- name: Run tests
run: python tests/sql.py
@@ -56,7 +56,7 @@ jobs:
- name: Create Release
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.*
!/.github/
!.gitignore
build/
*.db
*.egg-info/
*.pyc
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ services:
- postgres
environment:
MYSQL_HOST: mysql
POSTGRESQL_HOST: postgresql
POSTGRESQL_HOST: postgres
links:
- mysql
- postgres
@@ -20,7 +20,7 @@ services:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
healthcheck:
test: ["CMD", "mysqladmin", "-uroot", "ping"]
image: cs50/mysql:8
image: cs50/mysql
ports:
- 3306:3306
postgres:
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@
"Topic :: Software Development :: Libraries :: Python Modules"
],
description="CS50 library for Python",
install_requires=["Flask>=1.0", "SQLAlchemy", "sqlparse", "termcolor", "wheel"],
install_requires=["Flask>=1.0", "packaging", "SQLAlchemy>=2,<3", "sqlparse", "termcolor", "wheel"],
keywords="cs50",
license="GPLv3",
long_description_content_type="text/markdown",
name="cs50",
package_dir={"": "src"},
packages=["cs50"],
url="https://github.com/cs50/python-cs50",
version="9.2.3"
version="9.4.0"
)
1 change: 1 addition & 0 deletions src/cs50/__init__.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

# Import cs50_*
from .cs50 import get_char, get_float, get_int, get_string

try:
from .cs50 import get_long
except ImportError:
52 changes: 34 additions & 18 deletions src/cs50/cs50.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
import re
import sys

from distutils.sysconfig import get_python_lib
from os.path import abspath, join
from termcolor import colored
from traceback import format_exception
@@ -18,7 +17,9 @@

try:
# Patch formatException
logging.root.handlers[0].formatter.formatException = lambda exc_info: _formatException(*exc_info)
logging.root.handlers[
0
].formatter.formatException = lambda exc_info: _formatException(*exc_info)
except IndexError:
pass

@@ -38,26 +39,31 @@
_logger.addHandler(handler)


class _flushfile():
class _Unbuffered:
"""
Disable buffering for standard output and standard error.
http://stackoverflow.com/a/231216
https://stackoverflow.com/a/107717
https://docs.python.org/3/library/io.html
"""

def __init__(self, f):
self.f = f
def __init__(self, stream):
self.stream = stream

def __getattr__(self, name):
return object.__getattribute__(self.f, name)
def __getattr__(self, attr):
return getattr(self.stream, attr)

def write(self, x):
self.f.write(x)
self.f.flush()
def write(self, b):
self.stream.write(b)
self.stream.flush()

def writelines(self, lines):
self.stream.writelines(lines)
self.stream.flush()

sys.stderr = _flushfile(sys.stderr)
sys.stdout = _flushfile(sys.stdout)

sys.stderr = _Unbuffered(sys.stderr)
sys.stdout = _Unbuffered(sys.stdout)


def _formatException(type, value, tb):
@@ -79,19 +85,29 @@ def _formatException(type, value, tb):
lines += line
else:
matches = re.search(r"^(\s*)(.*?)(\s*)$", line, re.DOTALL)
lines.append(matches.group(1) + colored(matches.group(2), "yellow") + matches.group(3))
lines.append(
matches.group(1)
+ colored(matches.group(2), "yellow")
+ matches.group(3)
)
return "".join(lines).rstrip()


sys.excepthook = lambda type, value, tb: print(_formatException(type, value, tb), file=sys.stderr)
sys.excepthook = lambda type, value, tb: print(
_formatException(type, value, tb), file=sys.stderr
)


def eprint(*args, **kwargs):
raise RuntimeError("The CS50 Library for Python no longer supports eprint, but you can use print instead!")
raise RuntimeError(
"The CS50 Library for Python no longer supports eprint, but you can use print instead!"
)


def get_char(prompt):
raise RuntimeError("The CS50 Library for Python no longer supports get_char, but you can use get_string instead!")
raise RuntimeError(
"The CS50 Library for Python no longer supports get_char, but you can use get_string instead!"
)


def get_float(prompt):
@@ -135,7 +151,7 @@ def get_string(prompt):
as line endings. If user inputs only a line ending, returns "", not None.
Returns None upon error or no input whatsoever (i.e., just EOF).
"""
if type(prompt) is not str:
if not isinstance(prompt, str):
raise TypeError("prompt must be of type str")
try:
return input(prompt)
17 changes: 13 additions & 4 deletions src/cs50/flask.py
Original file line number Diff line number Diff line change
@@ -2,22 +2,31 @@
import pkgutil
import sys


def _wrap_flask(f):
if f is None:
return

from distutils.version import StrictVersion
from packaging.version import Version, InvalidVersion
from .cs50 import _formatException

if f.__version__ < StrictVersion("1.0"):
try:
if Version(f.__version__) < Version("1.0"):
return
except InvalidVersion:
return

if os.getenv("CS50_IDE_TYPE") == "online":
from werkzeug.middleware.proxy_fix import ProxyFix

_flask_init_before = f.Flask.__init__

def _flask_init_after(self, *args, **kwargs):
_flask_init_before(self, *args, **kwargs)
self.wsgi_app = ProxyFix(self.wsgi_app, x_proto=1) # For HTTPS-to-HTTP proxy
self.wsgi_app = ProxyFix(
self.wsgi_app, x_proto=1
) # For HTTPS-to-HTTP proxy

f.Flask.__init__ = _flask_init_after


@@ -27,7 +36,7 @@ def _flask_init_after(self, *args, **kwargs):

# If Flask wasn't imported
else:
flask_loader = pkgutil.get_loader('flask')
flask_loader = pkgutil.get_loader("flask")
if flask_loader:
_exec_module_before = flask_loader.exec_module

Loading