[kupfer] icons: Simplify get_/set_icon



commit f02ae13e48e0336debc79cef2ef36457333d5bd8
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Sep 27 12:16:53 2009 +0200

    icons: Simplify get_/set_icon

 kupfer/icons.py |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/kupfer/icons.py b/kupfer/icons.py
index 7f368ce..546bc3c 100644
--- a/kupfer/icons.py
+++ b/kupfer/icons.py
@@ -47,8 +47,9 @@ def get_icon(key, icon_size):
 	try retrieve icon in cache
 	is a generator so it can be concisely called with a for loop
 	"""
-	rec = icon_cache.get(icon_size, {}).get(key, None)
-	if not rec:
+	try:
+		rec = icon_cache[icon_size][key]
+	except KeyError:
 		return
 	rec["accesses"] += 1
 	yield rec["icon"]
@@ -61,8 +62,7 @@ def store_icon(key, icon_size, icon):
 		"icon %s already in cache" % key
 	assert icon, "icon %s may not be %s" % (key, icon)
 	icon_rec = {"icon":icon, "accesses":0}
-	if icon_size not in icon_cache: icon_cache[icon_size] = {}
-	icon_cache[icon_size][key] = icon_rec
+	icon_cache.setdefault(icon_size, {})[key] = icon_rec
 
 def _get_icon_dwim(icon, icon_size):
 	"""Make an icon at @icon_size where



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]