示例#1
0
文件: core.py 项目: graingert/httpbin
        response.data += b'\n'
    return response


# Prevent WSGI from correcting the casing of the Location header
BaseResponse.autocorrect_location_header = False

# Find the correct template folder when running from a different location
tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                        'templates')

app = Flask(__name__, template_folder=tmpl_dir)
app.debug = bool(os.environ.get('DEBUG'))

# Setup Flask-Common.
common = Common(app)

# Send app errors to Sentry.
if 'SENTRY_DSN' in os.environ:
    sentry = Sentry(app, dsn=os.environ['SENTRY_DSN'])

# Set up Bugsnag exception tracking, if desired. To use Bugsnag, install the
# Bugsnag Python client with the command "pip install bugsnag", and set the
# environment variable BUGSNAG_API_KEY. You can also optionally set
# BUGSNAG_RELEASE_STAGE.
if os.environ.get("BUGSNAG_API_KEY") is not None:
    try:
        import bugsnag
        import bugsnag.flask
        release_stage = os.environ.get("BUGSNAG_RELEASE_STAGE") or "production"
        bugsnag.configure(api_key=os.environ.get("BUGSNAG_API_KEY"),
示例#2
0
import os
from codecs import open

import redis
import hypermark
import flask

from pyquery import PyQuery as pq
from flask import Flask, render_template, abort
from flask_common import Common

app = Flask(__name__)

common = Common(app)
r = redis.from_url(os.environ['REDIS_URL'])

class Entry(object):
    def __init__(self, path):
        self.path = path

    @property
    def html(self):
        with open(self.path, 'rb', 'utf-8') as f:
            return hypermark.text(f.read()).html

    @property
    def title(self):
        return pq(self.html)('h1')[0].text

    @property
    def slug(self):