aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-14 23:54:28 +0200
committerMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-14 23:54:28 +0200
commit46123a0a78149a8832e9201f33de3a8dfa520c4b (patch)
tree6e3cc9d8f595b28e45a68509b56ebfa138d26f2e
parentebb7d4799f00c6ebb2cb1f53dcce4e1b1cc884f3 (diff)
downloadpyParrotZikTCP-46123a0a78149a8832e9201f33de3a8dfa520c4b.tar.xz
pyParrotZikTCP-46123a0a78149a8832e9201f33de3a8dfa520c4b.zip
Perform one fetch per notification path.
-rw-r--r--resource_manager.py14
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