# HG changeset patch # User Ludovic Chabant # Date 1506564334 25200 # Node ID 9d804fa186a0cef1d8880b47857fa43c97c8053f # Parent f2b75e4be9810cc802aa763f003920b0ff463a65 data: Make the `Assetor` more into a `dict` than a `list`. diff -r f2b75e4be981 -r 9d804fa186a0 piecrust/data/assetor.py --- 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()