changeset 915:9d804fa186a0

data: Make the `Assetor` more into a `dict` than a `list`.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 27 Sep 2017 19:05:34 -0700
parents f2b75e4be981
children 84ce51430346
files piecrust/data/assetor.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/data/assetor.py	Sun Jul 23 18:03:21 2017 -0700
+++ b/piecrust/data/assetor.py	Wed Sep 27 19:05:34 2017 -0700
@@ -1,7 +1,6 @@
 import os
 import os.path
 import logging
-import collections.abc
 from piecrust.sources.base import REL_ASSETS
 from piecrust.uriutil import multi_replace
 
@@ -19,7 +18,7 @@
         self.uri = uri
 
 
-class Assetor(collections.abc.Sequence):
+class Assetor:
     debug_render_doc = """Helps render URLs to files in the current page's
                           asset folder."""
     debug_render = []
@@ -37,13 +36,21 @@
         except KeyError:
             raise AttributeError()
 
-    def __getitem__(self, i):
+    def __getitem__(self, name):
+        self._cacheAssets()
+        return self._cache_map[name].uri
+
+    def __contains__(self, name):
         self._cacheAssets()
-        return self._cache_list[i]
+        return name in self._cache_map
+
+    def __iter__(self):
+        self._cacheAssets()
+        return iter(self._cache_list)
 
     def __len__(self):
         self._cacheAssets()
-        return len(self._cache_list)
+        return len(self._cache_map)
 
     def _getAssetNames(self):
         self._cacheAssets()