Hello community,
here is the log from the commit of package python-SQLAlchemy-Utils for
openSUSE:Factory checked in at 2018-09-26 14:24:34
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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 26 14:24:34 2018 rev:12 rq:638277 version:0.33.5
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-SQLAlchemy-Utils/python-SQLAlchemy-Utils.changes
2018-09-18 11:44:20.623853770 +0200
+++
/work/SRC/openSUSE:Factory/.python-SQLAlchemy-Utils.new/python-SQLAlchemy-Utils.changes
2018-09-26 14:24:56.585776677 +0200
@@ -1,0 +2,9 @@
+Sat Sep 22 05:30:08 UTC 2018 - Arun Persaud <[email protected]>
+
+- update to version 0.33.5:
+ * Added optional attr parameter for locale calleble in
+ TranslationHybrid
+ * Fixed an issue with PasswordType so that it is compatible with
+ older versions of passlib (#342)
+
+-------------------------------------------------------------------
Old:
----
SQLAlchemy-Utils-0.33.4.tar.gz
New:
----
SQLAlchemy-Utils-0.33.5.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-SQLAlchemy-Utils.spec ++++++
--- /var/tmp/diff_new_pack.lc6n86/_old 2018-09-26 14:24:57.073775901 +0200
+++ /var/tmp/diff_new_pack.lc6n86/_new 2018-09-26 14:24:57.077775895 +0200
@@ -18,7 +18,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name: python-SQLAlchemy-Utils
-Version: 0.33.4
+Version: 0.33.5
Release: 0
Summary: Various utility functions for SQLAlchemy
License: BSD-3-Clause
++++++ SQLAlchemy-Utils-0.33.4.tar.gz -> SQLAlchemy-Utils-0.33.5.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/SQLAlchemy-Utils-0.33.4/CHANGES.rst
new/SQLAlchemy-Utils-0.33.5/CHANGES.rst
--- old/SQLAlchemy-Utils-0.33.4/CHANGES.rst 2018-09-11 09:51:09.000000000
+0200
+++ new/SQLAlchemy-Utils-0.33.5/CHANGES.rst 2018-09-20 09:34:38.000000000
+0200
@@ -3,6 +3,14 @@
Here you can see the full list of changes between each SQLAlchemy-Utils
release.
+
+0.33.5 (2018-09-19)
+^^^^^^^^^^^^^^^^^^^
+
+- Added optional attr parameter for locale calleble in TranslationHybrid
+- Fixed an issue with PasswordType so that it is compatible with older
versions of passlib (#342)
+
+
0.33.4 (2018-09-11)
^^^^^^^^^^^^^^^^^^^
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/SQLAlchemy-Utils-0.33.4/PKG-INFO
new/SQLAlchemy-Utils-0.33.5/PKG-INFO
--- old/SQLAlchemy-Utils-0.33.4/PKG-INFO 2018-09-11 09:52:29.000000000
+0200
+++ new/SQLAlchemy-Utils-0.33.5/PKG-INFO 2018-09-20 09:39:00.000000000
+0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: SQLAlchemy-Utils
-Version: 0.33.4
+Version: 0.33.5
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.33.4/SQLAlchemy_Utils.egg-info/PKG-INFO
new/SQLAlchemy-Utils-0.33.5/SQLAlchemy_Utils.egg-info/PKG-INFO
--- old/SQLAlchemy-Utils-0.33.4/SQLAlchemy_Utils.egg-info/PKG-INFO
2018-09-11 09:52:29.000000000 +0200
+++ new/SQLAlchemy-Utils-0.33.5/SQLAlchemy_Utils.egg-info/PKG-INFO
2018-09-20 09:39:00.000000000 +0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: SQLAlchemy-Utils
-Version: 0.33.4
+Version: 0.33.5
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.33.4/docs/internationalization.rst
new/SQLAlchemy-Utils-0.33.5/docs/internationalization.rst
--- old/SQLAlchemy-Utils-0.33.4/docs/internationalization.rst 2015-08-16
10:02:59.000000000 +0200
+++ new/SQLAlchemy-Utils-0.33.5/docs/internationalization.rst 2018-09-20
09:34:12.000000000 +0200
@@ -120,7 +120,9 @@
---------------
Sometimes locales need to be dynamic. The following example illustrates how to
setup
-dynamic locales.
+dynamic locales. You can pass a callable of either 0, 1 or 2 args as a
constructor parameter for TranslationHybrid.
+
+The first argument should be the associated object and second parameter the
name of the translations attribute.
::
@@ -142,12 +144,24 @@
article = Article(name_translations={'en': 'Some article'})
+ article.locale = 'en'
session.add(article)
session.commit()
article.name # Some article (even if current locale is other than 'en')
+The locales can also be attribute dependent so you can set up translation
hybrid in a way that
+it is guaranteed to return a translation.
+
+::
+
+ translation_hybrid.default_locale = lambda obj, attr: sorted(getattr(obj,
attr).keys())[0]
+
+
+ article.name # Some article
+
+
.. _SQLAlchemy-i18n: https://github.com/kvesteri/sqlalchemy-i18n
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/SQLAlchemy-Utils-0.33.4/sqlalchemy_utils/__init__.py
new/SQLAlchemy-Utils-0.33.5/sqlalchemy_utils/__init__.py
--- old/SQLAlchemy-Utils-0.33.4/sqlalchemy_utils/__init__.py 2018-09-11
09:51:22.000000000 +0200
+++ new/SQLAlchemy-Utils-0.33.5/sqlalchemy_utils/__init__.py 2018-09-20
09:38:10.000000000 +0200
@@ -99,4 +99,4 @@
WeekDaysType
)
-__version__ = '0.33.4'
+__version__ = '0.33.5'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/SQLAlchemy-Utils-0.33.4/sqlalchemy_utils/i18n.py
new/SQLAlchemy-Utils-0.33.5/sqlalchemy_utils/i18n.py
--- old/SQLAlchemy-Utils-0.33.4/sqlalchemy_utils/i18n.py 2016-04-25
16:20:06.000000000 +0200
+++ new/SQLAlchemy-Utils-0.33.5/sqlalchemy_utils/i18n.py 2018-09-20
09:34:12.000000000 +0200
@@ -1,3 +1,5 @@
+import inspect
+
import six
import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
@@ -23,7 +25,22 @@
)
-def cast_locale(obj, locale):
+if six.PY2:
+ def get_args_count(func):
+ if (
+ callable(func) and
+ not inspect.isfunction(func) and
+ not inspect.ismethod(func)
+ ):
+ func = func.__call__
+ args = inspect.getargspec(func).args
+ return len(args) - 1 if inspect.ismethod(func) else len(args)
+else:
+ def get_args_count(func):
+ return len(inspect.signature(func).parameters)
+
+
+def cast_locale(obj, locale, attr):
"""
Cast given locale to string. Supports also callbacks that return locales.
@@ -33,24 +50,28 @@
Locale object or string or callable that returns a locale.
"""
if callable(locale):
- try:
+ args_count = get_args_count(locale)
+ if args_count == 0:
locale = locale()
- except TypeError:
+ elif args_count == 1:
locale = locale(obj)
+ elif args_count == 2:
+ locale = locale(obj, attr.key)
if isinstance(locale, babel.Locale):
return str(locale)
return locale
class cast_locale_expr(ColumnElement):
- def __init__(self, cls, locale):
+ def __init__(self, cls, locale, attr):
self.cls = cls
self.locale = locale
+ self.attr = attr
@compiles(cast_locale_expr)
def compile_cast_locale_expr(element, compiler, **kw):
- locale = cast_locale(element.cls, element.locale)
+ locale = cast_locale(element.cls, element.locale, element.attr)
if isinstance(locale, six.string_types):
return "'{0}'".format(locale)
return compiler.process(locale)
@@ -74,13 +95,11 @@
is no translation found for default locale it returns None.
"""
def getter(obj):
- current_locale = cast_locale(obj, self.current_locale)
+ current_locale = cast_locale(obj, self.current_locale, attr)
try:
return getattr(obj, attr.key)[current_locale]
except (TypeError, KeyError):
- default_locale = cast_locale(
- obj, self.default_locale
- )
+ default_locale = cast_locale(obj, self.default_locale, attr)
try:
return getattr(obj, attr.key)[default_locale]
except (TypeError, KeyError):
@@ -91,15 +110,15 @@
def setter(obj, value):
if getattr(obj, attr.key) is None:
setattr(obj, attr.key, {})
- locale = cast_locale(obj, self.current_locale)
+ locale = cast_locale(obj, self.current_locale, attr)
getattr(obj, attr.key)[locale] = value
return setter
def expr_factory(self, attr):
def expr(cls):
cls_attr = getattr(cls, attr.key)
- current_locale = cast_locale_expr(cls, self.current_locale)
- default_locale = cast_locale_expr(cls, self.default_locale)
+ current_locale = cast_locale_expr(cls, self.current_locale, attr)
+ default_locale = cast_locale_expr(cls, self.default_locale, attr)
return sa.func.coalesce(
cls_attr[current_locale],
cls_attr[default_locale]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/SQLAlchemy-Utils-0.33.4/sqlalchemy_utils/types/password.py
new/SQLAlchemy-Utils-0.33.5/sqlalchemy_utils/types/password.py
--- old/SQLAlchemy-Utils-0.33.4/sqlalchemy_utils/types/password.py
2018-09-11 09:49:17.000000000 +0200
+++ new/SQLAlchemy-Utils-0.33.5/sqlalchemy_utils/types/password.py
2018-09-19 19:09:17.000000000 +0200
@@ -158,7 +158,7 @@
# Construct the passlib crypt context.
self.context = LazyCryptContext(**kwargs)
-
+ self.hashing_method = 'hash' if hasattr(self, 'hash') else 'encrypt'
self._max_length = max_length
@property
@@ -207,19 +207,22 @@
if isinstance(value, Password):
# If were given a password secret; hash it.
if value.secret is not None:
- return self.context.hash(value.secret).encode('utf8')
+ return self._hash(value.secret).encode('utf8')
# Value has already been hashed.
return value.hash
if isinstance(value, six.string_types):
# Assume value has not been hashed.
- return self.context.hash(value).encode('utf8')
+ return self._hash(value).encode('utf8')
def process_result_value(self, value, dialect):
if value is not None:
return Password(value, self.context)
+ def _hash(self, value):
+ return getattr(self.context, self.hashing_method)(value)
+
def _coerce(self, value):
if value is None:
@@ -227,7 +230,7 @@
if not isinstance(value, Password):
# Hash the password using the default scheme.
- value = self.context.hash(value).encode('utf8')
+ value = self._hash(value).encode('utf8')
return Password(value, context=self.context)
else:
@@ -236,7 +239,7 @@
# If were given a password secret; hash it.
if value.secret is not None:
- value.hash = self.context.hash(value.secret).encode('utf8')
+ value.hash = self._hash(value.secret).encode('utf8')
value.secret = None
return value
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/SQLAlchemy-Utils-0.33.4/tests/test_translation_hybrid.py
new/SQLAlchemy-Utils-0.33.5/tests/test_translation_hybrid.py
--- old/SQLAlchemy-Utils-0.33.4/tests/test_translation_hybrid.py
2016-10-20 09:57:03.000000000 +0200
+++ new/SQLAlchemy-Utils-0.33.5/tests/test_translation_hybrid.py
2018-09-20 09:34:12.000000000 +0200
@@ -59,6 +59,17 @@
assert city.name == 'Helsinki'
+ def test_fallback_to_attr_dependent_locale(self, City, translation_hybrid):
+ translation_hybrid.current_locale = 'en'
+ translation_hybrid.default_locale = (
+ lambda obj, attr: sorted(getattr(obj, attr).keys())[0]
+ )
+ city = City(name_translations={})
+ city.name_translations['fi'] = 'Helsinki'
+ assert city.name == 'Helsinki'
+ city.name_translations['de'] = 'Stadt Helsinki'
+ assert city.name == 'Stadt Helsinki'
+
@pytest.mark.parametrize(
('name_translations', 'name'),
(