Hello community,

here is the log from the commit of package python-SQLAlchemy-Utils for 
openSUSE:Factory checked in at 2017-09-27 16:55:26
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-SQLAlchemy-Utils (Old)
 and      /work/SRC/openSUSE:Factory/.python-SQLAlchemy-Utils.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-SQLAlchemy-Utils"

Wed Sep 27 16:55:26 2017 rev:4 rq:528893 version:0.32.16

Changes:
--------
--- 
/work/SRC/openSUSE:Factory/python-SQLAlchemy-Utils/python-SQLAlchemy-Utils.changes
  2017-09-05 15:14:46.644971447 +0200
+++ 
/work/SRC/openSUSE:Factory/.python-SQLAlchemy-Utils.new/python-SQLAlchemy-Utils.changes
     2017-09-27 16:55:27.834132136 +0200
@@ -1,0 +2,11 @@
+Sun Sep 24 21:56:50 UTC 2017 - [email protected]
+
+- update to version 0.32.16:
+  * Added more hints when decrypting AES with an invalid key (#275,
+    pull request courtesy of xrmx)
+
+- changes from version 0.32.15:
+  * Added better handling of date types for EncryptedType (#184, pull
+    request courtesy of konstantinoskostis)
+
+-------------------------------------------------------------------

Old:
----
  SQLAlchemy-Utils-0.32.14.tar.gz

New:
----
  SQLAlchemy-Utils-0.32.16.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-SQLAlchemy-Utils.spec ++++++
--- /var/tmp/diff_new_pack.5zCJXc/_old  2017-09-27 16:55:28.490039863 +0200
+++ /var/tmp/diff_new_pack.5zCJXc/_new  2017-09-27 16:55:28.494039300 +0200
@@ -18,7 +18,7 @@
 
 %{?!python_module:%define python_module() python-%{**} python3-%{**}}
 Name:           python-SQLAlchemy-Utils
-Version:        0.32.14
+Version:        0.32.16
 Release:        0
 Summary:        Various utility functions for SQLAlchemy
 License:        BSD-3-Clause

++++++ SQLAlchemy-Utils-0.32.14.tar.gz -> SQLAlchemy-Utils-0.32.16.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/SQLAlchemy-Utils-0.32.14/CHANGES.rst 
new/SQLAlchemy-Utils-0.32.16/CHANGES.rst
--- old/SQLAlchemy-Utils-0.32.14/CHANGES.rst    2017-03-27 15:48:21.000000000 
+0200
+++ new/SQLAlchemy-Utils-0.32.16/CHANGES.rst    2017-09-01 11:08:03.000000000 
+0200
@@ -4,6 +4,18 @@
 Here you can see the full list of changes between each SQLAlchemy-Utils 
release.
 
 
+0.32.16 (2017-09-01)
+^^^^^^^^^^^^^^^^^^^^
+
+- Added more hints when decrypting AES with an invalid key (#275, pull request 
courtesy of xrmx)
+
+
+0.32.15 (2017-08-31)
+^^^^^^^^^^^^^^^^^^^^
+
+- Added better handling of date types for EncryptedType (#184, pull request 
courtesy of konstantinoskostis)
+
+
 0.32.14 (2017-03-27)
 ^^^^^^^^^^^^^^^^^^^^
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/SQLAlchemy-Utils-0.32.14/PKG-INFO 
new/SQLAlchemy-Utils-0.32.16/PKG-INFO
--- old/SQLAlchemy-Utils-0.32.14/PKG-INFO       2017-03-27 15:57:06.000000000 
+0200
+++ new/SQLAlchemy-Utils-0.32.16/PKG-INFO       2017-09-01 11:09:22.000000000 
+0200
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: SQLAlchemy-Utils
-Version: 0.32.14
+Version: 0.32.16
 Summary: Various utility functions for SQLAlchemy.
 Home-page: https://github.com/kvesteri/sqlalchemy-utils
 Author: Konsta Vesterinen, Ryan Leckey, Janne Vanhala, Vesa Uimonen
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/SQLAlchemy-Utils-0.32.14/SQLAlchemy_Utils.egg-info/PKG-INFO 
new/SQLAlchemy-Utils-0.32.16/SQLAlchemy_Utils.egg-info/PKG-INFO
--- old/SQLAlchemy-Utils-0.32.14/SQLAlchemy_Utils.egg-info/PKG-INFO     
2017-03-27 15:57:05.000000000 +0200
+++ new/SQLAlchemy-Utils-0.32.16/SQLAlchemy_Utils.egg-info/PKG-INFO     
2017-09-01 11:09:21.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: SQLAlchemy-Utils
-Version: 0.32.14
+Version: 0.32.16
 Summary: Various utility functions for SQLAlchemy.
 Home-page: https://github.com/kvesteri/sqlalchemy-utils
 Author: Konsta Vesterinen, Ryan Leckey, Janne Vanhala, Vesa Uimonen
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/SQLAlchemy-Utils-0.32.14/sqlalchemy_utils/__init__.py 
new/SQLAlchemy-Utils-0.32.16/sqlalchemy_utils/__init__.py
--- old/SQLAlchemy-Utils-0.32.14/sqlalchemy_utils/__init__.py   2017-03-27 
15:48:47.000000000 +0200
+++ new/SQLAlchemy-Utils-0.32.16/sqlalchemy_utils/__init__.py   2017-09-01 
11:08:46.000000000 +0200
@@ -95,4 +95,4 @@
     WeekDaysType
 )
 
-__version__ = '0.32.14'
+__version__ = '0.32.16'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/SQLAlchemy-Utils-0.32.14/sqlalchemy_utils/types/encrypted.py 
new/SQLAlchemy-Utils-0.32.16/sqlalchemy_utils/types/encrypted.py
--- old/SQLAlchemy-Utils-0.32.14/sqlalchemy_utils/types/encrypted.py    
2017-03-12 11:08:09.000000000 +0100
+++ new/SQLAlchemy-Utils-0.32.16/sqlalchemy_utils/types/encrypted.py    
2017-09-01 08:58:42.000000000 +0200
@@ -21,6 +21,14 @@
     pass
 
 
+dateutil = None
+try:
+    import dateutil
+    from dateutil.parser import parse as datetime_parse
+except ImportError:
+    pass
+
+
 class EncryptionDecryptionBaseEngine(object):
     """A base encryption and decryption engine.
 
@@ -86,7 +94,10 @@
         decrypted = decryptor.update(decrypted) + decryptor.finalize()
         decrypted = decrypted.rstrip(self.PADDING)
         if not isinstance(decrypted, six.string_types):
-            decrypted = decrypted.decode('utf-8')
+            try:
+                decrypted = decrypted.decode('utf-8')
+            except UnicodeDecodeError:
+                raise ValueError('Invalid decryption key')
         return decrypted
 
 
@@ -270,24 +281,16 @@
 
                 # Handle 'boolean' and 'dates'
                 type_ = self.underlying_type.python_type
+                date_types = [datetime.datetime, datetime.time, datetime.date]
+
                 if issubclass(type_, bool):
                     return decrypted_value == 'true'
 
-                elif issubclass(type_, datetime.datetime):
-                    return datetime.datetime.strptime(
-                        decrypted_value, '%Y-%m-%dT%H:%M:%S'
+                elif type_ in date_types:
+                    return DatetimeHandler.process_value(
+                        decrypted_value, type_
                     )
 
-                elif issubclass(type_, datetime.time):
-                    return datetime.datetime.strptime(
-                        decrypted_value, '%H:%M:%S'
-                    ).time()
-
-                elif issubclass(type_, datetime.date):
-                    return datetime.datetime.strptime(
-                        decrypted_value, '%Y-%m-%d'
-                    ).date()
-
                 # Handle all others
                 return self.underlying_type.python_type(decrypted_value)
 
@@ -296,3 +299,31 @@
             return self.underlying_type._coerce(value)
 
         return value
+
+
+class DatetimeHandler(object):
+    """
+    DatetimeHandler is responsible for parsing strings and
+    returning the appropriate date, datetime or time objects.
+    """
+
+    @classmethod
+    def process_value(cls, value, python_type):
+        """
+        process_value returns a datetime, date
+        or time object according to a given string
+        value and a python type.
+        """
+        if not dateutil:
+            raise ImproperlyConfigured(
+                "'python-dateutil' is required to process datetimes"
+            )
+
+        return_value = datetime_parse(value)
+
+        if issubclass(python_type, datetime.datetime):
+            return return_value
+        elif issubclass(python_type, datetime.time):
+            return return_value.time()
+        elif issubclass(python_type, datetime.date):
+            return return_value.date()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/SQLAlchemy-Utils-0.32.14/tests/types/test_encrypted.py 
new/SQLAlchemy-Utils-0.32.16/tests/types/test_encrypted.py
--- old/SQLAlchemy-Utils-0.32.14/tests/types/test_encrypted.py  2016-04-25 
16:20:07.000000000 +0200
+++ new/SQLAlchemy-Utils-0.32.16/tests/types/test_encrypted.py  2017-09-01 
08:58:42.000000000 +0200
@@ -4,7 +4,11 @@
 import sqlalchemy as sa
 
 from sqlalchemy_utils import ColorType, EncryptedType, PhoneNumberType
-from sqlalchemy_utils.types.encrypted import AesEngine, FernetEngine
+from sqlalchemy_utils.types.encrypted import (
+    AesEngine,
+    DatetimeHandler,
+    FernetEngine
+)
 
 cryptography = None
 try:
@@ -119,7 +123,7 @@
 
 @pytest.fixture
 def user_datetime():
-    return datetime(2010, 10, 2, 10, 12)
+    return datetime(2010, 10, 2, 10, 12, 45, 2334)
 
 
 @pytest.fixture
@@ -177,6 +181,38 @@
     return session.query(User).get(user.id)
 
 
[email protected]
+def datetime_with_micro_and_timezone():
+    import pytz
+    tz = pytz.timezone('Pacific/Tahiti')
+    return datetime(2017, 8, 21, 4, 26, 36, 523010, tzinfo=tz)
+
+
[email protected]
+def datetime_with_micro():
+    return datetime(2017, 8, 21, 10, 12, 45, 22)
+
+
[email protected]
+def datetime_simple():
+    return datetime(2017, 8, 21, 10, 12, 45)
+
+
[email protected]
+def time_with_micro():
+    return time(10, 12, 45, 22)
+
+
[email protected]
+def time_simple():
+    return time(10, 12, 45)
+
+
[email protected]
+def date_simple():
+    return date(2017, 8, 21)
+
+
 @pytest.mark.skipif('cryptography is None')
 class EncryptedTypeTestCase(object):
 
@@ -289,9 +325,82 @@
 
         assert test.username == user.username
 
+    def test_decrypt_raises_value_error_with_invalid_key(self, session, Team):
+        self._team_key = 'one'
+        team = Team(key=self._team_key, name=u'One')
+        session.add(team)
+        session.commit()
+
+        self._team_key = 'notone'
+        with pytest.raises(ValueError):
+            assert team.name == u'One'
+
 
 class TestFernetEncryptedTypeTestCase(EncryptedTypeTestCase):
 
     @pytest.fixture
     def encryption_engine(self):
         return FernetEngine
+
+
+class TestDatetimeHandler(object):
+
+    def test_datetime_with_micro_and_timezone(self):
+        original_datetime = datetime_with_micro_and_timezone()
+        original_datetime_isoformat = original_datetime.isoformat()
+        python_type = datetime
+
+        assert DatetimeHandler.process_value(
+            original_datetime_isoformat,
+            python_type
+        ) == original_datetime
+
+    def test_datetime_with_micro(self):
+        original_datetime = datetime_with_micro()
+        original_datetime_isoformat = original_datetime.isoformat()
+        python_type = datetime
+
+        assert DatetimeHandler.process_value(
+            original_datetime_isoformat,
+            python_type
+        ) == original_datetime
+
+    def test_datetime_simple(self):
+        original_datetime = datetime_simple()
+        original_datetime_isoformat = original_datetime.isoformat()
+        python_type = datetime
+
+        assert DatetimeHandler.process_value(
+            original_datetime_isoformat,
+            python_type
+        ) == original_datetime
+
+    def test_time_with_micro(self):
+        original_time = time_with_micro()
+        original_time_isoformat = original_time.isoformat()
+        python_type = time
+
+        assert DatetimeHandler.process_value(
+            original_time_isoformat,
+            python_type
+        ) == original_time
+
+    def test_time_simple(self):
+        original_time = time_simple()
+        original_time_isoformat = original_time.isoformat()
+        python_type = time
+
+        assert DatetimeHandler.process_value(
+            original_time_isoformat,
+            python_type
+        ) == original_time
+
+    def test_date_simple(self):
+        original_date = date_simple()
+        original_date_isoformat = original_date.isoformat()
+        python_type = date
+
+        assert DatetimeHandler.process_value(
+            original_date_isoformat,
+            python_type
+        ) == original_date
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/SQLAlchemy-Utils-0.32.14/tests/types/test_timezone.py 
new/SQLAlchemy-Utils-0.32.16/tests/types/test_timezone.py
--- old/SQLAlchemy-Utils-0.32.14/tests/types/test_timezone.py   2016-11-19 
09:35:59.000000000 +0100
+++ new/SQLAlchemy-Utils-0.32.16/tests/types/test_timezone.py   2017-08-31 
14:50:46.000000000 +0200
@@ -63,7 +63,6 @@
 def test_can_coerce_pytz_StaticTzInfo():
     tzcol = TimezoneType(backend='pytz')
     tz = pytz.timezone('Pacific/Truk')
-    assert isinstance(tz, pytz.tzfile.StaticTzInfo)
     assert tzcol._coerce(tz) is tz
 
 


Reply via email to