From 113df51ef92e089f2cf3c20e86de51009c819648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Fri, 14 Jul 2017 18:52:36 +0100 Subject: [PATCH 1/7] Fixes #1685 --- gluon/validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluon/validators.py b/gluon/validators.py index 084661a1..1d9dddcf 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -2767,7 +2767,7 @@ class LazyCrypt(object): else: digest_alg, key = self.crypt.digest_alg, '' if self.crypt.salt: - if self.crypt.salt: + if self.crypt.salt is True: salt = str(web2py_uuid()).replace('-', '')[-16:] else: salt = self.crypt.salt From b7b8a009f2c1c059358fcf6777e1bb96d0bd6523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Fri, 14 Jul 2017 20:17:30 +0100 Subject: [PATCH 2/7] Fixes #1680 --- gluon/authapi.py | 2 +- gluon/contrib/imageutils.py | 2 +- gluon/sqlhtml.py | 4 ++-- gluon/tools.py | 12 ++++++------ gluon/utils.py | 12 ++++++------ 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/gluon/authapi.py b/gluon/authapi.py index 4bc7727f..3347cb68 100644 --- a/gluon/authapi.py +++ b/gluon/authapi.py @@ -115,7 +115,7 @@ class AuthAPI(object): if auth.last_visit and auth.last_visit + delta > now: self.user = auth.user # this is a trick to speed up sessions to avoid many writes - if (now - auth.last_visit).seconds > (auth.expiration / 10): + if (now - auth.last_visit).seconds > (auth.expiration // 10): auth.last_visit = now else: self.user = None diff --git a/gluon/contrib/imageutils.py b/gluon/contrib/imageutils.py index 28cf10e0..a5c24b69 100644 --- a/gluon/contrib/imageutils.py +++ b/gluon/contrib/imageutils.py @@ -45,7 +45,7 @@ class RESIZE(object): background = Image.new('RGBA', (self.nx, self.ny), (255, 255, 255, 0)) background.paste( img, - ((self.nx - img.size[0]) / 2, (self.ny - img.size[1]) / 2)) + ((self.nx - img.size[0]) // 2, (self.ny - img.size[1]) // 2)) background.save(s, 'JPEG', quality=self.quality) else: img.save(s, 'JPEG', quality=self.quality) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 59ebbeea..8b1d5c52 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -405,7 +405,7 @@ class RadioWidget(OptionsWidget): cols = attributes.get('cols', 1) totals = len(options) mods = totals % cols - rows = totals / cols + rows = totals // cols if mods: rows += 1 @@ -471,7 +471,7 @@ class CheckboxesWidget(OptionsWidget): cols = attributes.get('cols', 1) totals = len(options) mods = totals % cols - rows = totals / cols + rows = totals // cols if mods: rows += 1 diff --git a/gluon/tools.py b/gluon/tools.py index 0ff96de6..1f54e746 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -1762,7 +1762,7 @@ class Auth(AuthAPI): if auth.last_visit and auth.last_visit + delta > now: self.user = auth.user # this is a trick to speed up sessions to avoid many writes - if (now - auth.last_visit).seconds > (auth.expiration / 10): + if (now - auth.last_visit).seconds > (auth.expiration // 10): auth.last_visit = now else: self.user = None @@ -5531,15 +5531,15 @@ def prettydate(d, T=lambda x: x, utc=False): else: suffix = ' ago' if dt.days >= 2 * 365: - return T('%d years' + suffix) % int(dt.days / 365) + return T('%d years' + suffix) % int(dt.days // 365) elif dt.days >= 365: return T('1 year' + suffix) elif dt.days >= 60: - return T('%d months' + suffix) % int(dt.days / 30) + return T('%d months' + suffix) % int(dt.days // 30) elif dt.days >= 27: # 4 weeks ugly return T('1 month' + suffix) elif dt.days >= 14: - return T('%d weeks' + suffix) % int(dt.days / 7) + return T('%d weeks' + suffix) % int(dt.days // 7) elif dt.days >= 7: return T('1 week' + suffix) elif dt.days > 1: @@ -5547,11 +5547,11 @@ def prettydate(d, T=lambda x: x, utc=False): elif dt.days == 1: return T('1 day' + suffix) elif dt.seconds >= 2 * 60 * 60: - return T('%d hours' + suffix) % int(dt.seconds / 3600) + return T('%d hours' + suffix) % int(dt.seconds // 3600) elif dt.seconds >= 60 * 60: return T('1 hour' + suffix) elif dt.seconds >= 2 * 60: - return T('%d minutes' + suffix) % int(dt.seconds / 60) + return T('%d minutes' + suffix) % int(dt.seconds // 60) elif dt.seconds >= 60: return T('1 minute' + suffix) elif dt.seconds > 1: diff --git a/gluon/utils.py b/gluon/utils.py index 85d7d49f..3b26a51b 100644 --- a/gluon/utils.py +++ b/gluon/utils.py @@ -156,12 +156,12 @@ def get_digest(value): raise ValueError("Invalid digest algorithm: %s" % value) DIGEST_ALG_BY_SIZE = { - 128 / 4: 'md5', - 160 / 4: 'sha1', - 224 / 4: 'sha224', - 256 / 4: 'sha256', - 384 / 4: 'sha384', - 512 / 4: 'sha512', + 128 // 4: 'md5', + 160 // 4: 'sha1', + 224 // 4: 'sha224', + 256 // 4: 'sha256', + 384 // 4: 'sha384', + 512 // 4: 'sha512', } From 7a5f611e7694016889e33a02518de7eb8c5c99f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Fri, 14 Jul 2017 20:23:13 +0100 Subject: [PATCH 3/7] Fixes #1571 --- gluon/sqlhtml.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 8b1d5c52..dfdc1d10 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -684,9 +684,10 @@ class AutocompleteWidget(object): urlvars = request.vars urlvars[default_var] = 1 self.url = URL(args=request.args, vars=urlvars) - self.callback() + self.run_callback = True else: self.url = request + self.run_callback = False def callback(self): if self.keyword in self.request.vars: @@ -759,6 +760,8 @@ class AutocompleteWidget(object): raise HTTP(200, '') def __call__(self, field, value, **attributes): + if self.run_callback: + self.callback() default = dict( _type='text', value=(value is not None and str(value)) or '', From 780510dc326f811209d0f80ca8e16f025af170f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Sat, 15 Jul 2017 09:52:58 +0100 Subject: [PATCH 4/7] Fixes #1684 --- gluon/fileutils.py | 4 ++-- gluon/tests/test_fileutils.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gluon/fileutils.py b/gluon/fileutils.py index 27fe8a8d..0fa29acf 100644 --- a/gluon/fileutils.py +++ b/gluon/fileutils.py @@ -415,10 +415,10 @@ def fix_newlines(path): |\r| )''') for filename in listdir(path, '.*\.(py|html)$', drop=False): - rdata = read_file(filename, 'rb') + rdata = read_file(filename, 'r') wdata = regex.sub('\n', rdata) if wdata != rdata: - write_file(filename, wdata, 'wb') + write_file(filename, wdata, 'w') def copystream( diff --git a/gluon/tests/test_fileutils.py b/gluon/tests/test_fileutils.py index 5e408796..a09f5704 100644 --- a/gluon/tests/test_fileutils.py +++ b/gluon/tests/test_fileutils.py @@ -1,10 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import os import unittest import datetime -from gluon.fileutils import parse_version +from gluon.fileutils import parse_version, fix_newlines, listdir class TestFileUtils(unittest.TestCase): @@ -22,3 +23,6 @@ class TestFileUtils(unittest.TestCase): # Semantic Beta rtn = parse_version('Version 2.14.1-beta+timestamp.2016.03.21.22.35.26') self.assertEqual(rtn, (2, 14, 1, 'beta', datetime.datetime(2016, 3, 21, 22, 35, 26))) + + def test_fix_newlines(self): + fix_newlines(os.path.dirname(os.path.abspath(__file__))) From d144ff7d656bc6d3e181b6719a34373db100e995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Sun, 16 Jul 2017 14:06:03 +0100 Subject: [PATCH 5/7] Fixes #1687 --- gluon/http.py | 5 ++++- gluon/tests/test_fileutils.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gluon/http.py b/gluon/http.py index ac630cc6..c56e2dc3 100644 --- a/gluon/http.py +++ b/gluon/http.py @@ -11,7 +11,7 @@ HTTP statuses helpers """ import re -from gluon._compat import iteritems +from gluon._compat import iteritems, unicodeT __all__ = ['HTTP', 'redirect'] @@ -119,9 +119,12 @@ class HTTP(Exception): elif v is not None: rheaders.append((k, str(v))) responder(status, rheaders) + print(type(body)) if env.get('request_method', '') == 'HEAD': return [''] elif isinstance(body, (str, bytes, bytearray)): + if isinstance(body, unicodeT): + body = body.encode('utf-8') return [body] elif hasattr(body, '__iter__'): return body diff --git a/gluon/tests/test_fileutils.py b/gluon/tests/test_fileutils.py index a09f5704..a4a25ee0 100644 --- a/gluon/tests/test_fileutils.py +++ b/gluon/tests/test_fileutils.py @@ -5,7 +5,7 @@ import os import unittest import datetime -from gluon.fileutils import parse_version, fix_newlines, listdir +from gluon.fileutils import parse_version, fix_newlines class TestFileUtils(unittest.TestCase): From 05d2ced779ce9da9121c81a5b85455c6f768c927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Sun, 16 Jul 2017 14:27:11 +0100 Subject: [PATCH 6/7] remove print that was left from debugging --- gluon/http.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gluon/http.py b/gluon/http.py index c56e2dc3..539a00fd 100644 --- a/gluon/http.py +++ b/gluon/http.py @@ -119,7 +119,6 @@ class HTTP(Exception): elif v is not None: rheaders.append((k, str(v))) responder(status, rheaders) - print(type(body)) if env.get('request_method', '') == 'HEAD': return [''] elif isinstance(body, (str, bytes, bytearray)): From ce0b2557470ecb7c92719645293cb00785fe48bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Sun, 16 Jul 2017 17:59:52 +0100 Subject: [PATCH 7/7] Fixes #1672 --- gluon/sqlhtml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index dfdc1d10..0468c0f7 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -1919,7 +1919,7 @@ class SQLFORM(FORM): if 'table_name' in attributes: del attributes['table_name'] - return SQLFORM(DAL(None).define_table(table_name, *fields), + return SQLFORM(DAL(None).define_table(table_name, *[field.clone() for field in fields]), **attributes) @staticmethod