diff --git a/rophako/app.py b/rophako/app.py index e36335d..4209060 100644 --- a/rophako/app.py +++ b/rophako/app.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Flask app for Rophako.""" @@ -35,8 +35,14 @@ from rophako.log import logger #import rophako.model.tracking as Tracking import rophako.utils +# String escaping for the secret key (processes \ escapes properly), the +# escape encoding name varies between Python 2 and 3. +string_escape = "string_escape" if sys.version_info[0] == 2 \ + else "unicode_escape" + app.DEBUG = Config.site.debug == "true" -app.secret_key = Config.security.secret_key.decode("string_escape") +app.secret_key = bytes(Config.security.secret_key.encode("utf-8")) \ + .decode(string_escape) # Security? if Config.security.force_ssl == "true": diff --git a/rophako/jsondb.py b/rophako/jsondb.py index e5921ca..cdfe16d 100644 --- a/rophako/jsondb.py +++ b/rophako/jsondb.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, print_function, absolute_import """JSON flat file database system.""" import codecs import os import os.path -import glob import re from fcntl import flock, LOCK_EX, LOCK_SH, LOCK_UN import redis @@ -215,7 +214,7 @@ def get_redis(): ) redis_client.ping() except Exception as e: - logger.error("Couldn't connect to Redis; memory caching will be disabled! {}".format(e.message)) + logger.error("Couldn't connect to Redis; memory caching will be disabled! {}".format(e)) redis_client = None disable_redis = True return redis_client diff --git a/rophako/log.py b/rophako/log.py index 44956c6..8e2bb70 100644 --- a/rophako/log.py +++ b/rophako/log.py @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, print_function, absolute_import """Debug and logging functions.""" -from __future__ import print_function - -from flask import g, request import logging from rophako.settings import Config @@ -17,9 +14,6 @@ class LogHandler(logging.Handler): # The initial log line, which has the $prefix$ in it. line = self.format(record) - # Is the user logged in? - name = "-nobody-" - line = line.replace('$prefix$', '') print(line) diff --git a/rophako/model/blog.py b/rophako/model/blog.py index fff0d3f..a9f9255 100644 --- a/rophako/model/blog.py +++ b/rophako/model/blog.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Blog models.""" diff --git a/rophako/model/comment.py b/rophako/model/comment.py index 7b815ed..36939be 100644 --- a/rophako/model/comment.py +++ b/rophako/model/comment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Commenting models.""" diff --git a/rophako/model/emoticons.py b/rophako/model/emoticons.py index 1216028..a8d5b1f 100644 --- a/rophako/model/emoticons.py +++ b/rophako/model/emoticons.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Emoticon models.""" diff --git a/rophako/model/photo.py b/rophako/model/photo.py index 6b58e31..09b37e3 100644 --- a/rophako/model/photo.py +++ b/rophako/model/photo.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Photo album models.""" diff --git a/rophako/model/tracking.py b/rophako/model/tracking.py index f4a5561..b710953 100644 --- a/rophako/model/tracking.py +++ b/rophako/model/tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Visitor tracking models.""" diff --git a/rophako/model/user.py b/rophako/model/user.py index 819a995..cc998ee 100644 --- a/rophako/model/user.py +++ b/rophako/model/user.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """User account models.""" diff --git a/rophako/model/wiki.py b/rophako/model/wiki.py index e34bd42..993e1a1 100644 --- a/rophako/model/wiki.py +++ b/rophako/model/wiki.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Wiki models.""" diff --git a/rophako/modules/account/__init__.py b/rophako/modules/account/__init__.py index 09ebd03..505de3c 100644 --- a/rophako/modules/account/__init__.py +++ b/rophako/modules/account/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Endpoints for user login and out.""" diff --git a/rophako/modules/admin/__init__.py b/rophako/modules/admin/__init__.py index 46dd7bc..2a39a27 100644 --- a/rophako/modules/admin/__init__.py +++ b/rophako/modules/admin/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Endpoints for admin functions.""" diff --git a/rophako/modules/blog/__init__.py b/rophako/modules/blog/__init__.py index f6a8846..69401a6 100644 --- a/rophako/modules/blog/__init__.py +++ b/rophako/modules/blog/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Endpoints for the web blog.""" diff --git a/rophako/modules/comment/__init__.py b/rophako/modules/comment/__init__.py index fffeb2b..42bf4d8 100644 --- a/rophako/modules/comment/__init__.py +++ b/rophako/modules/comment/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals, absolute_import """Endpoints for the commenting subsystem.""" diff --git a/rophako/modules/contact/__init__.py b/rophako/modules/contact/__init__.py index df468e9..590b2b5 100644 --- a/rophako/modules/contact/__init__.py +++ b/rophako/modules/contact/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Endpoints for contacting the site owner.""" diff --git a/rophako/modules/emoticons/__init__.py b/rophako/modules/emoticons/__init__.py index 3bad49d..77e1d0e 100644 --- a/rophako/modules/emoticons/__init__.py +++ b/rophako/modules/emoticons/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Endpoints for the commenting subsystem.""" diff --git a/rophako/modules/photo/__init__.py b/rophako/modules/photo/__init__.py index b8bb2fb..a387fb0 100644 --- a/rophako/modules/photo/__init__.py +++ b/rophako/modules/photo/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Endpoints for the photo albums.""" diff --git a/rophako/modules/tracking/__init__.py b/rophako/modules/tracking/__init__.py index 621c93c..ebb4145 100644 --- a/rophako/modules/tracking/__init__.py +++ b/rophako/modules/tracking/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Endpoints for visitor tracking functions.""" diff --git a/rophako/modules/wiki/__init__.py b/rophako/modules/wiki/__init__.py index abe6ebb..322d81f 100644 --- a/rophako/modules/wiki/__init__.py +++ b/rophako/modules/wiki/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Endpoints for the wiki.""" diff --git a/rophako/plugin.py b/rophako/plugin.py index 49bdb60..f1d3a62 100644 --- a/rophako/plugin.py +++ b/rophako/plugin.py @@ -1,11 +1,10 @@ #!/usr/bin/env python -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import """Dynamic CMS plugin loader.""" import os from importlib import import_module -from rophako.app import app, BLUEPRINT_PATHS def load_plugin(name, as_blueprint=True, template_path=None): """Load a Rophako CMS plugin. @@ -17,6 +16,7 @@ def load_plugin(name, as_blueprint=True, template_path=None): * `template_path` is a filesystem path where the blueprint's templates can be found. If not provided, the path is automatically determined based on the module name, which is suitable for the built-in plugins.""" + from rophako.app import app, BLUEPRINT_PATHS module = import_module(name) if as_blueprint: mod = getattr(module, "mod") diff --git a/rophako/settings.py b/rophako/settings.py index f5cffbf..c938c38 100644 --- a/rophako/settings.py +++ b/rophako/settings.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, print_function, absolute_import import os import datetime @@ -33,7 +33,7 @@ class ConfigHandler(object): def print_settings(self): """Pretty-print the contents of the configuration.""" - print self.settings + print(self.settings) def load_plugins(self): """Load all the plugins specified by the config file.""" diff --git a/rophako/utils.py b/rophako/utils.py index e54baaa..7f7cf3a 100644 --- a/rophako/utils.py +++ b/rophako/utils.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, print_function, absolute_import from flask import (g, session, request, render_template, flash, redirect, url_for, current_app) @@ -14,7 +14,10 @@ import importlib import smtplib import markdown import json -import urlparse +try: + import urlparse +except ImportError: + from urllib import parse as urlparse import traceback from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText @@ -207,7 +210,7 @@ def send_email(to, subject, message, sender=None, reply_to=None): def handle_exception(error): """Send an e-mail to the site admin when an exception occurs.""" if current_app.config.get("DEBUG"): - print traceback.format_exc() + print(traceback.format_exc()) raise import rophako.jsondb as JsonDB diff --git a/runserver.py b/runserver.py index 8d37d05..11a1f9a 100644 --- a/runserver.py +++ b/runserver.py @@ -1,8 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import -import sys import argparse from rophako.app import app @@ -49,4 +48,3 @@ if __name__ == '__main__': flask_options["ssl_context"] = context app.run(**flask_options) - diff --git a/scripts/orphaned-photos.py b/scripts/orphaned-photos.py index 7dc171c..47620d3 100644 --- a/scripts/orphaned-photos.py +++ b/scripts/orphaned-photos.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from __future__ import unicode_literals +from __future__ import unicode_literals, print_function, absolute_import """Locate any orphaned photos. @@ -12,11 +12,14 @@ import json import glob sys.path.append(".") +from rophako.settings import Config +Config.load_settings() + import rophako.jsondb as JsonDB def main(): if len(sys.argv) == 1: - print "Usage: {} ".format(__file__) + print("Usage: {} ".format(__file__)) sys.exit(1) photo_root = sys.argv[1] @@ -32,7 +35,7 @@ def main(): for img in glob.glob("{}/*.*".format(photo_root)): fname = img.split("/")[-1] if not fname in photos: - print "Orphan:", fname + print("Orphan:", fname) if __name__ == "__main__": main()