Cleanup mediagoblin._compat and fix translation tests.
This commit is contained in:
parent
173099ad2b
commit
cf3b5926f4
@ -1,23 +1,15 @@
|
||||
from six import PY3, iteritems
|
||||
|
||||
from mediagoblin import mg_globals
|
||||
from six import PY3
|
||||
|
||||
if PY3:
|
||||
from email.mime.text import MIMEText
|
||||
from urllib import parse as urlparse
|
||||
# TODO(berker): Rename to gettext and ungettext instead?
|
||||
ugettext = mg_globals.thread_scope.translations.gettext
|
||||
ungettext = mg_globals.thread_scope.translations.ngettext
|
||||
else:
|
||||
from email.MIMEText import MIMEText
|
||||
import urlparse
|
||||
ugettext = mg_globals.thread_scope.translations.ugettext
|
||||
ungettext = mg_globals.thread_scope.translations.ungettext
|
||||
|
||||
|
||||
# taken from
|
||||
# https://github.com/django/django/blob/master/django/utils/encoding.py
|
||||
def py2_unicode(klass):
|
||||
# TODO: Add support for __repr__
|
||||
if not PY3:
|
||||
if '__str__' not in klass.__dict__:
|
||||
raise ValueError("@py2_unicode cannot be applied "
|
||||
|
@ -18,9 +18,10 @@
|
||||
from sqlalchemy import create_engine, event
|
||||
import logging
|
||||
|
||||
import six
|
||||
|
||||
from mediagoblin.db.base import Base, Session
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin._compat import iteritems
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
@ -29,7 +30,7 @@ class DatabaseMaster(object):
|
||||
def __init__(self, engine):
|
||||
self.engine = engine
|
||||
|
||||
for k, v in iteritems(Base._decl_class_registry):
|
||||
for k, v in six.iteritems(Base._decl_class_registry):
|
||||
setattr(self, k, v)
|
||||
|
||||
def commit(self):
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from urllib import urlencode
|
||||
from six.moves.urllib.parse import urlencode
|
||||
|
||||
import six
|
||||
|
||||
|
@ -14,16 +14,16 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from six.moves.urllib.parse import urlparse
|
||||
|
||||
from mediagoblin.storage import (
|
||||
StorageInterface,
|
||||
clean_listy_filepath,
|
||||
NoWebServing)
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from mediagoblin._compat import urlparse
|
||||
|
||||
|
||||
class BasicFileStorage(StorageInterface):
|
||||
"""
|
||||
|
@ -14,6 +14,7 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import six
|
||||
|
||||
import jinja2
|
||||
from jinja2.ext import Extension
|
||||
@ -33,8 +34,6 @@ from mediagoblin.tools.pluginapi import get_hook_templates, hook_transform
|
||||
from mediagoblin.tools.timesince import timesince
|
||||
from mediagoblin.meddleware.csrf import render_csrf_form_token
|
||||
|
||||
from mediagoblin._compat import ugettext, ungettext
|
||||
|
||||
SETUP_JINJA_ENVS = {}
|
||||
|
||||
|
||||
@ -67,7 +66,12 @@ def get_jinja_env(template_loader, locale):
|
||||
'jinja2.ext.i18n', 'jinja2.ext.autoescape',
|
||||
TemplateHookExtension] + local_exts)
|
||||
|
||||
template_env.install_gettext_callables(ugettext, ungettext)
|
||||
if six.PY2:
|
||||
template_env.install_gettext_callables(mg_globals.thread_scope.translations.ugettext,
|
||||
mg_globals.thread_scope.translations.ungettext)
|
||||
else:
|
||||
template_env.install_gettext_callables(mg_globals.thread_scope.translations.gettext,
|
||||
mg_globals.thread_scope.translations.ngettext)
|
||||
|
||||
# All templates will know how to ...
|
||||
# ... fetch all waiting messages and remove them from the queue
|
||||
|
@ -17,12 +17,12 @@
|
||||
import gettext
|
||||
import pkg_resources
|
||||
|
||||
import six
|
||||
|
||||
from babel import localedata
|
||||
from babel.support import LazyProxy
|
||||
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin._compat import ugettext, ungettext
|
||||
|
||||
###################
|
||||
# Translation tools
|
||||
@ -147,7 +147,9 @@ def pass_to_ugettext(*args, **kwargs):
|
||||
The reason we can't have a global ugettext method is because
|
||||
mg_globals gets swapped out by the application per-request.
|
||||
"""
|
||||
return ugettext(*args, **kwargs)
|
||||
if six.PY2:
|
||||
return mg_globals.thread_scope.translations.ugettext(*args, **kwargs)
|
||||
return mg_globals.thread_scope.translations.gettext(*args, **kwargs)
|
||||
|
||||
def pass_to_ungettext(*args, **kwargs):
|
||||
"""
|
||||
@ -156,7 +158,9 @@ def pass_to_ungettext(*args, **kwargs):
|
||||
The reason we can't have a global ugettext method is because
|
||||
mg_globals gets swapped out by the application per-request.
|
||||
"""
|
||||
return ungettext(*args, **kwargs)
|
||||
if six.PY2:
|
||||
return mg_globals.thread_scope.translations.ungettext(*args, **kwargs)
|
||||
return mg_globals.thread_scope.translations.ngettext(*args, **kwargs)
|
||||
|
||||
|
||||
def lazy_pass_to_ugettext(*args, **kwargs):
|
||||
|
Loading…
x
Reference in New Issue
Block a user