Package pyamf :: Module amf0
[hide private]
[frames] | no frames]

Module amf0

source code

AMF0 implementation.

AMF0 supports the basic data types used for the NetConnection, NetStream, LocalConnection, SharedObjects and other classes in the Adobe Flash Player.


See Also:
Official AMF0 Specification in English (external), Official AMF0 Specification in Japanese (external), AMF documentation on OSFlash (external)

Since: 0.1

Classes [hide private]
  Context
I hold the AMF0 context for en/decoding streams.
  Decoder
Decodes an AMF0 stream.
  Encoder
Encodes an AMF0 stream.
  RecordSet
I represent the RecordSet class used in Adobe Flash Remoting to hold (amongst other things) SQL records.
Functions [hide private]
 
decode(*args, **kwargs)
A helper function to decode an AMF0 datastream.
source code
StringIO
encode(*args, **kwargs)
A helper function to encode an element into the AMF0 format.
source code
 
check_nan(func) source code
 
_check_for_int(x)
This is a compatibility function that takes a float and converts it to an int if the values are equal.
source code
Variables [hide private]
  TYPE_NUMBER = '\x00'
Represented as 9 bytes: 1 byte for 0×00 and 8 bytes a double representing the value of the number.
  TYPE_BOOL = '\x01'
Represented as 2 bytes: 1 byte for 0×01 and a second, 0×00 for False, 0×01 for True.
  TYPE_STRING = '\x02'
Represented as 3 bytes + len(String): 1 byte 0×02, then a UTF8 string, including the top two bytes representing string length as a int.
  TYPE_OBJECT = '\x03'
Represented as 1 byte, 0×03, then pairs of UTF8 string, the key, and an AMF element, ended by three bytes, 0×00 0×00 0×09.
  TYPE_MOVIECLIP = '\x04'
MovieClip does not seem to be supported by Remoting.
  TYPE_NULL = '\x05'
1 single byte, 0×05 indicates null.
  TYPE_UNDEFINED = '\x06'
1 single byte, 0×06 indicates null.
  TYPE_REFERENCE = '\x07'
When an ActionScript object refers to itself, such this.self = this, or when objects are repeated within the same scope (for example, as the two parameters of the same function called), a code of 0×07 and an int, the reference number, are written.
  TYPE_MIXEDARRAY = '\x08'
A MixedArray is indicated by code 0×08, then a Long representing the highest numeric index in the array, or 0 if there are none or they are all negative.
  TYPE_OBJECTTERM = '\t'
  TYPE_ARRAY = '\n'
An array is indicated by 0x0A, then a Long for array length, then the array elements themselves.
  TYPE_DATE = '\x0b'
Date is represented as 00x0B, then a double, then an int.
  TYPE_LONGSTRING = '\x0c'
LongString is reserved for strings larger then 2^16 characters long.
  TYPE_UNSUPPORTED = '\r'
Trying to send values which don’t make sense, such as prototypes, functions, built-in objects, etc.
  TYPE_RECORDSET = '\x0e'
Remoting Server -> Client only.
  TYPE_XML = '\x0f'
The XML element is indicated by 00x0F and followed by a LongUTF containing the string representation of the XML object.
  TYPE_TYPEDOBJECT = '\x10'
A typed object is indicated by 0×10, then a UTF string indicating class name, and then the same structure as a normal 0×03 Object.
  TYPE_AMF3 = '\x11'
An AMF message sent from an AVM+ client such as the Flash Player 9 may break out into AMF3 mode.

Imports: datetime, types, copy, pyamf, util


Function Details [hide private]

encode(*args, **kwargs)

source code 

A helper function to encode an element into the AMF0 format.

Parameters:
  • element (mixed) - The element to encode
  • context (Context) - AMF0 Context to use for the encoding. This holds previously referenced objects etc.
Returns: StringIO
The encoded stream.

Variables Details [hide private]

TYPE_MOVIECLIP

MovieClip does not seem to be supported by Remoting. It may be used by other AMF clients such as SharedObjects.

Value:
'\x04'

TYPE_MIXEDARRAY

A MixedArray is indicated by code 0×08, then a Long representing the highest numeric index in the array, or 0 if there are none or they are all negative. After that follow the elements in key : value pairs.

Value:
'\x08'

TYPE_OBJECTTERM

See Also: TYPE_OBJECT

Value:
'\t'

TYPE_ARRAY

An array is indicated by 0x0A, then a Long for array length, then the array elements themselves. Arrays are always sparse; values for inexistant keys are set to null (0×06) to maintain sparsity.

Value:
'''
'''

TYPE_DATE

Date is represented as 00x0B, then a double, then an int. The double represents the number of milliseconds since 01/01/1970. The int represents the timezone offset in minutes between GMT. Note for the latter than values greater than 720 (12 hours) are represented as 2^16 - the value. Thus GMT+1 is 60 while GMT-5 is 65236.

Value:
'\x0b'

TYPE_LONGSTRING

LongString is reserved for strings larger then 2^16 characters long. It is represented as 00x0C then a LongUTF.

Value:
'\x0c'

TYPE_UNSUPPORTED

Trying to send values which don’t make sense, such as prototypes, functions, built-in objects, etc. will be indicated by a single 00x0D byte.

Value:
'\r'

TYPE_RECORDSET

Remoting Server -> Client only.

Value:
'\x0e'

TYPE_XML

The XML element is indicated by 00x0F and followed by a LongUTF containing the string representation of the XML object. The receiving gateway may which to wrap this string inside a language-specific standard XML object, or simply pass as a string.

Value:
'\x0f'

TYPE_TYPEDOBJECT

A typed object is indicated by 0×10, then a UTF string indicating class name, and then the same structure as a normal 0×03 Object. The receiving gateway may use a mapping scheme, or send back as a vanilla object or associative array.

Value:
'\x10'

TYPE_AMF3

An AMF message sent from an AVM+ client such as the Flash Player 9 may break out into AMF3 mode. In this case the next byte will be the AMF3 type code and the data will be in AMF3 format until the decoded object reaches it’s logical conclusion (for example, an object has no more keys).

Value:
'\x11'