diff --git a/applications/admin/static/js/web2py.js b/applications/admin/static/js/web2py.js index 7131727d..22b9f253 100644 --- a/applications/admin/static/js/web2py.js +++ b/applications/admin/static/js/web2py.js @@ -617,7 +617,7 @@ flash: function (message, status) { var flash = $('.w2p_flash'); web2py.hide_flash(); - flash.html(message).addClass(status); + flash.text(message).addClass(status); if (flash.html()) flash.append(' × ')[animateIn](); }, hide_flash: function () { diff --git a/applications/examples/static/js/web2py.js b/applications/examples/static/js/web2py.js index 7131727d..22b9f253 100644 --- a/applications/examples/static/js/web2py.js +++ b/applications/examples/static/js/web2py.js @@ -617,7 +617,7 @@ flash: function (message, status) { var flash = $('.w2p_flash'); web2py.hide_flash(); - flash.html(message).addClass(status); + flash.text(message).addClass(status); if (flash.html()) flash.append(' × ')[animateIn](); }, hide_flash: function () { diff --git a/applications/welcome/controllers/appadmin.py b/applications/welcome/controllers/appadmin.py index 74240e59..0188ade9 100644 --- a/applications/welcome/controllers/appadmin.py +++ b/applications/welcome/controllers/appadmin.py @@ -392,12 +392,11 @@ def ccache(): cache.disk.clear() session.flash += T("Disk Cleared") redirect(URL(r=request)) - + try: - from guppy import hpy - hp = hpy() + from pympler.asizeof import asizeof except ImportError: - hp = False + asizeof = False import shelve import os @@ -451,9 +450,9 @@ def ccache(): ram['ratio'] = 0 for key, value in iteritems(cache.ram.storage): - if hp: - ram['bytes'] += hp.iso(value[1]).size - ram['objects'] += hp.iso(value[1]).count + if asizeof: + ram['bytes'] += asizeof(value[1]) + ram['objects'] += 1 ram['entries'] += 1 if value[0] < ram['oldest']: ram['oldest'] = value[0] @@ -469,9 +468,9 @@ def ccache(): except (KeyError, ZeroDivisionError): disk['ratio'] = 0 else: - if hp: - disk['bytes'] += hp.iso(value[1]).size - disk['objects'] += hp.iso(value[1]).count + if asizeof: + disk['bytes'] += asizeof(value[1]) + disk['objects'] += 1 disk['entries'] += 1 if value[0] < disk['oldest']: disk['oldest'] = value[0] @@ -511,7 +510,7 @@ def ccache(): total['keys'] = key_table(total['keys']) return dict(form=form, total=total, - ram=ram, disk=disk, object_stats=hp != False) + ram=ram, disk=disk, object_stats=asizeof != False) def table_template(table): diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index 7131727d..22b9f253 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -617,7 +617,7 @@ flash: function (message, status) { var flash = $('.w2p_flash'); web2py.hide_flash(); - flash.html(message).addClass(status); + flash.text(message).addClass(status); if (flash.html()) flash.append(' × ')[animateIn](); }, hide_flash: function () { diff --git a/applications/welcome/views/appadmin.html b/applications/welcome/views/appadmin.html index 59b85563..8a9d3400 100644 --- a/applications/welcome/views/appadmin.html +++ b/applications/welcome/views/appadmin.html @@ -148,7 +148,7 @@ {{=T.M("(**%.0d MB**)", total['bytes'] / 1048576)}} {{pass}} {{else:}} - {{=T.M("**not available** (requires the Python [[guppy http://pypi.python.org/pypi/guppy/ popup]] library)")}} + {{=T.M("**not available** (requires the Python [[Pympler https://pypi.python.org/pypi/Pympler popup]] library)")}} {{pass}}
@@ -176,7 +176,7 @@ {{=T.M("(**%.0d MB**)", ram['bytes'] / 10485576)}} {{pass}} {{else:}} - {{=T.M("``**not available**``:red (requires the Python [[guppy http://pypi.python.org/pypi/guppy/ popup]] library)")}} + {{=T.M("``**not available**``:red (requires the Python [[Pympler https://pypi.python.org/pypi/Pympler popup]] library)")}} {{pass}}
@@ -205,7 +205,7 @@ {{=T.M("(**%.0d MB**)", disk['bytes'] / 1048576)}} {{pass}} {{else:}} - {{=T.M("``**not available**``:red (requires the Python [[guppy http://pypi.python.org/pypi/guppy/ popup]] library)")}} + {{=T.M("``**not available**``:red (requires the Python [[Pympler https://pypi.python.org/pypi/Pympler popup]] library)")}} {{pass}}
diff --git a/applications/welcome/views/layout.html b/applications/welcome/views/layout.html index 9f664c45..54dcf8d2 100644 --- a/applications/welcome/views/layout.html +++ b/applications/welcome/views/layout.html @@ -75,7 +75,7 @@ {{else:}} {{=T('Login')}} {{=T('Sign up')}} - {{=T('Lost Password')}} + {{=T('Lost Password')}} {{pass}} diff --git a/gluon/languages.py b/gluon/languages.py index 0d8bd4a2..293ecac9 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -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) diff --git a/gluon/rocket.py b/gluon/rocket.py index e3faf0bd..d76da94e 100644 --- a/gluon/rocket.py +++ b/gluon/rocket.py @@ -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: diff --git a/gluon/tests/test_languages.py b/gluon/tests/test_languages.py index cb2fb6bc..c996bd6a 100644 --- a/gluon/tests/test_languages.py +++ b/gluon/tests/test_languages.py @@ -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('Пустое значение недопустимо')) + self.assertEqual(elem.flatten(), 'Пустое значение недопустимо') diff --git a/gluon/utf8.py b/gluon/utf8.py index 21fd12c4..34bfa87f 100644 --- a/gluon/utf8.py +++ b/gluon/utf8.py @@ -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']