sebastien - in flumotion/branches/transcoder-1: . flumotion/common

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Fri Mar 30 11:54:06 CEST 2007


Author: sebastien
Date: Fri Mar 30 11:54:04 2007
New Revision: 4694

Modified:
   flumotion/branches/transcoder-1/ChangeLog
   flumotion/branches/transcoder-1/flumotion/common/enum.py
Log:
2007-03-30  Sebastien Merle  <sebastien at fluendo.com>

	* flumotion/common/enum.py: 
	Modified the Enum jellying for the enum to be unjellyed
	even without knowing the custom enum class.
	It allow a peer to proxy an enum value without having to 
	know about the enum custom class.
	In practice it allow a componenet to declar custom enums,
	and an admin/ui to use it without the manager knowing about it.


Modified: flumotion/branches/transcoder-1/ChangeLog
==============================================================================
--- flumotion/branches/transcoder-1/ChangeLog	(original)
+++ flumotion/branches/transcoder-1/ChangeLog	Fri Mar 30 11:54:04 2007
@@ -1,3 +1,13 @@
+2007-03-30  Sebastien Merle  <sebastien at fluendo.com>
+
+	* flumotion/common/enum.py: 
+	Modified the Enum jellying for the enum to be unjellyed
+	even without knowing the custom enum class.
+	It allow a peer to proxy an enum value without having to 
+	know about the enum custom class.
+	In practice it allow a componenet to declar custom enums,
+	and an admin/ui to use it without the manager knowing about it.
+
 2007-03-29  Sebastien Merle  <sebastien at fluendo.com>
 
 	* flumotion/test/test_enum.py: 

Modified: flumotion/branches/transcoder-1/flumotion/common/enum.py
==============================================================================
--- flumotion/branches/transcoder-1/flumotion/common/enum.py	(original)
+++ flumotion/branches/transcoder-1/flumotion/common/enum.py	Fri Mar 30 11:54:04 2007
@@ -26,6 +26,7 @@
 from twisted.python.reflect import qual
 from twisted.spread import jelly
 
+_enumClassRegistry = {}
 
 class EnumMetaClass(type):
     # pychecker likes this attribute to be there since we use it in this class
@@ -55,6 +56,7 @@
             nick = name
             
         self.nick = nick
+        self._enumClassName = self.__class__.__name__
 
     def __repr__(self):
         return '<enum %s of type %s>' % (self.name,
@@ -68,12 +70,26 @@
         klass[value] = item
     set = classmethod(set)
     
-    def getStateFor(self, jellier):
-        return self.value
+    def jellyFor(self, jellier):
+        sxp = jellier.prepare(self)
+        sxp.extend([
+            qual(Enum),
+            self._enumClassName,
+            self.value, self.name, self.nick])
+        return jellier.preserve(self, sxp)
 
     def unjellyFor(self, unjellier, jellyList):
-        value = unjellier.unjelly(jellyList[1])
-        return self.get(value)
+        enumClassName, value, name, nick = jellyList[1:]
+        enumClass = _enumClassRegistry.get(enumClassName, None)
+        if enumClass:
+            enum = enumClass.get(value)
+            assert enum.name == name, "Inconsistent Enum Name"
+            return enum
+        self._enumClassName = enumClassName
+        self.value = value
+        self.name = name
+        self.nick = nick
+        return self
 
 
 class EnumClass(object):
@@ -102,8 +118,7 @@
                 setattr(enum, extra_key, extra_values[value])
             etype[value] = enum
         
-        if len(etype) > 0:
-            enumClassName = qual(etype.get(0).__class__)
-            jelly.setUnjellyableForClass(enumClassName, etype)
+        _enumClassRegistry[type_name] = etype
         return etype
 
+jelly.setUnjellyableForClass(qual(Enum), Enum)


More information about the flumotion-commit mailing list