From 0863f05fb7205f0eda4a293319f45833c753d68d Mon Sep 17 00:00:00 2001 From: Alex Moiseenko Date: Fri, 27 Apr 2012 19:23:23 +0300 Subject: [PATCH 1/3] patched applying of synonyms during decoding process, fixed incorrect test --- pyamf/alias.py | 4 ++-- pyamf/tests/test_alias.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyamf/alias.py b/pyamf/alias.py index ab4f63ce..a365476e 100644 --- a/pyamf/alias.py +++ b/pyamf/alias.py @@ -504,12 +504,12 @@ def getDecodableAttributes(self, obj, attrs, codec=None): missing = object() for k, v in self.synonym_attrs.iteritems(): - value = attrs.pop(k, missing) + value = attrs.pop(v, missing) if value is missing: continue - attrs[v] = value + attrs[k] = value if not changed: return attrs diff --git a/pyamf/tests/test_alias.py b/pyamf/tests/test_alias.py index b96b1884..0aaf7574 100644 --- a/pyamf/tests/test_alias.py +++ b/pyamf/tests/test_alias.py @@ -391,13 +391,13 @@ def test_synonym(self): self.assertFalse(self.alias.shortcut_decode) attrs = { - 'foo': 'foo', + 'bar': 'foo', 'spam': 'eggs' } ret = self.alias.getDecodableAttributes(self.obj, attrs) - self.assertEquals(ret, {'bar': 'foo', 'spam': 'eggs'}) + self.assertEquals(ret, {'foo': 'foo', 'spam': 'eggs'}) class ApplyAttributesTestCase(unittest.TestCase): From 95ca36705042769165ef40082ce8e61fcbad45aa Mon Sep 17 00:00:00 2001 From: Alex Moiseenko Date: Sat, 5 May 2012 19:30:18 +0300 Subject: [PATCH 2/3] Added test that covers synonyms+exclude case and fixed issue due to this combination --- pyamf/alias.py | 16 ++++++++-------- pyamf/tests/test_alias.py | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/pyamf/alias.py b/pyamf/alias.py index a365476e..36a18b33 100644 --- a/pyamf/alias.py +++ b/pyamf/alias.py @@ -500,6 +500,13 @@ def getDecodableAttributes(self, obj, attrs, codec=None): attrs[k] = context.getObjectForProxy(v) + if changed: + # apply all filters before synonyms + a = {} + + [a.__setitem__(p, attrs[p]) for p in props] + attrs = a + if self.synonym_attrs: missing = object() @@ -511,14 +518,7 @@ def getDecodableAttributes(self, obj, attrs, codec=None): attrs[k] = value - if not changed: - return attrs - - a = {} - - [a.__setitem__(p, attrs[p]) for p in props] - - return a + return attrs def applyAttributes(self, obj, attrs, codec=None): """ diff --git a/pyamf/tests/test_alias.py b/pyamf/tests/test_alias.py index 0aaf7574..0e989ee8 100644 --- a/pyamf/tests/test_alias.py +++ b/pyamf/tests/test_alias.py @@ -399,6 +399,31 @@ def test_synonym(self): self.assertEquals(ret, {'foo': 'foo', 'spam': 'eggs'}) + def test_complex_synonym(self): + self.alias.synonym_attrs = {'foo_syn': 'bar_syn'} + self.alias.compile() + + self.alias.static_properties = ['foo_syn', ] + self.alias.exclude_attrs = ['baz', 'gak'] + self.alias.readonly_attrs = ['spam_rd_1', 'spam_rd_2'] + + + self.assertFalse(self.alias.shortcut_encode) + self.assertFalse(self.alias.shortcut_decode) + + attrs = { + 'bar_syn': 'foo', + 'spam': 'eggs', + 'spam_rd_1': 'eggs', + 'spam_rd_2': 'eggs', + 'baz': 'remove me', + 'gak': 'remove me' + } + + ret = self.alias.getDecodableAttributes(self.obj, attrs) + + self.assertEquals(ret, {'foo_syn': 'foo', 'spam': 'eggs'}) + class ApplyAttributesTestCase(unittest.TestCase): """ From be052f1a7df6e3308f0c6226e6f53ab394d6315a Mon Sep 17 00:00:00 2001 From: Nick Joyce Date: Fri, 23 Jan 2015 13:33:48 +0000 Subject: [PATCH 3/3] Fix Flake8 issue --- pyamf/tests/test_alias.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyamf/tests/test_alias.py b/pyamf/tests/test_alias.py index 0e989ee8..5872d7ca 100644 --- a/pyamf/tests/test_alias.py +++ b/pyamf/tests/test_alias.py @@ -407,7 +407,6 @@ def test_complex_synonym(self): self.alias.exclude_attrs = ['baz', 'gak'] self.alias.readonly_attrs = ['spam_rd_1', 'spam_rd_2'] - self.assertFalse(self.alias.shortcut_encode) self.assertFalse(self.alias.shortcut_decode)