-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from cs50/excepthook
grays out site packages in tracebacks
- Loading branch information
Showing
12 changed files
with
136 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from distutils.version import StrictVersion | ||
from pkg_resources import get_distribution | ||
|
||
from .cs50 import formatException | ||
|
||
# Try to monkey-patch Flask, if installed | ||
try: | ||
|
||
# Only patch 0.12 (in case logging changes in 0.13) | ||
version = StrictVersion(get_distribution("flask").version) | ||
assert version >= StrictVersion("0.10") and version < StrictVersion("0.13") | ||
|
||
# Get default logger | ||
import flask.logging | ||
f = flask.logging.create_logger | ||
|
||
def create_logger(app): | ||
"""Wrap default logger""" | ||
|
||
# Create default logger | ||
logger = f(app) | ||
|
||
# Reformat default logger's exceptions | ||
# https://docs.python.org/3/library/logging.html#logging.Formatter.formatException | ||
for handler in logger.handlers: | ||
handler.formatter.formatException = lambda exc_info: formatException(*exc_info) | ||
return logger | ||
|
||
# Replace default logger | ||
flask.logging.create_logger = create_logger | ||
|
||
except: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import requests | ||
from flask import Flask, render_template | ||
|
||
import cs50 | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def index(): | ||
def f(): | ||
res = requests.get("cs50.harvard.edu") | ||
f() | ||
return render_template("index.html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cs50 | ||
Flask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<title>error</title> | ||
</head> | ||
<body> | ||
error | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<title>flask</title> | ||
</head> | ||
<body> | ||
flask | ||
</body> | ||
</html> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from cs50 import SQL | ||
|
||
db = SQL("sqlite:///sqlite.db") | ||
db.execute("SELECT 1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import cs50 | ||
import requests | ||
|
||
def f(): | ||
res = requests.get("cs50.harvard.edu") | ||
f() |