commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8974 - trunk/gnue-common/src/definitions


From: jcater
Subject: [gnue] r8974 - trunk/gnue-common/src/definitions
Date: Fri, 3 Nov 2006 18:17:04 -0600 (CST)

Author: jcater
Date: 2006-11-03 18:17:03 -0600 (Fri, 03 Nov 2006)
New Revision: 8974

Modified:
   trunk/gnue-common/src/definitions/GObjects.py
   trunk/gnue-common/src/definitions/GParser.py
   trunk/gnue-common/src/definitions/GParserHelpers.py
Log:
removed redundant dict lookups in Parser (instead of refering to attrs[foo] 12 
times, do attr_foo=attrs[foo]); instead of having GParser do an 
object.__dict__.update() for attributes, call a subclassable ParserObj method 
to do it (needed by designer)

Modified: trunk/gnue-common/src/definitions/GObjects.py
===================================================================
--- trunk/gnue-common/src/definitions/GObjects.py       2006-11-02 05:50:01 UTC 
(rev 8973)
+++ trunk/gnue-common/src/definitions/GObjects.py       2006-11-04 00:17:03 UTC 
(rev 8974)
@@ -125,7 +125,7 @@
   # ---------------------------------------------------------------------------
   # phaseInit
   # ---------------------------------------------------------------------------
-  
+
   def phaseInit (self, iterations = 0):
     """
     Starts GNUe's phased initialization system from this object down.
@@ -189,7 +189,7 @@
     if hasattr (object, '_inits'):
       self._initCount = max (self._initCount, len (object._inits))
 
-  
+
   # ---------------------------------------------------------------------------
   # Show the XML tree of an object
   # ---------------------------------------------------------------------------

Modified: trunk/gnue-common/src/definitions/GParser.py
===================================================================
--- trunk/gnue-common/src/definitions/GParser.py        2006-11-02 05:50:01 UTC 
(rev 8973)
+++ trunk/gnue-common/src/definitions/GParser.py        2006-11-04 00:17:03 UTC 
(rev 8974)
@@ -400,7 +400,7 @@
 
       xmlns = {}
 
-      for qattr in attrs.keys ():
+      for qattr, qattr_data in attrs.items():
         attrns, attr = qattr
 
         if attrns:
@@ -408,17 +408,17 @@
             tmsg = u_("Unexpected namespace on attribute")
             raise MarkupError, (tmsg, self.url, self.parser.getLineNumber ())
           prefix = attrns.split (':') [-1]
-          lattrs [prefix + '__' + attr] = attrs [qattr]
-          xmlns [prefix] = attrns
+          lattrs[prefix + '__' + attr] = qattr_data
+          xmlns[prefix] = attrns
 
-          loadedxmlattrs [attr] = attrs [qattr]
+          loadedxmlattrs [attr] = qattr_data
 
         else:
           # Typecasting, anyone?  If attribute should be int, make it an int
           try:
-            typecast      = baseAttrs [attr].get ('Typecast', GTypecast.text)
-            lattrs [attr] = typecast (attrs [qattr])
-            loadedxmlattrs [attr] = lattrs [attr]
+            typecast = baseAttrs[attr].get('Typecast', GTypecast.text)
+            lattrs[attr] = attrvalue = typecast(qattr_data)
+            loadedxmlattrs[attr] = attrvalue
 
           except KeyError:
             raise MarkupError, \
@@ -427,33 +427,46 @@
                  % {'tagname': tname, 'attribute': attr},
                  self.url, self.parser.getLineNumber ())
 
+
+          valueset = baseAttrs[attr].get('ValueSet', {})
+          if valueset and not valueset.has_key(attrvalue):
+            # FIXME: This should raise an exception. Only issue a warning
+            # for now to stay compatible with earlier versions that didn't
+            # check this at all.
+            assert gDebug(1,
+                    "DEPRECATION WARNING: %s not a valid value for %s.%s" \
+                            % (attrvalue, tname, attr))
+            #raise InvalidValueSetError (item, object,
+            #        data ['ValueSet'].keys ())
+
+
           # If this attribute must be unique, check for duplicates
-          if baseAttrs [attr].get ('Unique', False):
-            if self.uniqueIDs.has_key ('%s' % (attrs [qattr])):
+          if baseAttrs[attr].get ('Unique', False):
+            if self.uniqueIDs.has_key ('%s' % (qattr_data)):
               tmsg = u_('Error processing <%(tag)s> tag ["%(attribute)s" '
                         'attribute should be unique; duplicate value is '
                         '"%(duplicate)s"]') \
                      % {'tag'      : tname,
                         'attribute': attr,
-                        'duplicate': attrs [qattr]}
+                        'duplicate': attrvalue}
               raise MarkupError, (tmsg, self.url, self.parser.getLineNumber ())
 
             # If we would really want to ensure uniqueness, we'd like to
             # uncomment the following lines. But as this seems to break forms
             # keep it (for now)
-            # self.uniqueIDs ["%s" % attrs [qattr]] = True
+            # self.uniqueIDs ["%s" % qattr_data] = True
 
 
-      for attr in baseAttrs:
+      for attr, attrdata in baseAttrs.items():
         try:
           if not attr in lattrs:
             # Pull default values for missing attributes
-            if 'Default' in baseAttrs [attr]:
-              typecast      = baseAttrs [attr].get ('Typecast', GTypecast.text)
-              lattrs [attr] = typecast (baseAttrs [attr]['Default'])
+            if baseAttrs[attr].get('Default', None) is not None:
+              typecast = attrdata.get ('Typecast', GTypecast.text)
+              lattrs[attr] = value = typecast (attrdata['Default'])
 
             # Check for missing required attributes
-            elif baseAttrs [attr].get ('Required', False):
+            elif attrdata.get('Required', False):
               tm = u_('Error processing <%(tagname)s> tag [required attribute '
                       '"%(attribute)s" not present]') \
                    % {'tagname': tname, 'attribute': attr}
@@ -468,7 +481,7 @@
       lattrs ['_xmlnamespaces'] = xmlns
 
       if self.bootstrapflag:
-        if self.xmlStack [0] is not None:
+        if self.xmlStack[0] is not None:
           object = elementDefinition ['BaseClass'] (self.xmlStack [0])
       else:
         object = elementDefinition ['BaseClass'] ()
@@ -534,20 +547,8 @@
     object._url        = self.url
 
     # Set the attributes
-    object.__dict__.update (lattrs)
+    object._set_initial_attributes_(lattrs)
 
-    for (item, data) in baseAttrs.items ():
-        if 'ValueSet' in data:
-            if not getattr (object, item) in data ['ValueSet']:
-                # FIXME: This should raise an exception. Only issue a warning
-                # for now to stay compatible with earlier versions that didn't
-                # check this at all.
-                assert gDebug(1,
-                        "DEPRECATION WARNING: %s not a valid value for %s" \
-                                % (getattr(object, item), item))
-                # raise InvalidValueSetError (item, object,
-                #         data ['ValueSet'].keys ())
-
     self.xmlStack.insert (0, object)
     self.nameStack.insert (0, tname)
 

Modified: trunk/gnue-common/src/definitions/GParserHelpers.py
===================================================================
--- trunk/gnue-common/src/definitions/GParserHelpers.py 2006-11-02 05:50:01 UTC 
(rev 8973)
+++ trunk/gnue-common/src/definitions/GParserHelpers.py 2006-11-04 00:17:03 UTC 
(rev 8974)
@@ -551,6 +551,15 @@
     return ""
 
 
+  def _set_initial_attributes_(self, attributes):
+      """
+      Set attributes loaded by GParser.
+
+      @param attributes: dictionary of attributes
+      """
+      self.__dict__.update(attributes)
+
+
 # =============================================================================
 # Mixin-class for leaf node objects
 # =============================================================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]