Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
metadata is now always stored as a set
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Oct 5, 2015
1 parent 5db8ae2 commit d93452b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Pyro4/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def register(self, name, uri, safe=False, metadata=None):
with self.lock:
if safe and name in self.storage:
raise NamingError("name already registered: " + name)
if metadata:
metadata = set(metadata)
self.storage[name] = uri, metadata

def set_metadata(self, name, metadata):
Expand All @@ -117,6 +119,8 @@ def set_metadata(self, name, metadata):
with self.lock:
try:
uri, old_meta = self.storage[name]
if metadata:
metadata = set(metadata)
self.storage[name] = uri, metadata
except KeyError:
raise NamingError("unknown name: " + name)
Expand Down
14 changes: 13 additions & 1 deletion tests/PyroTests/test_naming2.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def testMetadata(self):
# register some names with metadata, and perform simple lookups
ns.register("meta1", "PYRO:meta1@localhost:1111", metadata={"a", "b", "c"})
ns.register("meta2", "PYRO:meta2@localhost:2222", metadata={"x", "y", "z"})
ns.register("meta3", "PYRO:meta3@localhost:3333", metadata=["p", "q", "r", "r", "q"])
uri = ns.lookup("meta1")
self.assertEqual("meta1", uri.object)
uri, metadata = ns.lookup("meta1", return_metadata=True)
Expand All @@ -287,9 +288,14 @@ def testMetadata(self):
uri, metadata = ns.lookup("meta2", return_metadata=True)
self.assertEqual("meta2", uri.object)
self.assertSetEqual({"x", "y", "z"}, metadata)
uri, metadata = ns.lookup("meta3", return_metadata=True)
self.assertEqual("meta3", uri.object)
self.assertIsInstance(metadata, set)
self.assertSetEqual({"p", "q", "r"}, metadata)
# get a list of everything, without and with metadata
reg = ns.list()
self.assertDictEqual({'meta1': 'PYRO:meta1@localhost:1111', 'meta2': 'PYRO:meta2@localhost:2222'}, reg)
self.assertDictEqual({'meta1': 'PYRO:meta1@localhost:1111', 'meta2': 'PYRO:meta2@localhost:2222',
'meta3': 'PYRO:meta3@localhost:3333'}, reg)
reg = ns.list(return_metadata=True)
uri1, meta1 = reg["meta1"]
uri2, meta2 = reg["meta2"]
Expand Down Expand Up @@ -318,8 +324,14 @@ def testMetadata(self):
ns.set_metadata("meta1", {"one", "two", "three"})
uri, meta = ns.lookup("meta1", return_metadata=True)
self.assertSetEqual({"one", "two", "three"}, meta)
# check that a collection is converted to a set
ns.set_metadata("meta1", ["one", "two", "three", "three", "two"])
uri, meta = ns.lookup("meta1", return_metadata=True)
self.assertIsInstance(meta, set)
self.assertSetEqual({"one", "two", "three"}, meta)
# remove record that has some metadata
ns.remove("meta1")
ns.remove("meta3")
self.assertEqual(["meta2"], list(ns.list().keys()))
# other list filters
reg = ns.list(prefix="meta", return_metadata=True)
Expand Down

0 comments on commit d93452b

Please sign in to comment.