Back to index

enigmail  1.4.3
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
xpt.SimpleType Class Reference
Inheritance diagram for xpt.SimpleType:
Inheritance graph
[legend]
Collaboration diagram for xpt.SimpleType:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __str__
def encodeflags
def write

Static Public Member Functions

def get
def decodeflags
def read

Public Attributes

 tag
 pointer
 reference

Static Public Attributes

tuple Tags

Static Private Attributes

dictionary _cache = {}

Detailed Description

A simple data type. (SimpleTypeDescriptor from the typelib specification.)

Definition at line 218 of file xpt.py.


Constructor & Destructor Documentation

def xpt.SimpleType.__init__ (   self,
  tag,
  kwargs 
)

Reimplemented from xpt.Type.

Definition at line 225 of file xpt.py.

00225 
00226     def __init__(self, tag, **kwargs):
00227         Type.__init__(self, **kwargs)
00228         self.tag = tag


Member Function Documentation

def xpt.SimpleType.__str__ (   self)

Definition at line 241 of file xpt.py.

00241 
00242     def __str__(self):
00243         s = "unknown"
00244         if self.tag == Type.Tags.char_ptr and self.pointer:
00245             return "string"
00246         if self.tag == Type.Tags.wchar_t_ptr and self.pointer:
00247             return "wstring"
00248         for t in dir(Type.Tags):
00249             if self.tag == getattr(Type.Tags, t):
00250                 s = t
00251                 break
00252 
00253         if self.pointer:
00254             if self.reference:
00255                 s += " &"
00256             else:
00257                 s += " *"
00258         return s

def xpt.Type.decodeflags (   byte) [static, inherited]
Given |byte|, an unsigned uint8 containing flag bits,
decode the flag bits as described in
http://www.mozilla.org/scriptable/typelib_file.html#TypeDescriptor
and return a dict of flagname: (True|False) suitable
for passing to Type.__init__ as **kwargs.

Definition at line 151 of file xpt.py.

00151 
00152     def decodeflags(byte):
00153         """
00154         Given |byte|, an unsigned uint8 containing flag bits,
00155         decode the flag bits as described in
00156         http://www.mozilla.org/scriptable/typelib_file.html#TypeDescriptor
00157         and return a dict of flagname: (True|False) suitable
00158         for passing to Type.__init__ as **kwargs.
00159         
00160         """
00161         return {'pointer': bool(byte & 0x80),
00162                 'reference': bool(byte & 0x20),
00163                 }

def xpt.Type.encodeflags (   self) [inherited]
Encode the flag bits of this Type object. Returns a byte.

Definition at line 164 of file xpt.py.

00164 
00165     def encodeflags(self):
00166         """
00167         Encode the flag bits of this Type object. Returns a byte.
00168 
00169         """
00170         flags = 0
00171         if self.pointer:
00172             flags |= 0x80
00173         if self.reference:
00174             flags |= 0x20
00175         return flags

Here is the caller graph for this function:

def xpt.SimpleType.get (   data,
  tag,
  flags 
) [static]
Get a SimpleType object representing |data| (a TypeDescriptorPrefix).
May return an already-created object. If no cached object is found,
construct one with |tag| and |flags|.

Definition at line 230 of file xpt.py.

00230 
00231     def get(data, tag, flags):
00232         """
00233         Get a SimpleType object representing |data| (a TypeDescriptorPrefix).
00234         May return an already-created object. If no cached object is found,
00235         construct one with |tag| and |flags|.
00236         
00237         """
00238         if data not in SimpleType._cache:
00239             SimpleType._cache[data] = SimpleType(tag, **flags)
00240         return SimpleType._cache[data]

def xpt.Type.read (   typelib,
  map,
  data_pool,
  offset 
) [static, inherited]
Read a TypeDescriptor at |offset| from the mmaped file |map| with
data pool offset |data_pool|. Returns (Type, next offset),
where |next offset| is an offset suitable for reading the data
following this TypeDescriptor.

Definition at line 177 of file xpt.py.

00177 
00178     def read(typelib, map, data_pool, offset):
00179         """
00180         Read a TypeDescriptor at |offset| from the mmaped file |map| with
00181         data pool offset |data_pool|. Returns (Type, next offset),
00182         where |next offset| is an offset suitable for reading the data
00183         following this TypeDescriptor.
00184         
00185         """
00186         start = data_pool + offset - 1
00187         (data,) = Type._prefixdescriptor.unpack(map[start:start + Type._prefixdescriptor.size])
00188         # first three bits are the flags
00189         flags = data & 0xE0
00190         flags = Type.decodeflags(flags)
00191         # last five bits is the tag
00192         tag = data & 0x1F
00193         offset += Type._prefixdescriptor.size
00194         t = None
00195         if tag <= Type.Tags.wchar_t_ptr or tag >= Type.Tags.UTF8String:
00196             t = SimpleType.get(data, tag, flags)
00197         elif tag == Type.Tags.Interface:
00198             t, offset = InterfaceType.read(typelib, map, data_pool, offset, flags)
00199         elif tag == Type.Tags.InterfaceIs:
00200             t, offset = InterfaceIsType.read(typelib, map, data_pool, offset, flags)
00201         elif tag == Type.Tags.Array:
00202             t, offset = ArrayType.read(typelib, map, data_pool, offset, flags)
00203         elif tag == Type.Tags.StringWithSize:
00204             t, offset = StringWithSizeType.read(typelib, map, data_pool, offset, flags)
00205         elif tag == Type.Tags.WideStringWithSize:
00206             t, offset = WideStringWithSizeType.read(typelib, map, data_pool, offset, flags)
00207         return t, offset

def xpt.Type.write (   self,
  typelib,
  file 
) [inherited]
Write a TypeDescriptor to |file|, which is assumed
to be seeked to the proper position. For types other than
SimpleType, this is not sufficient for writing the TypeDescriptor,
and the subclass method must be called.

Reimplemented in xpt.WideStringWithSizeType, xpt.StringWithSizeType, xpt.ArrayType, xpt.InterfaceIsType, and xpt.InterfaceType.

Definition at line 208 of file xpt.py.

00208 
00209     def write(self, typelib, file):
00210         """
00211         Write a TypeDescriptor to |file|, which is assumed
00212         to be seeked to the proper position. For types other than
00213         SimpleType, this is not sufficient for writing the TypeDescriptor,
00214         and the subclass method must be called.
00215 
00216         """
00217         file.write(Type._prefixdescriptor.pack(self.encodeflags() | self.tag))

Here is the call graph for this function:


Member Data Documentation

dictionary xpt.SimpleType._cache = {} [static, private]

Definition at line 223 of file xpt.py.

xpt.Type.pointer [inherited]

Definition at line 145 of file xpt.py.

xpt.Type.reference [inherited]

Definition at line 146 of file xpt.py.

Definition at line 227 of file xpt.py.

tuple xpt.Type.Tags [static, inherited]

Definition at line 105 of file xpt.py.


The documentation for this class was generated from the following file: