Skip to content

Commit 041de90

Browse files
committed
Remove _compat and dependents.
1 parent 281c63f commit 041de90

File tree

4 files changed

+32
-58
lines changed

4 files changed

+32
-58
lines changed

flask_babel/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from pytz import timezone, UTC
2020
from werkzeug.datastructures import ImmutableDict
2121

22-
from flask_babel._compat import string_types
2322
from flask_babel.speaklater import LazyString
2423

2524

@@ -249,10 +248,7 @@ def get_timezone():
249248
if rv is None:
250249
tzinfo = babel.default_timezone
251250
else:
252-
if isinstance(rv, string_types):
253-
tzinfo = timezone(rv)
254-
else:
255-
tzinfo = rv
251+
tzinfo = timezone(rv) if isinstance(rv, str) else rv
256252
ctx.babel_tzinfo = tzinfo
257253
return tzinfo
258254

@@ -519,7 +515,7 @@ class Domain(object):
519515
"""
520516

521517
def __init__(self, translation_directories=None, domain='messages'):
522-
if isinstance(translation_directories, string_types):
518+
if isinstance(translation_directories, str):
523519
translation_directories = [translation_directories]
524520
self._translation_directories = translation_directories
525521
self.domain = domain

flask_babel/_compat.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

flask_babel/speaklater.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from flask_babel._compat import text_type
3-
4-
51
class LazyString(object):
62
def __init__(self, func, *args, **kwargs):
73
self._func = func
@@ -11,67 +7,69 @@ def __init__(self, func, *args, **kwargs):
117
def __getattr__(self, attr):
128
if attr == "__setstate__":
139
raise AttributeError(attr)
14-
string = text_type(self)
10+
11+
string = str(self)
1512
if hasattr(string, attr):
1613
return getattr(string, attr)
14+
1715
raise AttributeError(attr)
1816

1917
def __repr__(self):
20-
return "l'{0}'".format(text_type(self))
18+
return "l'{0}'".format(str(self))
2119

2220
def __str__(self):
23-
return text_type(self._func(*self._args, **self._kwargs))
21+
return str(self._func(*self._args, **self._kwargs))
2422

2523
def __len__(self):
26-
return len(text_type(self))
24+
return len(str(self))
2725

2826
def __getitem__(self, key):
29-
return text_type(self)[key]
27+
return str(self)[key]
3028

3129
def __iter__(self):
32-
return iter(text_type(self))
30+
return iter(str(self))
3331

3432
def __contains__(self, item):
35-
return item in text_type(self)
33+
return item in str(self)
3634

3735
def __add__(self, other):
38-
return text_type(self) + other
36+
return str(self) + other
3937

4038
def __radd__(self, other):
41-
return other + text_type(self)
39+
return other + str(self)
4240

4341
def __mul__(self, other):
44-
return text_type(self) * other
42+
return str(self) * other
4543

4644
def __rmul__(self, other):
47-
return other * text_type(self)
45+
return other * str(self)
4846

4947
def __lt__(self, other):
50-
return text_type(self) < other
48+
return str(self) < other
5149

5250
def __le__(self, other):
53-
return text_type(self) <= other
51+
return str(self) <= other
5452

5553
def __eq__(self, other):
56-
return text_type(self) == other
54+
return str(self) == other
5755

5856
def __ne__(self, other):
59-
return text_type(self) != other
57+
return str(self) != other
6058

6159
def __gt__(self, other):
62-
return text_type(self) > other
60+
return str(self) > other
6361

6462
def __ge__(self, other):
65-
return text_type(self) >= other
63+
return str(self) >= other
6664

6765
def __html__(self):
68-
return text_type(self)
66+
return str(self)
6967

7068
def __hash__(self):
71-
return hash(text_type(self))
69+
return hash(str(self))
7270

7371
def __mod__(self, other):
74-
return text_type(self) % other
72+
return str(self) % other
7573

7674
def __rmod__(self, other):
77-
return other + text_type(self)
75+
return other + str(self)

tests/test_gettext.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import flask_babel as babel
77
from flask_babel import gettext, lazy_gettext, lazy_ngettext, ngettext
8-
from flask_babel._compat import text_type
98

109

1110
def test_basics():
@@ -47,11 +46,12 @@ def test_lazy_gettext():
4746
babel.Babel(app, default_locale='de_DE')
4847
yes = lazy_gettext(u'Yes')
4948
with app.test_request_context():
50-
assert text_type(yes) == 'Ja'
49+
assert str(yes) == 'Ja'
5150
assert yes.__html__() == 'Ja'
51+
5252
app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
5353
with app.test_request_context():
54-
assert text_type(yes) == 'Yes'
54+
assert str(yes) == 'Yes'
5555
assert yes.__html__() == 'Yes'
5656

5757

@@ -60,11 +60,11 @@ def test_lazy_ngettext():
6060
babel.Babel(app, default_locale='de_DE')
6161
one_apple = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 1)
6262
with app.test_request_context():
63-
assert text_type(one_apple) == '1 Apfel'
63+
assert str(one_apple) == '1 Apfel'
6464
assert one_apple.__html__() == '1 Apfel'
6565
two_apples = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 2)
6666
with app.test_request_context():
67-
assert text_type(two_apples) == u'2 Äpfel'
67+
assert str(two_apples) == u'2 Äpfel'
6868
assert two_apples.__html__() == u'2 Äpfel'
6969

7070

@@ -73,10 +73,10 @@ def test_lazy_gettext_defaultdomain():
7373
b = babel.Babel(app, default_locale='de_DE', default_domain='test')
7474
first = lazy_gettext('first')
7575
with app.test_request_context():
76-
assert text_type(first) == 'erste'
76+
assert str(first) == 'erste'
7777
app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
7878
with app.test_request_context():
79-
assert text_type(first) == 'first'
79+
assert str(first) == 'first'
8080

8181

8282
def test_list_translations():

0 commit comments

Comments
 (0)