Пример #1
0
 def setValue(self, value):
     # Do some minimal checking if possible.
     if self.isFixedWidth():
         if self.type != 'string':
             if len(value) != self.width_in_bytes:
                 mstr = "Got wrong size for data (got len of %d rather than %d)" % (len(value),
                                                                                    self.width_in_bytes)
                 raise gdutil.GDException(mstr)
         else:
             if len(value) >= self.width_in_bytes:
                 mstr  = "Got wrong size for data (got string length of %d for " % len(value)
                 mstr += "a string buffer of length %d (-1 for NULL)." % self.width_in_bytes
                 raise gdutil.GDException(mstr)
     #
     self.value = value
Пример #2
0
 def dumpStr(self):
     # If this item is not pack compatible then we have no idea
     # how to dump it.
     if not self.isPackCompatible():
         raise gdutil.GDException("Could not dumpStr because item is not pack compatible.")
     val = None
     if self.value is None:
         if self.initial_value is None:
             raise gdutil.GDException("Could not dumpStr because value was not set")
         else:
             val = self.initial_value
     else:
         val = self.value
     cstr = struct.pack(self.packSpec(), val)
     return cstr
Пример #3
0
 def test_gdexception(self):
     t = gu.GDException("testexception")
     try:
         raise t
     except Exception, e:
         estr = str(e)
         assert estr == "testexception", "Did not get expected string representation of exception"
Пример #4
0
 def _isEnoughData(self, data, offset):
     if self.isFixedWidth():
         width = self.getWidth()
         lendata = len(data) - offset
         if lendata >= width:
             return width
         else:
             return 0
     else:
         # Not fixed width.  For now, behavior is undefined, but possibly
         # we could check each child in turn to see if there is enough data
         # for them.
         raise gdutil.GDException("Option not implemented")
Пример #5
0
 def dumpStr(self):
     if self.child_obj:
         val = self.child_obj.dumpStr()
     else:
         if self.value is None:
             if self.initial_value is None:
                 raise gdutil.GDException("Could not dumpStr because value was not set")
             else:
                 val = self.initial_value
         else:
             val = self.value
     if self.isFixedWidth():
         if self.type == 'string':
             # Make sure string is NULL-terminated and pad returned string
             # out to required length.
             val = val + '\00' * (self.width_in_bytes - len(val))
         return val
     else:
         self.computed_width = len(val)
         width_str = struct.pack(self.getWidthPackSpec(), self.computed_width)
         return width_str + val
Пример #6
0
 def _disconnect(self):
     raise gdutil.GDException("Error - _disconnect must be implemented by subclass.")
Пример #7
0
 def _connect(self, numretries):
     raise gdutil.GDException("Error - _connect must be implemented by subclass.")
Пример #8
0
 def setValue(self, value):
     raise gdutil.GDException("setValue() not supported for PadItem")
Пример #9
0
 def setValue(self, item_name, item_value):
     for x in self.items:
         if x.name == item_name:
             x.setValue(item_value)
             return
     raise gdutil.GDException("Item with name %s not found." % item_name)
Пример #10
0
 def getValue(self, data, offset):
     # @fixme: This method turned out not to be really relevant, consider removing.
     raise gdutil.GDException("Option not implemented")