styles.py: new Stylesheet1 methods suggested by Roberto Alsina <ralsina@netmanagers.com.ar>
authorrgbecker
Tue, 07 Sep 2010 10:35:23 +0000
changeset 3433 0562ca2f5155
parent 3432 04c84c2ef968
child 3434 3c14212cc997
styles.py: new Stylesheet1 methods suggested by Roberto Alsina <ralsina@netmanagers.com.ar>
src/reportlab/lib/styles.py
--- a/src/reportlab/lib/styles.py	Mon Sep 06 16:44:08 2010 +0000
+++ b/src/reportlab/lib/styles.py	Tue Sep 07 10:35:23 2010 +0000
@@ -122,6 +122,8 @@
         canvas.setLineWidth(1)
         #etc. etc.
 
+_stylesheet1_undefined = object()
+
 class StyleSheet1:
     """
     This may or may not be used.  The idea is to:
@@ -143,6 +145,7 @@
     Access is via getitem, so they can be
     compatible with plain old dictionaries.
     """
+
     def __init__(self):
         self.byName = {}
         self.byAlias = {}
@@ -156,9 +159,19 @@
             except KeyError:
                 raise KeyError("Style '%s' not found in stylesheet" % key)
 
+    def get(self,key,default=_stylesheet1_undefined):
+        try:
+            return self[key]
+        except KeyError:
+            if default!=_stylesheet1_undefined: return default
+            raise
+
     def __contains__(self, key):
         return key in self.byAlias or key in self.byName
 
+    def has_key(self,key):
+        return key in self
+
     def add(self, style, alias=None):
         key = style.name
         if key in self.byName: