Source code for pyrsslocal.rss.rss_flask

"""
Uses `Flask <http://flask.pocoo.org/>`_ to build pages.


:githublink:`%|py|5`
"""
import os
from flask import Flask, Response, render_template

try:
    from .rss_flask_helper import get_text_file, get_binary_file
except ImportError:
    from rss_flask_helper import get_text_file, get_binary_file

import sys
if hasattr(sys, 'enable_disabled_documented_pieces_of_code') and sys.enable_disabled_documented_pieces_of_code:
# -- HELP BEGIN EXCLUDE --
    
    app = Flask(__name__)
    app.config.from_object(__name__)
    
# -- HELP END EXCLUDE --


import sys
if hasattr(sys, 'enable_disabled_documented_pieces_of_code') and sys.enable_disabled_documented_pieces_of_code:
# -- HELP BEGIN EXCLUDE --
    
    # @app.route("/")
    pass
# -- HELP END EXCLUDE --
[docs]def main_page(): """ Serves the main page. :githublink:`%|py|28` """ return get_resource("rss_reader.html")
import sys if hasattr(sys, 'enable_disabled_documented_pieces_of_code') and sys.enable_disabled_documented_pieces_of_code: # -- HELP BEGIN EXCLUDE -- # @app.errorhandler(500) pass # -- HELP END EXCLUDE --
[docs]def internal_error(error): """ Intercepts an error. :githublink:`%|py|39` """ return render_template("errors.html", error=str(error), message="Internal Error"), 500
import sys if hasattr(sys, 'enable_disabled_documented_pieces_of_code') and sys.enable_disabled_documented_pieces_of_code: # -- HELP BEGIN EXCLUDE -- # @app.errorhandler(404) pass # -- HELP END EXCLUDE --
[docs]def not_found(error): """ Intercepts an error. :githublink:`%|py|52` """ return render_template("errors.html", error=str(error), message="Not Found"), 404
import sys if hasattr(sys, 'enable_disabled_documented_pieces_of_code') and sys.enable_disabled_documented_pieces_of_code: # -- HELP BEGIN EXCLUDE -- # @app.route('/js/', defaults={'path': ''}) # @app.route('/js/<path:path>') pass # -- HELP END EXCLUDE --
[docs]def get_js(path): # pragma: no cover """ Serves static files. :param path: relative path :return: content :githublink:`%|py|69` """ try: mimetypes = { ".js": ("application/javascript", get_text_file), } ext = os.path.splitext(path)[1] cp = mimetypes[ext] mimetype = cp[0] content = cp[1](os.path.join("..", "javascript", path)) r = Response(content, mimetype=mimetype) return r except Exception as e: print(e) raise e
import sys if hasattr(sys, 'enable_disabled_documented_pieces_of_code') and sys.enable_disabled_documented_pieces_of_code: # -- HELP BEGIN EXCLUDE -- # @app.route('/logs/', defaults={'path': ''}) # @app.route('/logs/<path:path>') pass # -- HELP END EXCLUDE --
[docs]def url_logging(path): # pragma: no cover """ Serves static files. :param path: relative path :return: content :githublink:`%|py|96` """ print("logging", path)
import sys if hasattr(sys, 'enable_disabled_documented_pieces_of_code') and sys.enable_disabled_documented_pieces_of_code: # -- HELP BEGIN EXCLUDE -- # @app.route('/', defaults={'path': ''}) # @app.route('/<path:path>') pass # -- HELP END EXCLUDE --
[docs]def get_resource(path): # pragma: no cover """ Serves static files. :param path: relative path :return: content :githublink:`%|py|111` """ try: mimetypes = { ".css": ("text/css", get_text_file), ".html": ("text/html", get_text_file), ".js": ("application/javascript", get_text_file), ".png": ("image/png", get_binary_file), } ext = os.path.splitext(path)[1] cp = mimetypes.get(ext, ("text/plain", get_binary_file)) mimetype = cp[0] content = cp[1](path) r = Response(content, mimetype=mimetype) return r except Exception as e: print(e) raise e
import sys if hasattr(sys, 'enable_disabled_documented_pieces_of_code') and sys.enable_disabled_documented_pieces_of_code: # -- HELP BEGIN EXCLUDE -- if __name__ == "__main__": app.run() # -- HELP END EXCLUDE --