Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Commit

Permalink
Add Python3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
DasIch committed Jul 28, 2013
1 parent 8a39819 commit 157fe4d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
6 changes: 4 additions & 2 deletions flask_babel.py → flask_babel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Implements i18n/l10n support for Flask applications based on Babel.
:copyright: (c) 2010 by Armin Ronacher.
:copyright: (c) 2013 by Armin Ronacher, Daniel Neuhäuser.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
Expand All @@ -28,6 +28,8 @@
timezone = pytz.timezone
UTC = pytz.UTC

from flask.ext.babel._compat import string_types


class Babel(object):
"""Central controller class that can be used to configure how
Expand Down Expand Up @@ -235,7 +237,7 @@ def get_timezone():
if rv is None:
tzinfo = babel.default_timezone
else:
if isinstance(rv, basestring):
if isinstance(rv, string_types):
tzinfo = timezone(rv)
else:
tzinfo = rv
Expand Down
20 changes: 20 additions & 0 deletions flask_babel/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
"""
flask.ext.babel._compat
~~~~~~~~~~~~~~~~~~~~~~~
:copyright: (c) 2013 by Armin Ronacher, Daniel Neuhäuser.
:license: BSD, see LICENSE for more details.
"""
import sys


PY2 = sys.version_info[0] == 2


if PY2:
text_type = unicode
string_types = (str, unicode)
else:
text_type = str
string_types = (str, )
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
author_email='armin.ronacher@active-4.com',
description='Adds i18n/l10n support to Flask applications',
long_description=__doc__,
py_modules=['flask_babel'],
packages=['flask_babel'],
zip_safe=False,
platforms='any',
install_requires=[
Expand All @@ -44,6 +44,7 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
]
Expand Down
5 changes: 3 additions & 2 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from datetime import datetime
import flask_babel as babel
from flask_babel import gettext, ngettext, lazy_gettext
from flask_babel._compat import text_type


class DateFormattingTestCase(unittest.TestCase):
Expand Down Expand Up @@ -156,10 +157,10 @@ def test_lazy_gettext(self):
b = babel.Babel(app, default_locale='de_DE')
yes = lazy_gettext(u'Yes')
with app.test_request_context():
assert unicode(yes) == 'Ja'
assert text_type(yes) == 'Ja'
app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
with app.test_request_context():
assert unicode(yes) == 'Yes'
assert text_type(yes) == 'Yes'

def test_list_translations(self):
app = flask.Flask(__name__)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27
envlist = py26, py27, py33

[testenv]
deps = pytz>=2013a
Expand Down

0 comments on commit 157fe4d

Please sign in to comment.