Package pyffi :: Package object_models :: Module binary_type :: Class SizedString
[hide private]
[frames] | no frames]

Class SizedString

source code

            object --+                
                     |                
utils.graph.DetailNode --+            
                         |            
          any_type.AnyType --+        
                             |        
        simple_type.SimpleType --+    
                                 |    
            object --+           |    
                     |           |    
utils.graph.DetailNode --+       |    
                         |       |    
          any_type.AnyType --+   |    
                             |   |    
                    BinaryType --+    
                                 |    
                  BinarySimpleType --+
                                     |
                    object --+       |
                             |       |
         editable.EditableBase --+   |
                                 |   |
         editable.EditableLineEdit --+
                                     |
                                    SizedString

Basic type for strings. The type starts with an unsigned int which describes the length of the string.

>>> from tempfile import TemporaryFile
>>> f = TemporaryFile()
>>> s = SizedString()
>>> if f.write('\x07\x00\x00\x00abcdefg'.encode("ascii")): pass # ignore result for py3k
>>> if f.seek(0): pass # ignore result for py3k
>>> s.read(f)
>>> str(s)
'abcdefg'
>>> if f.seek(0): pass # ignore result for py3k
>>> s.set_value('Hi There')
>>> s.write(f)
>>> if f.seek(0): pass # ignore result for py3k
>>> m = SizedString()
>>> m.read(f)
>>> str(m)
'Hi There'
Nested Classes [hide private]

Inherited from simple_type.SimpleType: __metaclass__

Instance Methods [hide private]
 
__init__(self)
Initialize the string.
source code
Whatever is appropriate.
get_value(self)
Return the string.
source code
 
set_value(self, value)
Set string to C{value}.
source code
str
__str__(self)
String representation.
source code
 
get_size(self)
Return number of bytes this type occupies in a file.
source code
 
read(self, stream)
Read string from stream.
source code
 
write(self, stream)
Write string to stream.
source code

Inherited from simple_type.SimpleType: get_detail_display, is_interchangeable

Inherited from any_type.AnyType: __hash__

Inherited from utils.graph.DetailNode: get_detail_child_edge_types, get_detail_child_names, get_detail_child_nodes, get_detail_iterator, replace_global_node

Inherited from editable.EditableBase: get_editor_value, set_editor_value

Inherited from object: __delattr__, __format__, __getattribute__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Variables [hide private]

Inherited from simple_type.SimpleType (private): _value

Properties [hide private]
  value
A property which wraps the actual data.

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 
Initialize the string.
Overrides: object.__init__

get_value(self)

source code 
Return the string.
Returns: Whatever is appropriate.
The stored string.
Overrides: simple_type.SimpleType.get_value

set_value(self, value)

source code 
Set string to C{value}.
Parameters:
  • value (str) - The value to assign.
Overrides: simple_type.SimpleType.set_value

__str__(self)
(Informal representation operator)

source code 
String representation. This implementation is simply a wrapper around str on _value.
Returns: str
String representation.
Overrides: object.__str__
(inherited documentation)

get_size(self)

source code 
Return number of bytes this type occupies in a file.
Returns:
Number of bytes.
Overrides: BinaryType.get_size

read(self, stream)

source code 
Read string from stream.
Parameters:
  • stream (file) - The stream to read from.
Overrides: any_type.AnyType.read

write(self, stream)

source code 
Write string to stream.
Parameters:
  • stream (file) - The stream to write to.
Overrides: any_type.AnyType.write

Property Details [hide private]

value

A property which wraps the actual data. This property always calls set_value to assign the value, and ensures that the value is valid (type, range, ...). Unless you know what you are doing, always use the value property to change the data.
Get Method:
unreachable.get_value(self) - Return the string.
Set Method:
unreachable.set_value(self, value) - Set string to C{value}.