Esempio n. 1
0
 def test_lazy_gettext(self):
     app = flask.Flask(__name__)
     b = babel.Babel(app, default_locale='de_DE')
     yes = lazy_gettext(u'Yes')
     with app.test_request_context():
         assert text_type(yes) == 'Ja'
     app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
     with app.test_request_context():
         assert text_type(yes) == 'Yes'
Esempio n. 2
0
 def test_lazy_ngettext(self):
     app = flask.Flask(__name__)
     babel.Babel(app, default_locale='de_DE')
     one_apple = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 1)
     with app.test_request_context():
         assert text_type(one_apple) == '1 Apfel'
         assert one_apple.__html__() == '1 Apfel'
     two_apples = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 2)
     with app.test_request_context():
         assert text_type(two_apples) == u'2 Äpfel'
         assert two_apples.__html__() == u'2 Äpfel'
Esempio n. 3
0
 def test_lazy_ngettext(self):
     app = flask.Flask(__name__)
     babel.Babel(app, default_locale='de_DE')
     one_apple = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 1)
     with app.test_request_context():
         assert text_type(one_apple) == '1 Apfel'
         assert one_apple.__html__() == '1 Apfel'
     two_apples = lazy_ngettext(u'%(num)s Apple', u'%(num)s Apples', 2)
     with app.test_request_context():
         assert text_type(two_apples) == u'2 Äpfel'
         assert two_apples.__html__() == u'2 Äpfel'
Esempio n. 4
0
 def __repr__(self):
     value = self._func(*self._args, **self._kwargs)
     if PY2 and isinstance(value, unicode):
         # With Python2 we need to encode unicode strings because those
         # can contain non-ASCII characters.
         return "l'{0}'".format(value.encode('utf-8'))
     return "l'{0}'".format(text_type(value))
Esempio n. 5
0
 def __getattr__(self, attr):
     if attr == "__setstate__":
         raise AttributeError(attr)
     string = text_type(self)
     if hasattr(string, attr):
         return getattr(string, attr)
     raise AttributeError(attr)
Esempio n. 6
0
 def __getattr__(self, attr):
     if attr == "__setstate__":
         raise AttributeError(attr)
     string = text_type(self)
     if hasattr(string, attr):
         return getattr(string, attr)
     raise AttributeError(attr)
Esempio n. 7
0
    def test_lazy_gettext(self):
        app = flask.Flask(__name__)
        babel.Babel(app, default_locale='de_DE')
        yes = lazy_gettext(u'Yes')
        with app.test_request_context():
            assert text_type(yes) == 'Ja'
            assert yes.__html__() == 'Ja'
        app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
        with app.test_request_context():
            assert text_type(yes) == 'Yes'
            assert yes.__html__() == 'Yes'

        hello = lazy_gettext(u'Hello %(name)s!')
        app.config['BABEL_DEFAULT_LOCALE'] = 'de_DE'
        with app.test_request_context():
            assert hello % {'name': 'Peter'} == 'Hallo Peter!'
        app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
        with app.test_request_context():
            assert hello % {'name': 'Peter'} == 'Hello Peter!'
Esempio n. 8
0
 def __le__(self, other):
     return text_type(self) <= other
Esempio n. 9
0
 def __add__(self, other):
     return text_type(self) + other
Esempio n. 10
0
 def __rmul__(self, other):
     return other * text_type(self)
Esempio n. 11
0
 def __len__(self):
     return len(text_type(self))
Esempio n. 12
0
 def __iter__(self):
     return iter(text_type(self))
Esempio n. 13
0
 def __hash__(self):
     return hash(text_type(self))
Esempio n. 14
0
 def __str__(self):
     return text_type(self._func(*self._args, **self._kwargs))
Esempio n. 15
0
 def __radd__(self, other):
     return other + text_type(self)
Esempio n. 16
0
 def __mod__(self, other):
     return text_type(self) % other
Esempio n. 17
0
 def __contains__(self, item):
     return item in text_type(self)
Esempio n. 18
0
 def __add__(self, other):
     return text_type(self) + other
Esempio n. 19
0
 def __iter__(self):
     return iter(text_type(self))
Esempio n. 20
0
 def __getitem__(self, key):
     return text_type(self)[key]
Esempio n. 21
0
 def __len__(self):
     return len(text_type(self))
Esempio n. 22
0
 def __ne__(self, other):
     return text_type(self) != other
Esempio n. 23
0
 def __mul__(self, other):
     return text_type(self) * other
Esempio n. 24
0
 def __ge__(self, other):
     return text_type(self) >= other
Esempio n. 25
0
 def __rmul__(self, other):
     return other * text_type(self)
Esempio n. 26
0
 def __rmod__(self, other):
     return other + text_type(self)
Esempio n. 27
0
 def __lt__(self, other):
     return text_type(self) < other
Esempio n. 28
0
 def __str__(self):
     return text_type(self._func(*self._args, **self._kwargs))
Esempio n. 29
0
 def __le__(self, other):
     return text_type(self) <= other
Esempio n. 30
0
 def __getitem__(self, key):
     return text_type(self)[key]
Esempio n. 31
0
 def __eq__(self, other):
     return text_type(self) == other
Esempio n. 32
0
 def __contains__(self, item):
     return item in text_type(self)
Esempio n. 33
0
 def __ne__(self, other):
     return text_type(self) != other
Esempio n. 34
0
 def __mul__(self, other):
     return text_type(self) * other
Esempio n. 35
0
 def __gt__(self, other):
     return text_type(self) > other
Esempio n. 36
0
 def __lt__(self, other):
     return text_type(self) < other
Esempio n. 37
0
 def __getattr__(self, attr):
     string = text_type(self)
     if hasattr(string, attr):
         return getattr(string, attr)
     raise AttributeError(attr)
Esempio n. 38
0
 def __eq__(self, other):
     return text_type(self) == other
Esempio n. 39
0
 def __html__(self):
     return text_type(self)
Esempio n. 40
0
 def __gt__(self, other):
     return text_type(self) > other
Esempio n. 41
0
 def __hash__(self):
     return hash(text_type(self))
Esempio n. 42
0
 def __html__(self):
     return text_type(self)
Esempio n. 43
0
 def __repr__(self):
     return "l'{0}'".format(text_type(self))
Esempio n. 44
0
 def __mod__(self, other):
     return text_type(self) % other
Esempio n. 45
0
 def __repr__(self):
     return "l'{0}'".format(text_type(self))
Esempio n. 46
0
 def __ge__(self, other):
     return text_type(self) >= other
Esempio n. 47
0
 def __getattr__(self, attr):
     string = text_type(self)
     if hasattr(string, attr):
         return getattr(string, attr)
     raise AttributeError(attr)