Package pyffi :: Package object_models :: Package xml :: Module basic :: Class BasicBase
[hide private]
[frames] | no frames]

Class BasicBase

source code

            object --+    
                     |    
utils.graph.DetailNode --+
                         |
                        BasicBase
Known Subclasses:

Base class from which all basic types are derived.

The BasicBase class implements the interface for basic types. All basic types are derived from this class. They must override read, write, get_value, and set_value.

>>> import struct
>>> class UInt(BasicBase):
...     def __init__(self, template = None, argument = 0):
...         self.__value = 0
...     def read(self, version = None, user_version = None, f = None,
...              link_stack = [], argument = None):
...         self.__value, = struct.unpack('<I', f.read(4))
...     def write(self, version = None, user_version = None, f = None,
...               block_index_dct = {}, argument = None):
...         f.write(struct.pack('<I', self.__value))
...     def get_value(self):
...         return self.__value
...     def set_value(self, value):
...         self.__value = int(value)
>>> x = UInt()
>>> x.set_value('123')
>>> x.get_value()
123
>>> class Test(BasicBase): # bad: read, write, get_value, and set_value are
...                        # not implemented
...     pass
>>> x = Test() # doctest: +ELLIPSIS
>>> x.set_value('123') # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
NotImplementedError
Instance Methods [hide private]
 
__init__(self, template=None, argument=None, parent=None)
Initializes the instance.
source code
 
__str__(self)
Return string representation.
source code
 
read(self, stream, data)
Read object from file.
source code
 
write(self, stream, data)
Write object to file.
source code
 
fix_links(self, data)
Fix links.
source code
 
get_links(self, data=None)
Return all links referred to in this object.
source code
 
get_strings(self, data)
Return all strings used by this object.
source code
 
get_refs(self, data=None)
Return all references (excluding weak pointers) used by this object.
source code
 
get_value(self)
Return object value.
source code
 
set_value(self, value)
Set object value.
source code
 
get_size(self, data=None)
Returns size of the object in bytes.
source code
 
get_hash(self, data=None)
Returns a hash value (an immutable object) that can be used to identify the object uniquely.
source code
 
replace_global_node(self, oldbranch, newbranch, **kwargs)
Replace a given branch.
source code
str
get_detail_display(self)
Return an object that can be used to display the instance.
source code
 
get_editor_value(self)
Return value suitable for editor.
source code
 
set_editor_value(self, editorvalue)
Set value from editor value.
source code

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

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

Class Variables [hide private]
  _is_template = False
  _has_links = False
  _has_refs = False
  _has_strings = False
  arg = None
hash(x)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, template=None, argument=None, parent=None)
(Constructor)

source code 
Initializes the instance.
Parameters:
  • template - type used as template
  • argument - argument used to initialize the instance (see the Struct class).
  • parent - The parent of this instance, that is, the instance this instance is an attribute of.
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 
Return string representation.
Overrides: object.__str__

fix_links(self, data)

source code 
Fix links. Called when all objects have been read, and converts block indices into blocks.

replace_global_node(self, oldbranch, newbranch, **kwargs)

source code 
Replace a given branch.
Overrides: utils.graph.DetailNode.replace_global_node

get_detail_display(self)

source code 
Return an object that can be used to display the instance.
Returns: str
A string that can be used to display the instance.
Overrides: utils.graph.DetailNode.get_detail_display