Commits

Anonymous committed 97288f4

Allow _fixFeedError and _stopFeeding to return iterables of fields.

Comments (0)

Files changed (1)

hachoir-core/hachoir_core/field/generic_field_set.py

         """
         if self._field_generator is None:
             return 0
-        added = 0
+        oldlen = len(self._fields)
         try:
             for index in xrange(number):
                 self._addField( self._field_generator.next() )
-                added += 1
         except HACHOIR_ERRORS, err:
             if self._fixFeedError(err) is False:
                 raise
-            added += 1
         except StopIteration:
-            if self._stopFeeding():
-                added += 1
-        return added
+            self._stopFeeding()
+        return len(self._fields) - oldlen
 
     def _feedAll(self):
         if self._field_generator is None:
                     done += 1
         except HACHOIR_ERRORS, err:
             field = self._fixFeedError(err)
-            if field:
+            if isinstance(field, Field):
                 yield field
+            elif hasattr(field, '__iter__'):
+                for f in field:
+                    yield f
             elif field is False:
                 raise
         except StopIteration:
             field = self._stopFeeding()
-            if field:
+            if isinstance(field, Field):
                 yield field
+            elif hasattr(field, '__iter__'):
+                for f in field:
+                    yield f
 
     def _isDone(self):
         return (self._field_generator is None)