Skip to content

Commit f7d7961

Browse files
author
Kareem Zidane
authored
Merge pull request #68 from cs50/develop
v3.0.1
2 parents d731c45 + 07ca0cb commit f7d7961

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
package_dir={"": "src"},
1717
packages=["cs50"],
1818
url="https://github.com/cs50/python-cs50",
19-
version="3.0.0"
19+
version="3.0.1"
2020
)

src/cs50/flask.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from distutils.version import StrictVersion
2+
from os import getenv
23
from pkg_resources import get_distribution
34

45
from .cs50 import formatException
@@ -9,12 +10,29 @@
910
# Only patch >= 1.0
1011
version = StrictVersion(get_distribution("flask").version)
1112
assert version >= StrictVersion("1.0")
12-
import flask.logging
1313

1414
# Reformat logger's exceptions
1515
# http://flask.pocoo.org/docs/1.0/logging/
1616
# https://docs.python.org/3/library/logging.html#logging.Formatter.formatException
17-
flask.logging.default_handler.formatter.formatException = lambda exc_info: formatException(*exc_info)
17+
try:
18+
import flask.logging
19+
flask.logging.default_handler.formatter.formatException = lambda exc_info: formatException(*exc_info)
20+
except:
21+
pass
22+
23+
# Add support for Cloud9 proxy so that flask.redirect doesn't redirect from HTTPS to HTTP
24+
# http://stackoverflow.com/a/23504684/5156190
25+
if getenv("C9_HOSTNAME") and not getenv("IDE_OFFLINE"):
26+
try:
27+
import flask
28+
from werkzeug.contrib.fixers import ProxyFix
29+
before = flask.Flask.__init__
30+
def after(self, *args, **kwargs):
31+
before(self, *args, **kwargs)
32+
self.wsgi_app = ProxyFix(self.wsgi_app)
33+
flask.Flask.__init__ = after
34+
except:
35+
pass
1836

1937
except:
2038
pass

tests/redirect/application.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cs50
2+
from flask import Flask, redirect, render_template
3+
4+
app = Flask(__name__)
5+
6+
@app.route("/")
7+
def index():
8+
return redirect("/foo")
9+
10+
@app.route("/foo")
11+
def foo():
12+
return render_template("foo.html")

tests/redirect/templates/foo.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo

0 commit comments

Comments
 (0)