From 1bfc9d7a1e61042d36a494773556d703f4772ef9 Mon Sep 17 00:00:00 2001 From: Aron Jones Date: Thu, 26 Jan 2017 10:49:26 -0500 Subject: [PATCH 01/13] Add Python 3.5 to travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 2c31166..bd384f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python python: - "2.7" + - "3.5" env: - DJANGO_VERSION=1.4 - DJANGO_VERSION=1.5 From d4bcb97040d136ab6ad4cb91b9b194a206b2f841 Mon Sep 17 00:00:00 2001 From: Aron Jones Date: Thu, 26 Jan 2017 10:54:53 -0500 Subject: [PATCH 02/13] Remove some older Django versions from tests --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index bd384f2..0a1fa06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,6 @@ python: - "2.7" - "3.5" env: - - DJANGO_VERSION=1.4 - - DJANGO_VERSION=1.5 - - DJANGO_VERSION=1.6 - DJANGO_VERSION=1.7 - DJANGO_VERSION=1.8 - DJANGO_VERSION=1.9 From f4c0824f04b75786bec286a83d2a57faae526bc8 Mon Sep 17 00:00:00 2001 From: Aron Jones Date: Thu, 26 Jan 2017 10:57:44 -0500 Subject: [PATCH 03/13] Also remove 1.7 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0a1fa06..6498615 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ python: - "2.7" - "3.5" env: - - DJANGO_VERSION=1.7 - DJANGO_VERSION=1.8 - DJANGO_VERSION=1.9 - DJANGO_VERSION=1.10 From ee2381dd14cdb6668c4d935d69f63028c1cc872e Mon Sep 17 00:00:00 2001 From: Aron Jones Date: Thu, 26 Jan 2017 11:00:17 -0500 Subject: [PATCH 04/13] upgrade requirements --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6775bc7..2ffd314 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -Django>=1.4 -python-keyczar==0.715 +Django>=1.8 +python-keyczar==0.716 From 16c809ea75bbd77f1d73612e4ec60cddbd798213 Mon Sep 17 00:00:00 2001 From: Aron Jones Date: Thu, 26 Jan 2017 11:07:22 -0500 Subject: [PATCH 05/13] change to py3 assertEqual --- encrypted_fields/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/encrypted_fields/tests.py b/encrypted_fields/tests.py index fa875b8..fa708b3 100644 --- a/encrypted_fields/tests.py +++ b/encrypted_fields/tests.py @@ -120,7 +120,7 @@ def test_decrypt_only_field(self): model.save() plaintext = self.get_db_value('decrypt_only', model.id) - self.assertEquals(plaintext, known_plaintext) + self.assertEqual(plaintext, known_plaintext) def test_decrypt_only_plaintext(self): known_plaintext = 'I am so plain and ordinary' @@ -129,7 +129,7 @@ def test_decrypt_only_plaintext(self): model.save() plaintext = self.get_db_value('decrypt_only', model.id) - self.assertEquals(plaintext, known_plaintext) + self.assertEqual(plaintext, known_plaintext) def test_char_field_encrypted(self): plaintext = 'Oh hi, test reader!' From 4e383a454648e0882fdccf5bc2a413106685505b Mon Sep 17 00:00:00 2001 From: Aron Jones Date: Thu, 26 Jan 2017 13:45:24 -0500 Subject: [PATCH 06/13] fix six for string types --- encrypted_fields/fields.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/encrypted_fields/fields.py b/encrypted_fields/fields.py index d8ea0e8..ac80ed6 100644 --- a/encrypted_fields/fields.py +++ b/encrypted_fields/fields.py @@ -1,12 +1,14 @@ import os import types +import binascii import django from django.db import models from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.utils.functional import cached_property +from django.utils import six try: from django.utils.encoding import smart_text @@ -163,7 +165,7 @@ def from_db_value(self, value, expression, connection, context): return self.to_python(value) def to_python(self, value): - if value is None or not isinstance(value, types.StringTypes): + if value is None or not isinstance(value, six.string_types): return value if self.prefix and value.startswith(self.prefix): @@ -177,7 +179,7 @@ def to_python(self, value): except UnicodeEncodeError: pass except binascii.Error: - pass + pass return super(EncryptedFieldMixin, self).to_python(value) @@ -187,7 +189,7 @@ def get_prep_value(self, value): if value is None or value == '' or self.decrypt_only: return value - if isinstance(value, types.StringTypes): + if isinstance(value, six.string_types): value = value.encode('unicode_escape') value = value.encode('ascii') else: From b39b07fd44cced9f54e89ac0cd218090bbfbf128 Mon Sep 17 00:00:00 2001 From: Mark Lavin Date: Fri, 9 Feb 2018 09:45:01 -0500 Subject: [PATCH 07/13] Use python3 version of keyczar --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7631311..93b4f3a 100755 --- a/setup.py +++ b/setup.py @@ -28,6 +28,6 @@ version=version, install_requires=[ 'Django>=1.4', - 'python-keyczar>=0.71c', + 'python3-keyczar>=0.71c', ], ) From 72e2084cb045af82b14e195255b74dc1e06b1b80 Mon Sep 17 00:00:00 2001 From: Mark Lavin Date: Fri, 9 Feb 2018 10:00:16 -0500 Subject: [PATCH 08/13] Python 3 fixes. --- encrypted_fields/fields.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/encrypted_fields/fields.py b/encrypted_fields/fields.py index ac80ed6..ee17313 100644 --- a/encrypted_fields/fields.py +++ b/encrypted_fields/fields.py @@ -1,19 +1,13 @@ - import os -import types import binascii import django from django.db import models from django.conf import settings from django.core.exceptions import ImproperlyConfigured -from django.utils.functional import cached_property from django.utils import six - -try: - from django.utils.encoding import smart_text -except ImportError: - from django.utils.encoding import smart_str as smart_text +from django.utils.encoding import force_text +from django.utils.functional import cached_property from keyczar import keyczar @@ -172,8 +166,7 @@ def to_python(self, value): value = value[len(self.prefix):] try: - value = self.crypter().decrypt(value) - value = value.decode('unicode_escape') + value = force_text(self.crypter().decrypt(value)) except keyczar.errors.KeyczarError: pass except UnicodeEncodeError: @@ -189,11 +182,7 @@ def get_prep_value(self, value): if value is None or value == '' or self.decrypt_only: return value - if isinstance(value, six.string_types): - value = value.encode('unicode_escape') - value = value.encode('ascii') - else: - value = str(value) + value = force_text(value) return self.prefix + self.crypter().encrypt(value) @@ -230,6 +219,7 @@ class EncryptedDateTimeField(EncryptedFieldMixin, models.DateTimeField): class EncryptedIntegerField(EncryptedFieldMixin, models.IntegerField): + @cached_property def validators(self): """ From 4390334d12f0d90c321d2dcb0084e19db84af65b Mon Sep 17 00:00:00 2001 From: Mark Lavin Date: Fri, 9 Feb 2018 10:09:10 -0500 Subject: [PATCH 09/13] Bump version number. --- encrypted_fields/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encrypted_fields/__init__.py b/encrypted_fields/__init__.py index 6e6ddb0..6052d8a 100644 --- a/encrypted_fields/__init__.py +++ b/encrypted_fields/__init__.py @@ -1,3 +1,3 @@ -__version__ = '1.1.2' +__version__ = '1.2.0a1' from .fields import * From 2df62d5de28d3dedb3867fd93cacad31f6de761f Mon Sep 17 00:00:00 2001 From: Mark Lavin Date: Fri, 9 Feb 2018 10:14:11 -0500 Subject: [PATCH 10/13] Change requirements.txt as well to use python3-keyczar. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2ffd314..89c6de9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ Django>=1.8 -python-keyczar==0.716 +python3-keyczar==0.71rc0 From 134e7f06b7433e30f5d709bedbd62e75e8787d59 Mon Sep 17 00:00:00 2001 From: Mark Lavin Date: Fri, 9 Feb 2018 10:23:10 -0500 Subject: [PATCH 11/13] Test on Django 1.11 as well. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6498615..31f3b8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ env: - DJANGO_VERSION=1.8 - DJANGO_VERSION=1.9 - DJANGO_VERSION=1.10 + - DJANGO_VERSION=1.11 install: - pip install -q Django==$DJANGO_VERSION - pip install -q -r requirements.txt From f4ea5cf97afb07c7cc19ef3bde2215f30d9da324 Mon Sep 17 00:00:00 2001 From: Bil Bas Date: Thu, 19 Sep 2019 21:26:44 +0100 Subject: [PATCH 12/13] Use correct params for from_db_value() from_db_value() "context" param generates a deprecation warning in Django 2.2 - should be **kwargs --- encrypted_fields/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encrypted_fields/fields.py b/encrypted_fields/fields.py index d8ea0e8..b647d88 100644 --- a/encrypted_fields/fields.py +++ b/encrypted_fields/fields.py @@ -159,7 +159,7 @@ def get_internal_type(self): def load_crypter(self): self._crypter = self._crypter_klass(self.keydir) - def from_db_value(self, value, expression, connection, context): + def from_db_value(self, value, expression, connection, **kwargs): return self.to_python(value) def to_python(self, value): From 2b44887c8d6c48cdc9b377ad0e616925113945ec Mon Sep 17 00:00:00 2001 From: Bil Bas Date: Sun, 5 Jul 2020 19:29:50 +0100 Subject: [PATCH 13/13] Update fields.py Removed dependency on six --- encrypted_fields/fields.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/encrypted_fields/fields.py b/encrypted_fields/fields.py index 66fa565..42977a0 100644 --- a/encrypted_fields/fields.py +++ b/encrypted_fields/fields.py @@ -5,7 +5,6 @@ from django.db import models from django.conf import settings from django.core.exceptions import ImproperlyConfigured -from django.utils import six from django.utils.encoding import force_text from django.utils.functional import cached_property @@ -159,7 +158,7 @@ def from_db_value(self, value, expression, connection, **kwargs): return self.to_python(value) def to_python(self, value): - if value is None or not isinstance(value, six.string_types): + if value is None or not isinstance(value, (str, bytes)): return value if self.prefix and value.startswith(self.prefix):