예제 #1
0
파일: app.py 프로젝트: diezguerra/pastepm
def notfound(e):
    return redirect("/")


@app.errorhandler(500)
def internal_server_error(e):
    return redirect("/")


url_mapping = {
    "post": {"url": "/post", "cls": PastePost},
    "view": {"url": "/<string:id>.<string:extension>", "cls": PasteViewWithExtension},
    "raw": {"url": "/raw/<string:id>", "cls": RawView},
    "fork": {"url": "/fork/<string:id>", "cls": ForkView},
    "view2": {"url": "/<string:id>", "cls": PasteViewWithoutExtension},
    "register": {"url": "/register", "cls": RegisterView},
    "paypal_start": {"url": "/paypal/start", "cls": PayPalStart},
    "paypal_confirm": {"url": "/paypal/confirm", "cls": PayPalConfirm},
    "paypal_do": {"url": "/paypal/do/<string:token>", "cls": PayPalDo},
    "paypal_status": {"url": "/paypal/status/<string:token>", "cls": PayPalStatus},
}

for view in url_mapping:
    mapping = url_mapping[view]
    app.add_url_rule(mapping["url"], view_func=mapping["cls"].as_view(view))

app.secret_key = config.get("security", "secret_key")

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8123, debug=True)
예제 #2
0
from pastepm.config import config
from pastepm.lib.pyclassifier import Classifier

c = Classifier.from_data(open(config.get('pyclassifier', 'file')))
language_ext_pairs = c.get_classes()

def language_detect(code):
    return c.identify(code)

def get_language_from_extension(extension):
    for language, ext in language_ext_pairs:
        if ext == extension: return language.lower()