Arena  1.0
A content management system
 All Classes Files Functions Variables Pages
Library.IO.Streams.AStream Class Reference

This class defines the methods common to all stream objects used by arena. More...

+ Inheritance diagram for Library.IO.Streams.AStream:

Public Member Functions

def __init__
 Construct a new stream instance. More...
 
def init
 Initialize the stream instance. More...
 
def readFormat
 Read one or more values from the stream. More...
 
def writeFormat
 Write one or more values to the stream. More...
 
def read
 Read one or more values from the stream. More...
 
def write
 Write the specified values to the stream. More...
 
def writeString
 Write a string to the stream, including a length specifier. More...
 
def readString
 Read a string from the stream. More...
 
def rewindBy
 Rewind the stream by the specified number of bytes.
 
def position
 Return the current position within the stream. More...
 
def moveTo
 Set the current position within the stream. More...
 
def length
 Get the current length of the stream, in bytes. More...
 
def __len__
 Get the current length of the stream, in bytes. More...
 
def hasEnded
 Determine whether or not the end of the stream has been reached. More...
 
- Public Member Functions inherited from Library.Base.Classwork.AnObject
def init
 Initialize a new object instance. More...
 
def __init__
 Construct and initialize a new instance of AnObject. More...
 
def __del__
 Destroy the object instance. More...
 
def displayName
 Construct a "pretty" display name for the class instance, based on the name of its class. More...
 
def implements
 Determine whether the class instance is related to the specified class. More...
 
def toString
 Return a string representation of the class, suitable for output to a console or text-based device. More...
 
def __str__
 Return a string representation of the class. More...
 
def classname
 Return the name of the class from which the instance was created. More...
 
def name
 Return the name of the class. More...
 

Detailed Description

This class defines the methods common to all stream objects used by arena.

Constructor & Destructor Documentation

def Library.IO.Streams.AStream.__init__ (   Self)

Construct a new stream instance.

Member Function Documentation

def Library.IO.Streams.AStream.__len__ (   Self)

Get the current length of the stream, in bytes.

This routine allows len() to be used on instances of AStream and its descendants. It simply returns the value of a call to AStream.length().

def Library.IO.Streams.AStream.hasEnded (   Self)

Determine whether or not the end of the stream has been reached.

In the base implementation of AStream, this routine simply checks to see whether AStream.position >= AStream.length. If so, it returns True; otherwise it returns False. Descendant classes should override this method where a better test is available.

def Library.IO.Streams.AStream.init (   Self)

Initialize the stream instance.

def Library.IO.Streams.AStream.length (   Self)

Get the current length of the stream, in bytes.

This routine is called whenever a program attempts to access the AStream.length attribute, either directly or by a call to len(). In the default implementation of AStream, it always returns zero (0). Descendant classes should override this method to produce more meaningful output.

def Library.IO.Streams.AStream.moveTo (   Self,
  newPosition 
)

Set the current position within the stream.

This routine is called whenever a program attempts to modify the AStream.position attribute. In the default implementation of AStream, it does nothing. Descendant classes should override this method.

The position within a stream is measured as the number of bytes from the beginning of the stream. The beginning of the stream is always located at position zero (0). If newPosition specifies a value that is less than zero, it is assumed to indicate an offset relative to the end of the stream (i.e., AStream.length + newPosition + 1). The end of the stream is always located at position -1.

def Library.IO.Streams.AStream.position (   Self)

Return the current position within the stream.

This routine is called whenever a program attempts to access the AStream.position attribute. In the default implementation of AStream, it always returns zero (0). Descendant classes should override this method to produce more relevant output.

The position within a stream is measured as the number of bytes from the beginning of the stream. The beginning of the stream is always located at position zero (0).

def Library.IO.Streams.AStream.read (   Self,
  values 
)

Read one or more values from the stream.

This method is provided for convenience, so that values may be read from a stream without the need to specify a format string for struct.unpack().

This method constructs the necessary format string by testing the type of each item in values. Boolean values are assumed to be stored as such within the stream; anything of type int() or long() is assumed to be stored as a signed 64-bit integer value; anything of type float() is assumed to be stored as a 64-bit floating-point value; all other values are assumed to be stored as strings of varying length. Once the format string has been constructed, this method calls AStream.readFormat().

This method complements AStream.write().

def Library.IO.Streams.AStream.readFormat (   Self,
  fmt,
  values 
)

Read one or more values from the stream.

The values are unpacked from the stream used by the specified format, which must match the specifications required by struct.unpack(). Each value read from the stream is assigned to a dictionary entry that has as its key the next unassigned name specified by values.

This method should be overridden by descendant classes, which will perform the work of reading and unpacking the values. In the base implementation, the method does nothing and returns a dictionary with a single entry: {"result": 0}.

Returns
Descendant classes should override this method to perform the act of reading from the stream and to return the values named. A dictionary object should be returned that has, as its keys, the names of the values passed to the function in values and one additional item with a key of "result" that indicates how much information was actually read from the stream (i.e., how many bytes were read).
def Library.IO.Streams.AStream.readString (   Self)

Read a string from the stream.

This routine reads the length specifier for the string and then the string value from the stream. It can be used to recall a string that was previously written by AStream.writeString().

Returns
The return value of this routine is a tuple: the first item indicates how many bytes were read from the stream; the second item is the string itself.
def Library.IO.Streams.AStream.write (   Self,
  values 
)

Write the specified values to the stream.

This routine is provided for convenience, so that it need not be necessary to construct a format string in order to write to the stream.

The routine constructs a format string by testing the type of each item in values: boolean values will be stored as such in the stream; anything of type int() or long() will be stored as a 64-bit signed integer value; items of type float() will be stored as 64-bit floating-point values; all other values will be stored as strings of varying length. Once the format string has been constructed, this method calls AStream.writeFormat().

This method complements AStream.read().

def Library.IO.Streams.AStream.writeFormat (   Self,
  fmt,
  values 
)

Write one or more values to the stream.

The values are packed into the stream using the specified format, which must match the specifications required by struct.pack(). Alternatively, values may be omitted, in which case the routine assumes that fmt represents a string (perhaps one already packed) that is to be written to the stream.

Descendant classes should override this method to perform the act of packing the values and writing them to the stream. The base implementation of this method does nothing and returns zero (0).

Returns
The return value of this method should indicate how much information was actually written to the stream (i.e., how many bytes were written).
def Library.IO.Streams.AStream.writeString (   Self,
  thisString 
)

Write a string to the stream, including a length specifier.

Strings written by this routine can be recalled from the stream by a call to AStream.readString().

Returns
The return value of this routine indicates how many bytes were written to the stream.

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