+8
-2
@@ -431,10 +431,16 @@ class lazyT(object):
|
||||
return str(self) if self.M else local_html_escape(str(self), quote=False)
|
||||
|
||||
def encode(self, *a, **b):
|
||||
return str(self).encode(*a, **b)
|
||||
if PY2 and a[0] != 'utf8':
|
||||
return to_unicode(str(self)).encode(*a, **b)
|
||||
else:
|
||||
return str(self)
|
||||
|
||||
def decode(self, *a, **b):
|
||||
return str(self).decode(*a, **b)
|
||||
if PY2:
|
||||
return str(self).decode(*a, **b)
|
||||
else:
|
||||
return str(self)
|
||||
|
||||
def read(self):
|
||||
return str(self)
|
||||
|
||||
+1
-1
@@ -1750,7 +1750,7 @@ class WSGIWorker(Worker):
|
||||
if self.request_method != 'HEAD':
|
||||
try:
|
||||
if self.chunked:
|
||||
self.conn.sendall(b('%x\r\n%s\r\n' % (len(data), data)))
|
||||
self.conn.sendall(b'%x\r\n%s\r\n' % (len(data), to_bytes(data, 'ISO-8859-1')))
|
||||
else:
|
||||
self.conn.sendall(to_bytes(data))
|
||||
except socket.timeout:
|
||||
|
||||
@@ -12,7 +12,9 @@ import tempfile
|
||||
import unittest
|
||||
|
||||
from gluon import languages
|
||||
from gluon._compat import PY2
|
||||
from gluon._compat import PY2, to_unicode, to_bytes
|
||||
from gluon.storage import Messages
|
||||
from gluon.html import SPAN
|
||||
|
||||
MP_WORKING = 0
|
||||
try:
|
||||
@@ -108,6 +110,8 @@ class TestTranslations(unittest.TestCase):
|
||||
T.force('it')
|
||||
self.assertEqual(str(T('Hello World')),
|
||||
'Salve Mondo')
|
||||
self.assertEqual(to_unicode(T('Hello World')),
|
||||
'Salve Mondo')
|
||||
|
||||
class TestDummyApp(unittest.TestCase):
|
||||
|
||||
@@ -179,3 +183,43 @@ def index():
|
||||
for key in ['hello', 'world', '%s %%{shop}', 'ahoy']:
|
||||
self.assertTrue(key in en_dict)
|
||||
self.assertTrue(key in pt_dict)
|
||||
|
||||
class TestMessages(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
if os.path.isdir('gluon'):
|
||||
self.langpath = 'applications/welcome/languages'
|
||||
else:
|
||||
self.langpath = os.path.realpath(
|
||||
'../../applications/welcome/languages')
|
||||
self.http_accept_language = 'en'
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_decode(self):
|
||||
T = languages.translator(self.langpath, self.http_accept_language)
|
||||
messages = Messages(T)
|
||||
messages.update({'email_sent':'Email sent', 'test': "ä"})
|
||||
self.assertEqual(to_unicode(messages.email_sent, 'utf-8'), 'Email sent')
|
||||
|
||||
class TestHTMLTag(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
if os.path.isdir('gluon'):
|
||||
self.langpath = 'applications/welcome/languages'
|
||||
else:
|
||||
self.langpath = os.path.realpath(
|
||||
'../../applications/welcome/languages')
|
||||
self.http_accept_language = 'en'
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_decode(self):
|
||||
T = languages.translator(self.langpath, self.http_accept_language)
|
||||
elem = SPAN(T("Complete"))
|
||||
self.assertEqual(elem.flatten(), "Complete")
|
||||
elem = SPAN(T("Cannot be empty", language="ru"))
|
||||
self.assertEqual(elem.xml(), to_bytes('<span>Пустое значение недопустимо</span>'))
|
||||
self.assertEqual(elem.flatten(), 'Пустое значение недопустимо')
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ Utilities and class for UTF8 strings managing
|
||||
----------------------------------------------
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from gluon._compat import builtin as __builtin__, unicodeT, iteritems, to_unicode, to_native
|
||||
from gluon._compat import builtin as __builtin__, unicodeT, iteritems, to_unicode, to_native, reload
|
||||
|
||||
__all__ = ['Utf8']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user