Skip to content

Commit

Permalink
Merge pull request #78 from cs50/develop
Browse files Browse the repository at this point in the history
adds support for other paramstyles
  • Loading branch information
dmalan authored Jul 1, 2019
2 parents 63a77fd + 12747c7 commit 93f1751
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 199 deletions.
51 changes: 20 additions & 31 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
language: python
python:
- '2.7'
- '3.6'
python: '3.6'
branches:
except: "/^v\\d/"
services:
- mysql
- postgresql
- mysql
- postgresql
install:
- python setup.py install
- pip install mysqlclient
- pip install psycopg2-binary
- python setup.py install
- pip install mysqlclient
- pip install psycopg2-binary
before_script:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- psql -c 'create database test;' -U postgres
- touch test.db test1.db
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- psql -c 'create database test;' -U postgres
- touch test.db test1.db
script: python tests/sql.py
after_script: rm -f test.db
jobs:
include:
- stage: deploy
python: '3.6'
install: skip
before_script: skip
script: skip
deploy:
- provider: script
script: 'curl --fail --data "{ \"tag_name\": \"v$(python setup.py --version)\",
\"target_commitish\": \"$TRAVIS_COMMIT\", \"name\": \"v$(python setup.py --version)\"
}" --user bot50:$GITHUB_TOKEN https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases'
on:
branch: master
- provider: pypi
user: "$PYPI_USERNAME"
password: "$PYPI_PASSWORD"
on:
branch: master
deploy:
- provider: script
script: 'curl --fail --data "{ \"tag_name\": \"v$(python setup.py --version)\",
\"target_commitish\": \"$TRAVIS_COMMIT\", \"name\": \"v$(python setup.py --version)\"
}" --user bot50:$GITHUB_TOKEN https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases'
on:
branch: master
- provider: pypi
user: "$PYPI_USERNAME"
password: "$PYPI_PASSWORD"
on: master
notifications:
slack:
secure: lJklhcBVjDT6KzUNa3RFHXdXSeH7ytuuGrkZ5ZcR72CXMoTf2pMJTzPwRLWOp6lCSdDC9Y8MWLrcg/e33dJga4Jlp9alOmWqeqesaFjfee4st8vAsgNbv8/RajPH1gD2bnkt8oIwUzdHItdb5AucKFYjbH2g0d8ndoqYqUeBLrnsT1AP5G/Vi9OHC9OWNpR0FKaZIJE0Wt52vkPMH3sV2mFeIskByPB+56U5y547mualKxn61IVR/dhYBEtZQJuSvnwKHPOn9Pkk7cCa+SSSeTJ4w5LboY8T17otaYNauXo46i1bKIoGiBcCcrJyQHHiPQmcq/YU540MC5Wzt9YXUycmJzRi347oyQeDee27wV3XJlWMXuuhbtJiKCFny7BTQ160VATlj/dbwIzN99Ra6/BtTumv/6LyTdKIuVjdAkcN8dtdDW1nlrQ29zuPNCcXXzJ7zX7kQaOCUV1c2OrsbiH/0fE9nknUORn97txqhlYVi0QMS7764wFo6kg0vpmFQRkkQySsJl+TmgcZ01AlsJc2EMMWVuaj9Af9JU4/4yalqDiXIh1fOYYUZnLfOfWS+MsnI+/oLfqJFyMbrsQQTIjs+kTzbiEdhd2R4EZgusU/xRFWokS2NAvahexrRhRQ6tpAI+LezPrkNOR3aHiykBf+P9BkUa0wPp6V2Ayc6q0=
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# CS50 Library for Python

[![Build Status](https://travis-ci.org/cs50/python-cs50.svg?branch=master)](https://travis-ci.org/cs50/python-cs50)

Supports Python 2 and Python 3.
[![Build Status](https://travis-ci.com/cs50/python-cs50.svg?branch=master)](https://travis-ci.org/cs50/python-cs50)

## Installation

Expand All @@ -19,13 +17,4 @@ pip install cs50
c = cs50.get_char();
f = cs50.get_float();
i = cs50.get_int();
l = cs50.get_long(); # Python 2 only
s = cs50.get_string();

# References

- https://github.com/ronsavage/SQL/blob/master/sql-92.bnf#L19-L72

## TODO
* Add targets for `pacman`, `rpm`.
* Add tests.
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="3.1.0"
version="3.2.0"
)
4 changes: 2 additions & 2 deletions src/cs50/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
try:

# Save student's sys.path
path = sys.path[:]
_path = sys.path[:]

# In case student has files that shadow packages
sys.path = [p for p in sys.path if p not in ("", os.getcwd())]
Expand All @@ -25,4 +25,4 @@
finally:

# Restore student's sys.path (just in case library raised an exception that caller caught)
sys.path = path
sys.path = _path
38 changes: 30 additions & 8 deletions src/cs50/flask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from distutils.version import StrictVersion
from os import getenv
from pkg_resources import get_distribution
Expand All @@ -8,31 +10,51 @@
try:

# Only patch >= 1.0
version = StrictVersion(get_distribution("flask").version)
assert version >= StrictVersion("1.0")
_version = StrictVersion(get_distribution("flask").version)
assert _version >= StrictVersion("1.0")

# Reformat logger's exceptions
# http://flask.pocoo.org/docs/1.0/logging/
# https://docs.python.org/3/library/logging.html#logging.Formatter.formatException
try:
import flask.logging
flask.logging.default_handler.formatter.formatException = lambda exc_info: formatException(*exc_info)
except:
except Exception:
pass

# Enable logging when Flask is in use,
# monkey-patching own SQL module, which shouldn't need to know about Flask
logging.getLogger("cs50").disabled = True
try:
import flask
from .sql import SQL
except ImportError:
pass
else:
_before = SQL.execute
def _after(*args, **kwargs):
disabled = logging.getLogger("cs50").disabled
if flask.current_app:
logging.getLogger("cs50").disabled = False
try:
return _before(*args, **kwargs)
finally:
logging.getLogger("cs50").disabled = disabled
SQL.execute = _after

# Add support for Cloud9 proxy so that flask.redirect doesn't redirect from HTTPS to HTTP
# http://stackoverflow.com/a/23504684/5156190
if getenv("C9_HOSTNAME") and not getenv("IDE_OFFLINE"):
try:
import flask
from werkzeug.contrib.fixers import ProxyFix
before = flask.Flask.__init__
def after(self, *args, **kwargs):
before(self, *args, **kwargs)
_before = flask.Flask.__init__
def _after(*args, **kwargs):
_before(*args, **kwargs)
self.wsgi_app = ProxyFix(self.wsgi_app)
flask.Flask.__init__ = after
flask.Flask.__init__ = _after
except:
pass

except:
except Exception:
pass
Loading

0 comments on commit 93f1751

Please sign in to comment.