2.1. pyamf.amf0 — AMF0
AMF0 implementation.
AMF0 supports the basic data types used for the NetConnection, NetStream,
LocalConnection, SharedObjects and other classes in the Adobe Flash Player.
Since: 0.1
-
class pyamf.amf0.Context(**kwargs)
I hold the AMF0 context for en/decoding streams.
AMF0 object references start at index 1.
| Ivariables: |
- amf3_objs : util.IndexedCollection
A list of objects that have been decoded in
AMF3
|
-
addAMF3Object(obj)
Adds an AMF3 reference to C{obj}.
@type obj: C{mixed}
@param obj: The object to add to the context.
@rtype: C{int}
@return: Reference to C{obj}.
-
clear()
- Clears the context.
-
hasAMF3ObjectReference(obj)
- Gets a reference for an object.
-
class pyamf.amf0.Decoder(stream=None, context=None, strict=False, timezone_offset=None)
Decodes an AMF0 stream.
-
context_class
- alias of Context
-
readAMF3()
Read AMF3 elements from the data stream.
@rtype: C{mixed}
@return: The AMF3 element read from the stream
-
readBoolean()
Reads a ActionScript C{Boolean} value.
@rtype: C{bool}
@return: Boolean.
-
readDate()
Reads a UTC date from the data stream. Client and servers are
responsible for applying their own timezones.
Date: C{0x0B T7 T6} .. C{T0 Z1 Z2 T7} to C{T0} form a 64 bit
Big Endian number that specifies the number of nanoseconds
that have passed since 1/1/1970 0:00 to the specified time.
This format is UTC 1970. C{Z1} and C{Z0} for a 16 bit Big
Endian number indicating the indicated time’s timezone in
minutes.
-
readList()
Read a C{list} from the data stream.
@rtype: C{list}
@return: C{list}
-
readLongString()
- Read UTF8 string.
-
readMixedArray()
Read mixed array.
@rtype: C{dict}
@return: C{dict} read from the stream
-
readNull()
Reads a ActionScript C{null} value.
@return: C{None}
@rtype: C{None}
-
readNumber()
Reads a ActionScript C{Number} value.
In ActionScript 1 and 2 the C{NumberASTypes} type represents all numbers,
both floats and integers.
@rtype: C{int} or C{float}
-
readObject()
Reads an object from the data stream.
@rtype: L{ASObject<pyamf.ASObject>}
-
readReference()
Reads a reference from the data stream.
@raise pyamf.ReferenceError: Unknown reference.
-
readString()
- Reads a C{string} from the stream.
-
readTypedObject()
Reads an ActionScript object from the stream and attempts to
‘cast’ it.
@see: L{load_class<pyamf.load_class>}
-
readUndefined()
Reads an ActionScript C{undefined} value.
@return: L{Undefined<pyamf.Undefined>}
-
readUnicode()
- Reads a C{unicode} from the data stream.
-
readXML()
- Read XML.
-
class pyamf.amf0.Encoder(*args, **kwargs)
Encodes an AMF0 stream.
@ivar use_amf3: A flag to determine whether this encoder knows about AMF3.
@type use_amf3: C{bool}
-
context_class
- alias of Context
-
writeAMF3(data)
Writes an element to the datastream in L{AMF3<pyamf.amf3>} format.
@type data: C{mixed}
@param data: The data to be encoded to the AMF0 data stream.
-
writeBoolean(b)
Write boolean to the data stream.
@type b: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param b: The boolean data to be encoded to the AMF0 data stream.
-
writeDate(d)
Writes a date to the data stream.
@type d: Instance of C{datetime.datetime}
@param d: The date to be encoded to the AMF0 data stream.
-
writeList(a)
Write array to the stream.
@type a: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param a: The array data to be encoded to the AMF0 data stream.
-
writeMixedArray(o)
Write mixed array to the data stream.
@type o: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param o: The mixed array data to be encoded to the AMF0
data stream.
-
writeNull(n)
Write null type to data stream.
@type n: C{None}
@param n: Is ignored.
-
writeNumber(n)
Write number to the data stream.
@type n: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param n: The number data to be encoded to the AMF0 data stream.
-
writeObject(o)
Write object to the stream.
@type o: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param o: The object data to be encoded to the AMF0 data stream.
-
writeReference(o)
Write reference to the data stream.
@type o: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param o: The reference data to be encoded to the AMF0 data
stream.
-
writeString(s, writeType=True)
Write string to the data stream.
@type s: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param s: The string data to be encoded to the AMF0 data stream.
@type writeType: C{bool}
@param writeType: Write data type.
-
writeType(t)
Writes the type to the stream.
@type t: C{str}
@param t: ActionScript type.
@raise pyamf.EncodeError: AMF0 type is not recognized.
-
writeUndefined(data)
Writes the L{undefined<TYPE_UNDEFINED>} data type to the stream.
- @param data: The C{undefined} data to be encoded to the AMF0 data
- stream.
@type data: C{undefined} data
-
writeUnicode(u, writeType=True)
- Write a unicode to the data stream.
-
writeUnsupported(data)
Writes L{unsupported<TYPE_UNSUPPORTED>} data type to the
stream.
- @param data: The C{unsupported} data to be encoded to the AMF0
- data stream.
@type data: C{unsupported} data
-
writeXML(e)
Write XML to the data stream.
@type e: L{BufferedByteStream<pyamf.util.BufferedByteStream>}
@param e: The XML data to be encoded to the AMF0 data stream.
-
class pyamf.amf0.RecordSet(columns=[], items=[], service=None, id=None)
I represent the C{RecordSet} class used in Adobe Flash Remoting to hold
(amongst other things) SQL records.
@ivar columns: The columns to send.
@type columns: List of strings.
@ivar items: The C{RecordSet} data.
@type items: List of lists, the order of the data corresponds to the order
of the columns.
@ivar service: Service linked to the C{RecordSet}.
@type service:
@ivar id: The id of the C{RecordSet}.
@type id: C{str}
@see: U{RecordSet on OSFlash (external)
<http://osflash.org/documentation/amf/recordset>}
-
pyamf.amf0.TYPE_AMF3
- An AMF message sent from an AVM+ client such as the Flash Player 9 may break
out into L{AMF3<pyamf.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).
-
pyamf.amf0.TYPE_ARRAY
- An array is indicated by C{0x0A}, then a Long for array length, then the
array elements themselves. Arrays are always sparse; values for
inexistant keys are set to null (C{0×06}) to maintain sparsity.
-
pyamf.amf0.TYPE_BOOL
- Represented as 2 bytes: 1 byte for C{0×01} and a second, C{0×00}
for C{False}, C{0×01} for C{True}.
-
pyamf.amf0.TYPE_DATE
- Date is represented as C{00x0B}, then a double, then an C{int}. The double
represents the number of milliseconds since 01/01/1970. The C{int} represents
the timezone offset in minutes between GMT. Note for the latter than values
greater than 720 (12 hours) are represented as M{2^16} - the value. Thus GMT+1
is 60 while GMT-5 is 65236.
-
pyamf.amf0.TYPE_LONGSTRING
- LongString is reserved for strings larger then M{2^16} characters long. It
is represented as C{00x0C} then a LongUTF.
-
pyamf.amf0.TYPE_MIXEDARRAY
- A MixedArray is indicated by code C{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.
-
pyamf.amf0.TYPE_MOVIECLIP
- MovieClip does not seem to be supported by Remoting.
It may be used by other AMF clients such as SharedObjects.
-
pyamf.amf0.TYPE_NULL
- 1 single byte, C{0×05} indicates null.
-
pyamf.amf0.TYPE_NUMBER
- Represented as 9 bytes: 1 byte for C{0×00} and 8 bytes a double
representing the value of the number.
-
pyamf.amf0.TYPE_OBJECT
- Represented as 1 byte, C{0×03}, then pairs of UTF8 string, the key, and
an AMF element, ended by three bytes, C{0×00} C{0×00} C{0×09}.
-
pyamf.amf0.TYPE_OBJECTTERM
- @see: L{TYPE_OBJECT}
-
pyamf.amf0.TYPE_RECORDSET
- Remoting Server -> Client only.
@see: L{RecordSet}
@see: U{RecordSet structure on OSFlash (external)
<http://osflash.org/documentation/amf/recordset>}
-
pyamf.amf0.TYPE_REFERENCE
- When an ActionScript object refers to itself, such C{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 C{0×07} and an
C{int}, the reference number, are written.
-
pyamf.amf0.TYPE_STRING
- Represented as 3 bytes + len(String): 1 byte C{0×02}, then a UTF8 string,
including the top two bytes representing string length as a C{int}.
-
pyamf.amf0.TYPE_TYPEDOBJECT
- A typed object is indicated by C{0×10}, then a UTF string indicating class
name, and then the same structure as a normal C{0×03} Object. The receiving
gateway may use a mapping scheme, or send back as a vanilla object or
associative array.
-
pyamf.amf0.TYPE_UNDEFINED
- 1 single byte, C{0×06} indicates null.
-
pyamf.amf0.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 C{00x0D} byte.
-
pyamf.amf0.TYPE_XML
- The XML element is indicated by C{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.
-
pyamf.amf0.decode(*args, **kwargs)
- A helper function to decode an AMF0 datastream.
-
pyamf.amf0.encode(*args, **kwargs)
A helper function to encode an element into the AMF0 format.
@type element: C{mixed}
@keyword element: The element to encode
@type context: L{Context<pyamf.amf0.Context>}
@keyword context: AMF0 C{Context} to use for the encoding. This holds
previously referenced objects etc.
@rtype: C{StringIO}
@return: The encoded stream.
The amf0 module supplies classes for [todo].
The amf0 module exports the following constants:
-
pyamf.amf0.TYPE_NUMBER
- Number type for AMF0.
2.1.1. Available Types
-
class pyamf.amf0.Context(**kwargs)
I hold the AMF0 context for en/decoding streams.
AMF0 object references start at index 1.
| Ivariables: |
- amf3_objs : util.IndexedCollection
A list of objects that have been decoded in
AMF3
|
The AMF0 context for en/decoding streams.