diff options
author | Marek Siarkowicz <mareksiarkowicz@gmail.com> | 2015-06-14 23:54:28 +0200 |
---|---|---|
committer | Marek Siarkowicz <mareksiarkowicz@gmail.com> | 2015-06-14 23:54:28 +0200 |
commit | 46123a0a78149a8832e9201f33de3a8dfa520c4b (patch) | |
tree | 6e3cc9d8f595b28e45a68509b56ebfa138d26f2e | |
parent | ebb7d4799f00c6ebb2cb1f53dcce4e1b1cc884f3 (diff) | |
download | pyParrotZikTCP-46123a0a78149a8832e9201f33de3a8dfa520c4b.tar.xz pyParrotZikTCP-46123a0a78149a8832e9201f33de3a8dfa520c4b.zip |
Perform one fetch per notification path.
Diffstat (limited to '')
-rw-r--r-- | resource_manager.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/resource_manager.py b/resource_manager.py index 8dcf6bc..752efe4 100644 --- a/resource_manager.py +++ b/resource_manager.py @@ -1,3 +1,4 @@ +from operator import itemgetter import sys from BeautifulSoup import BeautifulSoup import ParrotProtocol @@ -61,12 +62,14 @@ class ResourceManagerBase(object): else: raise AssertionError('Unknown response') data = self.receive_message() - for notification in notifications: - self.handle_notification(notification) + self.handle_notifications(notifications) return data.answer - def handle_notification(self, notification): - self.fetch(self._clean_path(notification['path'])) + def handle_notifications(self, notifications): + paths = map(itemgetter('path'), notifications) + clean_paths = set(map(self._clean_path, paths)) + for path in clean_paths: + self.fetch(path) def _clean_path(self, path): return path.rsplit('/', 1)[0].encode('utf-8') @@ -96,8 +99,7 @@ class GenericResourceManager(ResourceManagerBase): def get_resource_manager(self, resource_manager_class): resource_manager = resource_manager_class(self.sock, self.resource_values) - for notitifaction in self.notifications: - resource_manager.handle_notification(notitifaction) + resource_manager.handle_notifications(self.notifications) return resource_manager @property |