Skip to content

Commit

Permalink
Merge pull request #40 from hydralabs/fix-synonym
Browse files Browse the repository at this point in the history
Fix synonym
  • Loading branch information
njoyce committed Jan 23, 2015
2 parents 872fda4 + be052f1 commit 7e42b15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
20 changes: 10 additions & 10 deletions pyamf/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,25 +500,25 @@ 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()

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

a = {}

[a.__setitem__(p, attrs[p]) for p in props]

return a
return attrs

def applyAttributes(self, obj, attrs, codec=None):
"""
Expand Down
28 changes: 26 additions & 2 deletions pyamf/tests/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,37 @@ 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'})

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):
Expand Down

0 comments on commit 7e42b15

Please sign in to comment.