[Synopsis-changes] Synopsis/Synopsis/Synopsis Processor.py,1.2,1.3

Stefan Seefeld stefan at synopsis.fresco.org
Tue Nov 11 18:17:55 UTC 2003


Update of /cvs/synopsis/Synopsis/Synopsis
In directory frida:/tmp/cvs-serv28670/Synopsis

Modified Files:
	Processor.py 
Log Message:
factor out Parametrized so it can be used for things other than Processors

Index: Processor.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/Synopsis/Processor.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -p -d -r1.2 -r1.3
--- Processor.py	11 Nov 2003 06:05:03 -0000	1.2
+++ Processor.py	11 Nov 2003 18:17:17 -0000	1.3
@@ -28,8 +28,8 @@ class Type(type):
          setattr(cls, i, dict[i].value)
       setattr(cls, '_parameters', parameters)
 
-class Processor(object):
-   """Processor documentation..."""
+class Parametrized(object):
+   """Parametrized implements handling of Parameter attributes."""
 
    __metaclass__ = Type
    
@@ -37,9 +37,9 @@ class Processor(object):
       """merge all parameter catalogs for easy access to documentation,
       then use keyword arguments to override default values."""
       instance = object.__new__(cls)
-      # iterate over all base classes, starting at the 'Processor' base class
+      # iterate over all base classes, starting at the 'Parametrized' base class
       # i.e. remove mixin classes
-      hierarchy = list(filter(lambda i:isinstance(i, Processor), cls.__mro__))
+      hierarchy = list(filter(lambda i:isinstance(i, Parametrized), cls.__mro__))
       hierarchy.reverse()
       parameters = {}
       for c in hierarchy:
@@ -54,13 +54,27 @@ class Processor(object):
 
       return instance
 
-   verbose = Parameter(False, "operate verbosely")
-
    def get_parameters(self):
       return self._parameters
 
    def set_parameters(self, kwds):
       """Sets the given parameters to override the default values."""
+      for i in kwds:
+         if i in self._parameters:
+            setattr(self, i, kwds[i])
+         else:
+            raise TypeError, "No parameter '%s' in 'Parametrized'"%(i)
+
+
+class Processor(Parametrized):
+   """Processor documentation..."""
+
+   verbose = Parameter(False, "operate verbosely")
+
+   def set_parameters(self, kwds):
+      """Sets the given parameters to override the default values.
+      Override the Parametrized version so we can handle 'input' and 'output'
+      which are not in the _parameters' catalog."""
       for i in kwds:
          if i in self._parameters:
             setattr(self, i, kwds[i])





More information about the Synopsis-changes mailing list