Beispiel #1
0
 def _before_unpack(self, opts):
     CField._before_unpack(self, opts)
     try:
         opts['length'] = opts['data'].index('\0', opts['offset']) - opts['offset'] + 1
         if opts.has_key('max_length'):
             opts['length'] = min(opts['max_length'], opts['length'])
     except ValueError:
         raise UnpackException("Unterminated null string occured.")
Beispiel #2
0
 def set_value(self, obj, value):
     if not isinstance(value, str) or value[-1] != '\0':
         raise ValueError("NullStringField value must a string with last character == '\\0'.")
     
     return CField.set_value(self, obj, value)
Beispiel #3
0
 def _retrieve_value(self, opts):
     (v, offset) = CField._retrieve_value(self, opts)
     return (v[0], offset)
Beispiel #4
0
 def pack(self, obj, offset, **opts):
     value = getattr(obj, self.name)
     return CField.pack(self, obj, offset, length=len(value), **opts)
Beispiel #5
0
 def __init__(self, idx, default='', length=0, **kwargs):
     CField.__init__(self, idx, default, **dict(kwargs, length=length) )
Beispiel #6
0
 def set_value(self, obj, value):
     wrapper = ListItemWrapper(value)
     wrapper._set_action = self.item_set_value
     wrapper._get_action = self.item_get_value
     return CField.set_value(self, obj, wrapper)
Beispiel #7
0
 def __init__(self, idx, subfield, default=[], length=0, **kwargs):
     CField.__init__(self, idx, default, **dict(kwargs, length=length) )
     self.__subfield = subfield
Beispiel #8
0
 def __init__(self, idx, struct, default=None, **kwargs):
     CField.__init__(self, idx, default, **kwargs)
     self._struct_klass = struct