|
AMF3 implementation.
C{AMF3} is the default serialization for U{ActionScript<http://en.wikipedia.org/wiki/ActionScript>} 3.0 and provides various advantages over L{AMF0<pyamf.amf0>}, which is used for ActionScript 1.0 and 2.0. It adds support for sending C{int} and C{uint} objects as integers and supports data types that are available only in ActionScript 3.0, such as L{ByteArray} and L{ArrayCollection}.
@see: U{Official AMF3 Specification in English (external) <http://opensource.adobe.com/wiki/download/attachments/1114283/amf3_spec_05_05_08.pdf>} @see: U{Official AMF3 Specification in Japanese (external) <http://opensource.adobe.com/wiki/download/attachments/1114283/JP_amf3_spec_121207.pdf>} @see: U{AMF3 documentation on OSFlash (external) <http://osflash.org/documentation/amf3>}
@since: 0.1
I am a C{StringIO} type object containing byte data from the AMF stream. ActionScript 3.0 introduced the C{flash.utils.ByteArray} class to support the manipulation of raw data in the form of an Array of bytes.
Supports C{zlib} compression.
@see: U{ByteArray on Livedocs (external) <http://livedocs.adobe.com/flex/201/langref/flash/utils/ByteArray.html>}
I hold the AMF3 context for en/decoding streams.
@ivar strings: A list of string references. @type strings: C{list} @ivar classes: A list of L{ClassDefinition}. @type classes: C{list} @ivar legacy_xml: A list of legacy encoded XML documents. @type legacy_xml: C{list}
Creates a reference to C{class_def}.
@param alias: C{ClassDefinition} instance.
Creates a reference to C{doc}.
If C{doc} is already referenced that index will be returned. Otherwise a new index will be created.
@type doc: L{ET<util.ET>} @param doc: The XML document to reference. @rtype: C{int} @return: The reference to C{doc}.
Creates a reference to C{s}. If the reference already exists, that reference is returned.
@type s: C{str} @param s: The string to be referenced. @rtype: C{int} @return: The reference index.
@raise TypeError: The parameter C{s} is not of C{basestring} type.
Return class reference.
@return: Class reference.
Return class reference.
@return: Class reference.
Return the legacy XML reference. This is the C{flash.xml.XMLDocument} class in ActionScript 3.0 and the top-level C{XML} class in ActionScript 1.0 and 2.0.
@type ref: C{int} @param ref: The reference index. @return: Instance of L{ET<util.ET>} or C{None}
Return legacy XML reference.
@type doc: L{ET<util.ET>} @param doc: The XML document to reference. @return: The reference to C{doc} or C{None}. @rtype: C{int}
Gets a string based on a reference C{ref}.
@param ref: The reference index. @type ref: C{str}
@rtype: C{str} or C{None} @return: The referenced string.
Return string reference.
@type s: C{str} @param s: The referenced string. @return: The reference index to the string. @rtype: C{int} or C{None}
I provide a set of methods for reading binary data with ActionScript 3.0.
This class is the I/O counterpart to the L{DataOutput} class, which writes binary data.
@see: U{IDataInput on Livedocs (external) <http://livedocs.adobe.com/flex/201/langref/flash/utils/IDataInput.html>}
Read C{Boolean}.
@raise ValueError: Error reading Boolean. @rtype: C{bool} @return: A Boolean value, C{True} if the byte is nonzero, C{False} otherwise.
Reads a signed byte.
@rtype: C{int} @return: The returned value is in the range -128 to 127.
Reads an IEEE 754 double-precision floating point number from the data stream.
@rtype: C{number} @return: An IEEE 754 double-precision floating point number.
Reads an IEEE 754 single-precision floating point number from the data stream.
@rtype: C{number} @return: An IEEE 754 single-precision floating point number.
Reads a signed 32-bit integer from the data stream.
@rtype: C{int} @return: The returned value is in the range -2147483648 to 2147483647.
Reads a multibyte string of specified length from the data stream using the specified character set.
@type length: C{int} @param length: The number of bytes from the data stream to read. @type charset: C{str} @param charset: The string denoting the character set to use.
@rtype: C{str} @return: UTF-8 encoded string.
Reads an object from the data stream.
@return: The deserialized object.
Reads a signed 16-bit integer from the data stream.
@rtype: C{uint} @return: The returned value is in the range -32768 to 32767.
Reads a UTF-8 string from the data stream.
The string is assumed to be prefixed with an unsigned short indicating the length in bytes.
@rtype: C{str} @return: A UTF-8 string produced by the byte representation of characters.
Reads a sequence of C{length} UTF-8 bytes from the data stream and returns a string.
@type length: C{int} @param length: The number of bytes from the data stream to read. @rtype: C{str} @return: A UTF-8 string produced by the byte representation of characters of specified C{length}.
Reads an unsigned byte from the data stream.
@rtype: C{uint} @return: The returned value is in the range 0 to 255.
Reads an unsigned 32-bit integer from the data stream.
@rtype: C{uint} @return: The returned value is in the range 0 to 4294967295.
Reads an unsigned 16-bit integer from the data stream.
@rtype: C{uint} @return: The returned value is in the range 0 to 65535.
I am a C{StringIO} type object containing byte data from the AMF stream. ActionScript 3.0 introduced the C{flash.utils.ByteArray} class to support the manipulation of raw data in the form of an Array of bytes. I provide a set of methods for writing binary data with ActionScript 3.0.
This class is the I/O counterpart to the L{DataInput} class, which reads binary data.
@see: U{IDataOutput on Livedocs (external) <http://livedocs.adobe.com/flex/201/langref/flash/utils/IDataOutput.html>}
Writes a Boolean value.
@type value: C{bool} @param value: A C{Boolean} value determining which byte is written. If the parameter is C{True}, C{1} is written; if C{False}, C{0} is written.
@raise ValueError: Non-boolean value found.
Writes a byte.
@type value: C{int}
Writes an IEEE 754 double-precision (64-bit) floating point number.
@type value: C{number}
Writes an IEEE 754 single-precision (32-bit) floating point number.
@type value: C{float}
Writes a 32-bit signed integer.
@type value: C{int}
Writes a multibyte string to the datastream using the specified character set.
@type value: C{str} @param value: The string value to be written. @type charset: C{str} @param charset: The string denoting the character set to use. Possible
character set strings include C{shift-jis}, C{cn-gb}, C{iso-8859-1} and others.
Writes an object to data stream in AMF serialized format.
@param value: The object to be serialized.
Writes a 16-bit integer.
@type value: C{int} @param value: A byte value as an integer.
Writes a UTF-8 string to the data stream.
The length of the UTF-8 string in bytes is written first, as a 16-bit integer, followed by the bytes representing the characters of the string.
@type value: C{str} @param value: The string value to be written.
Writes a UTF-8 string. Similar to L{writeUTF}, but does not prefix the string with a 16-bit length word.
@type value: C{str} @param value: The string value to be written.
Writes an unsigned byte.
@type value: C{int} @since: 0.5
Writes a 32-bit unsigned integer.
@type value: C{int} @param value: A byte value as an unsigned integer.
Writes a 16-bit unsigned integer.
@type value: C{int} @param value: A byte value as an integer. @since: 0.5
Decodes an AMF3 data stream.
Reads an array from the stream.
@warning: There is a very specific problem with AMF3 where the first three bytes of an encoded empty C{dict} will mirror that of an encoded C{{‘’: 1, ‘2’: 2}}
@see: U{Docuverse blog (external) <http://www.docuverse.com/blog/donpark/2007/05/14/flash-9-amf3-bug>}
Returns C{False}.
@return: C{False} @rtype: C{bool}
Returns C{True}.
@return: C{True} @rtype: C{bool}
Reads a string of data from the stream.
Detects if the L{ByteArray} was compressed using C{zlib}.
@see: L{ByteArray} @note: This is not supported in ActionScript 1.0 and 2.0.
Read date from the stream.
The timezone is ignored as the date is always in UTC.
Reads and returns an integer from the stream.
@type signed: C{bool} @see: U{Parsing integers on OSFlash <http://osflash.org/amf3/parsing_integers>} for the AMF3 integer data format.
Read null.
@return: C{None} @rtype: C{None}
Reads an object from the stream.
| Raises pyamf.EncodeError: | |
|---|---|
| Decoding an object in amf3 tagged as amf0 only is not allowed. | |
| Raises pyamf.DecodeError: | |
| Unknown object encoding. | |
| Raises pyamf.ReferenceError: | |
| Bad object reference given. | |
Read a legacy XML Document from the stream.
@return: The XML Document. @rtype: L{ET<util.ET>}
Reads a string from the data stream and converts it into an XML Tree.
@return: The XML Document. @rtype: L{ET<util.ET>}
Encodes an AMF3 data stream.
Writes a L{ByteArray} to the data stream.
@param n: The L{ByteArray} data to be encoded to the AMF3 data stream. @type n: L{ByteArray}
Writes a C{datetime} instance to the stream.
@type n: L{datetime} @param n: The C{Date} data to be encoded to the AMF3 data stream.
Writes a C{dict} to the stream.
@type n: C{__builtin__.dict} @param n: The C{dict} data to be encoded to the AMF3 data stream. @raise ValueError: Non C{int}/C{str} key value found in the C{dict} @raise EncodeError: C{dict} contains empty string keys.
Writes an integer to the stream.
@type n: integer data @param n: The integer data to be encoded to the AMF3 data stream.
Writes a C{tuple}, C{set} or C{list} to the stream.
@param n: The C{list} data to be encoded to the AMF3 data stream.
Writes a float to the stream.
@type n: C{float}
Writes an object to the stream.
| Parameter: | obj – The object data to be encoded to the AMF3 data stream. |
|---|
Writes a string to the stream. If C{n} is not a unicode string, an attempt will be made to convert it.
@type n: C{basestring} @param n: The string data to be encoded to the AMF3 data stream.
Writes a XML string to the data stream.
@type n: L{ET<util.ET>} @param n: The XML Document to be encoded to the AMF3 data stream.
AMF object encodings.
A helper function to decode an AMF3 datastream.
@type stream: L{BufferedByteStream<util.BufferedByteStream>} @param stream: AMF3 data. @type context: L{Context} @param context: Context.
A helper function to encode an element into AMF3 format.
@type args: List of args to encode. @keyword context: Any initial context to use. @type context: L{Context} @return: C{StringIO} type object containing the encoded AMF3 data. @rtype: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
Encodes an int as a variable length signed 29-bit integer as defined by the spec.
@param n: The integer to be encoded @return: The encoded string @rtype: C{str} @raise OverflowError: Out of range.
The pyamf.amf3 module supplies classes for [todo].
The pyamf.amf3 module exports the following constants:
See also