PKQ8!"CCEGG-INFO/PKG-INFOMetadata-Version: 1.0 Name: PyAMF Version: 0.3.1 Summary: AMF support for Python Home-page: http://pyamf.org Author: The PyAMF Project Author-email: dev@pyamf.org License: MIT License Description: PyAMF provides Action Message Format (AMF) support for Python that is compatible with the Flash Player. The Adobe Integrated Runtime and Flash Player use AMF to communicate between an application and a remote server. AMF encodes remote procedure calls (RPC) into a compact binary representation that can be transferred over HTTP/HTTPS or the RTMP/RTMPS protocol. Objects and data values are serialized into this binary format, which increases performance, allowing applications to load data up to 10 times faster than with text-based formats such as XML or SOAP. AMF3, the default serialization for ActionScript 3.0, provides various advantages over AMF0, which is used for ActionScript 1.0 and 2.0. AMF3 sends data over the network more efficiently than AMF0. AMF3 supports sending int and uint objects as integers and supports data types that are available only in ActionScript 3.0, such as ByteArray, ArrayCollection, and IExternalizable. Keywords: amf amf0 amf3 flex flash remoting rpc http flashplayer air bytearray objectproxy arraycollection recordset actionscript decoder encoder gateway Platform: any Classifier: Development Status :: 4 - Beta Classifier: Natural Language :: English Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Framework :: Django Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application Classifier: Topic :: Software Development :: Libraries :: Python Modules PKQ82EGG-INFO/zip-safe PKQ8o~~EGG-INFO/SOURCES.txtCHANGES.txt INSTALL.txt LICENSE.txt README.txt THANKS.txt ez_setup.py setup.cfg setup.py PyAMF.egg-info/PKG-INFO PyAMF.egg-info/SOURCES.txt PyAMF.egg-info/dependency_links.txt PyAMF.egg-info/requires.txt PyAMF.egg-info/top_level.txt PyAMF.egg-info/zip-safe pyamf/__init__.py pyamf/amf0.py pyamf/amf3.py pyamf/logging.py pyamf/sol.py pyamf/adapters/__init__.py pyamf/adapters/_django_db_models_query.py pyamf/adapters/_google_appengine_ext_db.py pyamf/flex/__init__.py pyamf/flex/data.py pyamf/flex/messaging.py pyamf/remoting/__init__.py pyamf/remoting/amf0.py pyamf/remoting/amf3.py pyamf/remoting/client/__init__.py pyamf/remoting/gateway/__init__.py pyamf/remoting/gateway/django.py pyamf/remoting/gateway/google.py pyamf/remoting/gateway/twisted.py pyamf/remoting/gateway/wsgi.py pyamf/tests/__init__.py pyamf/tests/test_adapters.py pyamf/tests/test_amf0.py pyamf/tests/test_amf3.py pyamf/tests/test_basic.py pyamf/tests/test_flex.py pyamf/tests/test_gateway.py pyamf/tests/test_imports.py pyamf/tests/test_remoting.py pyamf/tests/test_sol.py pyamf/tests/test_util.py pyamf/tests/util.py pyamf/tests/adapters/__init__.py pyamf/tests/adapters/test_django.py pyamf/tests/adapters/test_google.py pyamf/tests/gateway/__init__.py pyamf/tests/gateway/test_django.py pyamf/tests/gateway/test_google.py pyamf/tests/gateway/test_twisted.py pyamf/tests/gateway/test_wsgi.py pyamf/tests/imports/spam.py pyamf/tests/imports/foo/__init__.py pyamf/tests/imports/foo/bar/__init__.py pyamf/tests/imports/foo/bar/baz.py pyamf/tests/remoting/__init__.py pyamf/tests/remoting/test_client.py pyamf/tests/remoting/test_remoteobject.py pyamf/util/__init__.py pyamf/util/imports.pyPKQ8^EGG-INFO/top_level.txtpyamf PKQ8 ;ooEGG-INFO/requires.txtelementtree >= 1.2.6 uuid>=1.30 fpconst>=0.7.2 [wsgi] wsgiref [twisted] Twisted>=2.5.0 [django] Django>=0.96PKQ82EGG-INFO/dependency_links.txt PKQ8,џџpyamf/__init__.pyc; OHc@sdZdkZdklZdklZdddddgZd d d fZhZgZ hZ hZ d Z d Z e e fZd fd YZgZx:eiD]/Zeid oeieieqqW[eZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZ defd YZ!d!e"fd"YZ#d#efd$YZ$d%efd&YZ%d'efd(YZ&d)efd*YZ'e(e(e(gd+Z)d,Z*d-Z+d.Z,d/Z-d0Z.d1Z/d2Z0e e(d3Z1d4Z2e(e(d5Z3d6Z4e(e(d7Z5d8Z6d9Z7d:Z8d;Z9e+e9e(d<Z:d=Z;d>Z<d?Z=d@Z>edS(AsD B{PyAMF} provides B{A}ction B{M}essage B{F}ormat (U{AMF}) support for Python that is compatible with the U{Flash Player}. @author: U{Arnar Birgisson} @author: U{Thijs Triemstra} @author: U{Nick Joyce} @copyright: Copyright (c) 2007-2008 The PyAMF Project. All Rights Reserved. @contact: U{dev@pyamf.org} @see: U{http://pyamf.org} @since: October 2007 @status: Beta @version: 0.3.1 N(sutil(sregister_adapterssregister_classsregister_class_loadersencodesdecodes __version__iiis ClientTypescBs tZdZdZdZdZRS(s Typecodes used to identify AMF clients and servers. @see: U{Flash Player on WikiPedia (external) } @see: U{Flash Media Server on WikiPedia (external) } iii(s__name__s __module__s__doc__sFlash6sFlashComsFlash9(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys ClientTypes8s s_s BaseErrorcBstZdZRS(s[ Base AMF Error. All AMF related errors should be subclassed from this class. (s__name__s __module__s__doc__(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys BaseErrorSs s DecodeErrorcBstZdZRS(sE Raised if there is an error in decoding an AMF data stream. (s__name__s __module__s__doc__(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys DecodeErrorZs sEOStreamcBstZdZRS(s> Raised if the data stream has come to a natural end. (s__name__s __module__s__doc__(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysEOStream_s sReferenceErrorcBstZdZRS(s_ Raised if an AMF data stream refers to a non-existent object or string reference. (s__name__s __module__s__doc__(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysReferenceErrords s EncodeErrorcBstZdZRS(s Raised if the element could not be encoded to the stream. @bug: See U{Docuverse blog (external) } for more info about the empty key string array bug. (s__name__s __module__s__doc__(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys EncodeErrorjs sUnknownClassAliascBstZdZRS(sr Raised if the AMF stream specifies a class that does not have an alias. @see: L{register_class} (s__name__s __module__s__doc__(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysUnknownClassAliasss s BaseContextcBsMtZdZdZdZdZdZdZdZdZ RS(s9 I hold the AMF context for en/decoding streams. cCs|idS(N(sselfsclear(sself((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__init__scCsg|_h|_h|_dS(N(sselfsobjectss rev_objectss class_aliases(sself((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysclears  cCsSt|ttf o tdny|i|SWntj o tnXdS(se Gets an object based on a reference. @raise TypeError: Bad reference type. sBad reference typeN( s isinstancesrefsintslongs TypeErrorsselfsobjectss IndexErrorsReferenceError(sselfsref((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys getObjects cCs5y|it|SWntj o tnXdS(s1 Gets a reference for an object. N(sselfs rev_objectssidsobjsKeyErrorsReferenceError(sselfsobj((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysgetObjectReferences cCs>|ii|t|id}||it|<|SdS(s Adds a 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}. iN(sselfsobjectssappendsobjslensidxs rev_objectssid(sselfsobjsidx((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys addObjects cCs]||ijo>yt||i|(sselfsaliassklasssid(sself((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__repr__uscCszt|to|i|jSnVt||io|i|ijSn/t|tti fo|i|jSnt SdS(N( s isinstancesothers basestringsselfsaliass __class__sklassstypestypess ClassTypesFalse(sselfsother((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__eq__yscCst|SdS(N(sidsself(sself((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__hash__sc Cs|tjo g}nt}|itj ot}||i7}nd|ijo |itj oUt}|i|}|gi }|D]!} | |jo|| qq~7}n|tjox}ti|iD]e} yt| }Wntj o qnX|i||t} | tj o|| 7}t}qqWn|tjotSng}x,|D]$} | |jo|i | qhqhW|SdS(Nsdynamic(sattrssNonesFalses did_somethingsselfsTruesmetadatas attr_funcsobjs extra_attrssappends_[1]skeystraversesutilsget_mros __class__sbasesget_class_aliassaliassUnknownClassAliassgetAttrssxsa( sselfsobjsattrsstraversesas extra_attrss did_somethings_[1]saliassbaseskeysx((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysgetAttrss:   @     ( s__name__s __module__s__doc__sNones__init__s__call__s__str__s__repr__s__eq__s__hash__sTruesgetAttrs(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys ClassAliass ;    s BaseDecodercBsDtZdZeZhZeedZdZdZ dZ RS(s= Base AMF decoder. @ivar context_class: The context for the decoding. @type context_class: An instance of C{BaseDecoder.context_class} @ivar type_map: @type type_map: C{list} @ivar stream: The underlying data stream. @type stream: L{BufferedByteStream} cCst|tio ||_nti||_|tjo|i|_n@t||io ||_n t d|ii |ii fdS(s< @type data: L{BufferedByteStream} @param data: Data stream. @type context: L{Context} @param context: Context. @raise TypeError: The C{context} parameter must be of type L{Context}. scontext must be of type %s.%sN( s isinstancesdatasutilsBufferedByteStreamsselfsstreamscontextsNones context_classs TypeErrors __module__s__name__(sselfsdatascontext((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__init__s   cCs tdS(N(sNotImplementedError(sself((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysreadTypescCsvy|i}Wntj o tnXyt||i|}Wn"tj o}t d|nX|SdS(s Reads an AMF3 element from the data stream. @raise DecodeError: The ActionScript type is unsupported. @raise EOStream: No more data left to decode. s$Unsupported ActionScript type 0x%02xN( sselfsreadTypestypesEOFErrorsEOStreamsgetattrstype_mapsfuncsKeyErrorses DecodeError(sselfsfuncsestype((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys readElements ccs=yxno|iVq WWntj o tnXdS(Ni(sselfs readElementsEOFErrors StopIteration(sself((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__iter__s ( s__name__s __module__s__doc__s BaseContexts context_classstype_mapsNones__init__sreadTypes readElements__iter__(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys BaseDecoders   sCustomTypeFunccBs tZdZdZdZRS(s Custom type mappings. cCs||_||_dS(N(sencodersselfsfunc(sselfsencodersfunc((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__init__s cCs|ii|i|dS(N(sselfsencoders writeElementsfuncsdata(sselfsdata((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__call__s(s__name__s __module__s__doc__s__init__s__call__(((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysCustomTypeFuncs  s BaseEncodercBsDtZdZeZgZeedZdZdZ dZ RS(s Base AMF encoder. @ivar type_map: A list of types -> functions. The types is a list of possible instances or functions to call (that return a C{bool}) to determine the correct function to call to encode the data. @type type_map: C{list} @ivar context_class: Holds the class that will create context objects for the implementing C{Encoder}. @type context_class: C{type} or C{types.ClassType} @ivar stream: The underlying data stream. @type stream: L{BufferedByteStream} @ivar context: The context for the encoding. @type context: An instance of C{BaseEncoder.context_class} cCst|tio ||_nti||_|tjo|i|_n@t||io ||_n t d|ii |ii fh|_ dS(s@ @type data: L{BufferedByteStream} @param data: Data stream. @type context: L{Context} @param context: Context. @raise TypeError: The C{context} parameter must be of type L{Context}. scontext must be of type %s.%sN( s isinstancesdatasutilsBufferedByteStreamsselfsstreamscontextsNones context_classs TypeErrors __module__s__name__s_write_elem_func_cache(sselfsdatascontext((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys__init__s   cCsxtiD]r\}}y%t||ot||SnWq tj o2t |o ||ot||Sqq Xq Wx|i D]\}}xt|D]l}y%t||ot||SnWqtj o2t |o ||ot||Sq qXqWqWtSdS(s Gets a function used to encode the data. @type data: C{mixed} @param data: Python data. @rtype: callable or C{None}. @return: The function used to encode data to the stream. N(sTYPE_MAPs iteritemsstype_sfuncs isinstancesdatasCustomTypeFuncsselfs TypeErrorscallablestype_mapstlistsmethodstsgetattrsNone(sselfsdatastype_stsfuncstlistsmethod((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys_getWriteElementFunc's(  cCsiy |i}Wn tj o|i|SnX||ijo|i||i|} @param stream: AMF data. @type encoding: C{int} @param encoding: AMF encoding type. @type context: L{AMF0 Context} or L{AMF3 Context} @param context: Context. @return: Each element in the stream. iN(s_get_decoder_classsencodingsstreamscontextsdecoders readElementsEOStream(sstreamsencodingscontextsdecoder((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysdecode6s cOsx|idt}|idt}ti}t |||}x|D]}|i |qLW|id|SdS(so A helper function to encode an element. @type element: C{mixed} @keyword element: Python data. @type encoding: C{int} @keyword encoding: AMF encoding type. @type context: L{amf0.Context} or L{amf3.Context} @keyword context: Context. @rtype: C{StringIO} @return: File-like object. sencodingscontextiN(skwargssgetsAMF0sencodingsNonescontextsutilsBufferedByteStreamsstreams_get_encoder_classsencodersargssels writeElementsseek(sargsskwargssstreamsencodingsencoderscontextsel((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pysencodeKs  cCst|d|d|SdS(Nsdatascontext(s_get_decoder_classsencodingsdatascontext(sencodingsdatascontext((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys get_decodergscCsS|tjodk}|iSn"|tjodk}|iSntd|dS(s Get compatible decoder. @type encoding: C{int} @param encoding: AMF encoding version. @raise ValueError: AMF encoding version is unknown. @rtype: L{amf0.Decoder} or L{amf3.Decoder} @return: AMF0 or AMF3 decoder. NsUnknown encoding %s(sencodingsAMF0samf0sDecodersAMF3samf3s ValueError(sencodingsamf0samf3((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys_get_decoder_classjs       cCst|d|d|SdS(Nsdatascontext(s_get_encoder_classsencodingsdatascontext(sencodingsdatascontext((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys get_encoderscCsS|tjodk}|iSn"|tjodk}|iSntd|dS(s Get compatible encoder. @type encoding: C{int} @param encoding: AMF encoding version. @raise ValueError: AMF encoding version is unknown. @rtype: L{amf0.Encoder} or L{amf3.Encoder} @return: AMF0 or AMF3 encoder. NsUnknown encoding %s(sencodingsAMF0samf0sEncodersAMF3samf3s ValueError(sencodingsamf0samf3((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys_get_encoder_classs       cCst|SdS(N(s_get_context_classsencoding(sencoding((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys get_contextscCsS|tjodk}|iSn"|tjodk}|iSntd|dS(s- Gets a compatible context class. @type encoding: C{int} @param encoding: AMF encoding version @raise ValueError: AMF encoding version is unknown. @rtype: L{amf0.Context} or L{amf3.Context} @return: AMF0 or AMF3 context class. NsUnknown encoding %s(sencodingsAMF0samf0sContextsAMF3samf3s ValueError(sencodingsamf0samf3((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys_get_context_classs       cCs|id odSnyc|ido dk}n;|ido dk}n|ido dk}nt|SWntj ot|nXdS(s Loader for L{Flex} framework compatibility classes. @raise UnknownClassAlias: Trying to load unknown Flex compatibility class. sflex.Nsflex.messaging.messagessflex.messaging.iosflex.data.messages( saliass startswithspyamf.flex.messagingspyamfs pyamf.flexspyamf.flex.datas CLASS_CACHEsKeyErrorsUnknownClassAlias(saliasspyamf((s.build/bdist.linux-x86_64/egg/pyamf/__init__.pys flex_loaders    cCsd}t|tot|}n|tjotd|nt|tiox&|D]}||qaWn |||t|            ! PKK8 $pyamf/logging.py# Copyright (c) 2007-2008 The PyAMF Project. # See LICENSE for details. """ Logging utilities. @author: U{Nick Joyce} @since: 0.2.0 """ logging = __import__('logging') def _get_instance_name(obj): return "%s.%s.0x%x" % ( obj.__class__.__module__, obj.__class__.__name__, id(obj)) def class_logger(cls): return logging.getLogger('%s.%s' % (cls.__module__, cls.__name__)) def instance_logger(instance): return logging.getLogger(_get_instance_name(instance)) PKQ8+˹{{pyamf/amf0.pyc; OHc@s|dZdkZdkZdkZdklZdfdYZgZx:eiD]/Zei d oei eieqQqQW[dei fdYZ dei fd YZd eifd YZed Zd ZdefdYZeiedddgddgdZyedWnej on.XeddjodZeeZndS(s AMF0 implementation. C{AMF0} supports the basic data types used for the NetConnection, NetStream, LocalConnection, SharedObjects and other classes in the Flash Player. @see: U{Official AMF0 Specification in English (external) } @see: U{Official AMF0 Specification in Japanese (external) } @see: U{AMF documentation on OSFlash (external) } @author: U{Arnar Birgisson} @author: U{Thijs Triemstra} @author: U{Nick Joyce} @since: 0.1.0 N(sutilsASTypescBsztZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZRS(s The AMF/RTMP data encoding format constants. @see: U{Data types on OSFlash (external) } iiiiiiiiii i i i i iiii(s__name__s __module__s__doc__sNUMBERsBOOLsSTRINGsOBJECTs MOVIECLIPsNULLs UNDEFINEDs REFERENCEs MIXEDARRAYs OBJECTTERMsARRAYsDATEs LONGSTRINGs UNSUPPORTEDs RECORDSETsXMLs TYPEDOBJECTsAMF3(((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysASTypess& s_sContextcBs;tZdZdZdZdZdZdZRS(sh I hold the AMF0 context for en/decoding streams. AMF0 object references start at index 1. cCsGtii|g|_h|_t|do|iindS(s Resets the context. The C{amf3_objs} var keeps a list of objects that were encoded in L{AMF3}. s amf3_contextN(spyamfs BaseContextsclearsselfs amf3_objss rev_amf3_objsshasattrs amf3_context(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysclearws   cCs|i|dSdS(Ni(sselfsobjectssref(sselfsref((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys _getObjectscCs,|i}|i|_|i|_|SdS(N(sselfs __class__scopys amf3_objss rev_amf3_objs(sselfscopy((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys__copy__s   cCs5y|it|SWntj o tnXdS(sv Gets a reference for an object. @raise ReferenceError: Object reference could not be found. N(sselfs rev_amf3_objssidsobjsKeyErrorsReferenceError(sselfsobj((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysgetAMF3ObjectReferences cCs>|ii|t|id}||it|<|SdS(s 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}. iN(sselfs amf3_objssappendsobjslensidxs rev_amf3_objssid(sselfsobjsidx((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys addAMF3Objects (s__name__s __module__s__doc__sclears _getObjects__copy__sgetAMF3ObjectReferences addAMF3Object(((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysContextqs     sDecodercBsatZdZeZheid<eid<eid<ei d<ei d<ei d<ei d<ei d<eid <eid <eid <eid<eid <eid <eid} N(spyamfs Undefined(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys readUndefinedscCs|ii}ti}|ii||i |g}xb|i D]T}y8t |}|i||f||||<||=WqKtj oqKXqKW|i|SdS(sj Read mixed array. @rtype: C{dict} @return: C{dict} read from the stream N(sselfsstreams read_ulongslenspyamfs MixedArraysobjscontexts addObjects _readObjectsikeysskeysskeysintsikeysappends ValueErrorssort(sselfsikeysikeysslenskeysobj((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysreadMixedArrays"       cCsWg}|ii||ii}x't|D]}|i |i q2W|SdS(sh Read a C{list} from the data stream. @rtype: C{list} @return: C{list} N( sobjsselfscontexts addObjectsstreams read_ulongslensxrangesisappends readElement(sselfsisobjslen((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysreadLists cCsL|i}ti|}|}|ii||i |||SdS(s Reads an ActionScript object from the stream and attempts to 'cast' it. @see: L{load_class} N( sselfs readStrings classnamespyamfs load_classsaliassretscontexts addObjects _readObject(sselfs classnamesaliassret((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysreadTypedObject$s  cCst|id o#dkl}|i|i_ntiti|i |ii}|i }|ii ||SdS(s Read AMF3 elements from the data stream. @rtype: C{mixed} @return: The AMF3 element read from the stream s amf3_context(samf3N(shasattrsselfscontextspyamfsamf3sContexts amf3_contexts_get_decoder_classsAMF3sstreamsdecoders readElementselements addAMF3Object(sselfselementsamf3sdecoder((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysreadAMF34s $ cCs#|ii}|ii|SdS(sf Reads a string from the data stream. @rtype: C{str} @return: string N(sselfsstreams read_ushortslensread_utf8_string(sselfslen((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys readStringGsc sg|tj o|i|n|i}tt i }t }x7|ii|jo |i||<|i}qMW|iit|tjo|in|oct|do|i|dSnxtd|iD]}t||||qWnW|i}t|tt fo |i}nx'|iD]\}}|||qZWdSdS(Ns __setstate__cs |jS(N(sxsattrs(sx(sattrs(s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysls(sattrssaliassNonesgetAttrssobjsselfs readStringskeyschrsASTypess OBJECTTERMsotsdicts obj_attrssstreamspeeks readElementsreadslenskeysshasattrs __setstate__sfilterssetattrs __setattr__sfs isinstanceslists __setitem__s iteritemssvalue( sselfsobjsaliassvalues obj_attrssfsattrsskeysot((sattrss*build/bdist.linux-x86_64/egg/pyamf/amf0.pys _readObjectQs6        cCs1ti}|ii||i||SdS(sd Reads an object from the data stream. @rtype: L{ASObject} N(spyamfsASObjectsobjsselfscontexts addObjects _readObject(sselfsobj((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys readObjectys   cCs#|ii}|ii|SdS(s9 Reads a reference from the data stream. N(sselfsstreams read_ushortsidxscontexts getObject(sselfsidx((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys readReferencescCsL|iid}|ii}tii|}|i i ||SdS(s 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. f1000.0N( sselfsstreams read_doublesmss read_shortstzsdatetimesutcfromtimestampsdscontexts addObject(sselfstzsdsms((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysreadDates cCs#|ii}|ii|SdS(s# Read UTF8 string. N(sselfsstreams read_ulongslensread_utf8_string(sselfslen((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysreadLongStringscCs6|i}tii|}|ii||SdS(s Read XML. N( sselfsreadLongStringsdatasutilsETs fromstringsxmlscontexts addObject(sselfsxmlsdata((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysreadXMLs  ('s__name__s __module__s__doc__sContexts context_classsASTypessNUMBERsBOOLsSTRINGsOBJECTsNULLs UNDEFINEDs REFERENCEs MIXEDARRAYsARRAYsDATEs LONGSTRINGs UNSUPPORTEDsXMLs TYPEDOBJECTsAMF3stype_mapsreadTypes readNumbers readBooleansreadNulls readUndefinedsreadMixedArraysreadListsreadTypedObjectsreadAMF3s readStringsNones _readObjects readObjects readReferencesreadDatesreadLongStringsreadXML(((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysDecoders&        (   sEncoderc BstZdZeZeieifdfeifdfe fdfe e e fdfei fdfeieifdfeifdfeieifdfeieifd feiifd fd fd feieifdfg Zd ZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%e&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/d Z0RS(!s! Encodes an AMF0 stream. swriteUnsupporteds writeNulls writeBooleans writeNumbers writeStrings writeObjectswriteMixedArrays writeArrays writeDateswriteXMLcCs |tijS(N(sxspyamfs Undefined(sx((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pyssswriteUndefinedcCsK|tjo*tid||iidfn|ii|dS(s Writes the type to the stream. @type type: C{int} @param type: ActionScript type. @raise pyamf.EncodeError: AMF0 type is not recognized. sUnknown AMF0 type 0x%02x at %diN(stypesACTIONSCRIPT_TYPESspyamfs EncodeErrorsselfsstreamstells write_uchar(sselfstype((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeTypes *cCs|itidS(s? Writes the undefined data type to the stream. N(sselfs writeTypesASTypess UNDEFINED(sselfsdata((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pyswriteUndefinedscCs|itidS(s= Writes unsupported data type to the stream. N(sselfs writeTypesASTypess UNSUPPORTED(sselfsdata((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pyswriteUnsupportedscCsHy|ii||iSWntj onXtii||SdS(sr Gets a function based on the type of data. @see: L{pyamf.BaseEncoder._writeElementFunc} N( sselfscontextsgetAMF3ObjectReferencesdatas writeAMF3sReferenceErrorspyamfs BaseEncoders_writeElementFunc(sselfsdata((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys_writeElementFuncs cCs|i|}|tjo|i|n_y||WnMttfj o n3ti j o nti d|nXdS(s Writes the data. @type data: C{mixed} @param data: The data to be encoded to the AMF0 data stream. @raise EncodeError: Unable to encode the data. sUnable to encode '%r'N( sselfs_writeElementFuncsdatasfuncsNoneswriteUnsupportedsKeyboardInterrupts SystemExitspyamfs EncodeError(sselfsdatasfunc((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeElements cCs|itidS(sl Write null type to data stream. @type n: C{None} @param n: Is ignored. N(sselfs writeTypesASTypessNULL(sselfsn((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeNullscCsy|i|dSWn&tij o|ii|nX|iti |i i t |x|D]}|i|qkWdS(s Write array to the stream. @type a: L{BufferedByteStream} @param a: AMF data. N(sselfswriteReferencesaspyamfsReferenceErrorscontexts addObjects writeTypesASTypessARRAYsstreams write_ulongslensdatas writeElement(sselfsasdata((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeArrays cCs*|iti|iit|dS(s Write number to the data stream. @type n: L{BufferedByteStream} @param n: AMF data. N(sselfs writeTypesASTypessNUMBERsstreams write_doublesfloatsn(sselfsn((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeNumber,scCs?|iti|o|iidn|iiddS(s Write boolean to the data stream. @type b: L{BufferedByteStream} @param b: AMF data. iiN(sselfs writeTypesASTypessBOOLsbsstreams write_uchar(sselfsb((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeBoolean6s cCst|t ot|id}nt|djo|iit|n|ii t||ii |dS(Nsutf8i( s isinstancesss basestringsunicodesencodeslensselfsstreams write_ulongs write_ushortswrite(sselfss((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys _writeStringDs cCst|to|id}n+t|t ot|id}nt|djo|o|iti qn|o|i i ti n|i |dS(s Write string to the data stream. @type s: L{BufferedByteStream} @param s: AMF data. @type writeType: C{bool} @param writeType: Write data type. sutf8iN(s isinstancesssunicodesencodes basestringslens writeTypesselfsASTypess LONGSTRINGsstreams write_ucharsSTRINGs _writeString(sselfsss writeType((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeStringOscCs6|ii|}|iti|ii |dS(s Write reference to the data stream. @type o: L{BufferedByteStream} @param o: AMF data. N( sselfscontextsgetObjectReferencesosidxs writeTypesASTypess REFERENCEsstreams write_ushort(sselfsosidx((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pyswriteReferencefscCs>x7|iD])\}}|i|t|i|q WdS(sp Write C{dict} to the data stream. @type o: C{iterable} @param o: AMF data. N(sos iteritemsskeysvalsselfs writeStringsFalses writeElement(sselfsosvalskey((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys _writeDictrs  cCsy|i|dSWn&tij o|ii|nX|iti ypt gi }|i D]2}t|dttfo||dqhqh~}|djo d}nWntj o}d}nX|ii||i||idS(s Write mixed array to the data stream. @type o: L{BufferedByteStream} @param o: AMF data. Ni(sselfswriteReferencesospyamfsReferenceErrorscontexts addObjects writeTypesASTypess MIXEDARRAYsmaxsappends_[1]sitemssys isinstancesintslongs max_indexs ValueErrorsesstreams write_ulongs _writeDicts_writeEndObject(sselfsoses_[1]sys max_index((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pyswriteMixedArray}s  U   cCs$|iid|itidS(Ns(sselfsstreamswrites writeTypesASTypess OBJECTTERM(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys_writeEndObjectscCst}|tj oN|i|}|tj o.h}x%|D]}t||||} @param o: AMF data. Nsamf3s anonymous(sselfswriteReferencesospyamfsReferenceErrorscontexts addObjects getClassAliass __class__saliassNones writeTypesASTypessOBJECTsmetadatas writeAMF3s TYPEDOBJECTs writeStringsFalses_getObjectAttrss obj_attrss iteritemsskeysvalues writeElements_writeEndObject(sselfsos obj_attrssaliassvalueskey((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeObjects,    cCsMti|}d}|iti|i i |d|i i |dS(s Writes a date to the data stream. @type d: Instance of C{datetime.datetime} @param d: The date to be written. if1000.0N( sutils get_timestampsdssecsstzsselfs writeTypesASTypessDATEsstreams write_doubles write_short(sselfsdstzssecs((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeDates cCsOtii|d}|iti|i i t ||i i |dS(s Write XML to the data stream. @type e: L{BufferedByteStream} @param e: AMF data. sutf-8N( sutilsETstostringsesdatasselfs writeTypesASTypessXMLsstreams write_ulongslenswrite(sselfsesdata((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pyswriteXMLs cCst|id o#dkl}|i|i_n|ii|ti ti |i |ii}|i ti |i|dS(s Writes an element to the datastream in L{AMF3} format. @type data: C{mixed} @param data: The data to be encoded. s amf3_context(samf3N(shasattrsselfscontextspyamfsamf3sContexts amf3_contexts addAMF3Objectsdatas_get_encoder_classsAMF3sstreamsencoders writeTypesASTypess writeElement(sselfsdatasencodersamf3((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys writeAMF3s $(1s__name__s __module__s__doc__sContexts context_classstypessBuiltinFunctionTypesBuiltinMethodTypesNoneTypesboolsintslongsfloats StringTypesspyamfs has_aliassASObjects MixedArraysListTypes TupleTypesdatetimesdatesutilsETs iselements InstanceTypes ObjectTypestype_maps writeTypeswriteUndefinedswriteUnsupporteds_writeElementFuncs writeElements writeNulls writeArrays writeNumbers writeBooleans _writeStringsTrues writeStringswriteReferences _writeDictswriteMixedArrays_writeEndObjects_getObjectAttrss writeObjects writeDateswriteXMLs writeAMF3(((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysEncoders.            %  ccsJt||}x4no,y|iVWqtij oPqXqWdS(s A helper function to decode an AMF0 datastream. @type stream: L{BufferedByteStream} @param stream: AMF0 datastream. @type context: L{Context} @param context: AMF0 Context. iN(sDecodersstreamscontextsdecoders readElementspyamfsEOStream(sstreamscontextsdecoder((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysdecode scOsS|idt}ti}t||}x|D]}|i |q4W|SdS(sq A helper function to encode an element into the AMF0 format. @type element: C{mixed} @param element: The element to encode @type context: L{Context} @param context: AMF0 C{Context} to use for the encoding. This holds previously referenced objects etc. @rtype: C{StringIO} @return: The encoded stream. scontextN( skwargssgetsNonescontextsutilsBufferedByteStreamsbufsEncodersencodersargsselements writeElement(sargsskwargssencoderscontextselementsbuf((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysencodes  s RecordSetcBsMtZdZggeedZdZdZeeeZdZ RS(s/ I represent the RecordSet class used in Flash Remoting to hold (amongst other things) SQL records. @ivar columns: The columns to send. @type columns: List of strings. @ivar items: The 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 recordset. @type service: @ivar id: The id of the recordset. @type id: C{str} @see: U{RecordSet on OSFlash (external) } cCs(||_||_||_||_dS(N(scolumnssselfsitemssservicesid(sselfscolumnssitemssservicesid((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys__init__Ds   c Cstidt|iddddd|id|i}|itj o'|i hdt |id<n|i tj o#|i hd t |i <n|SdS( Ns totalCountscursorisversions initialDatas columnNamess serviceNamesnamesid( spyamfsASObjectslensselfsitemsscolumnssretsservicesNonesupdatesstrsid(sselfsret((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys_get_server_infoJs!'#cCs|d|_|d|_ytd|d|_Wntj ot|_nXy|d|_Wntj ot|_nXdS(Ns columnNamess initialDatasnames serviceNamesid( svalsselfscolumnssitemssdictsservicesKeyErrorsNonesid(sselfsval((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys_set_server_infoVs  cCsd|i|iif}|itj o|d|i7}n|itj o|d|i7}n|dt|7}|SdS(Ns <%s.%s objects id=%ss service=%ss at 0x%x>(sselfs __module__s __class__s__name__sretsidsNonesservice(sselfsret((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys__repr__gs( s__name__s __module__s__doc__sNones__init__s_get_server_infos_set_server_infospropertys serverInfos__repr__(((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys RecordSet1s  sattrss serverInfosmetadatasamf0cCsPyt|}Wntj on$X||jo ||jo|Sn|SdS(sz This is a compatibility function that takes a C{float} and converts it to an C{int} if the values are equal. N(sintsxsys OverflowError(sxsy((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys_check_for_intvssnanicsd|_SdS(Ncs;t|iiddjo|Sni|SdS(Nsnani(sstrsxslowersfindsf2sfunc(sx(sf2(s*build/bdist.linux-x86_64/egg/pyamf/amf0.pysf2s"(sf2sfunc(sfuncsf2((sf2s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys check_nans  (s__doc__sdatetimestypesspyamfsutilsASTypessACTIONSCRIPT_TYPESs__dict__sxs startswithsappends BaseContextsContexts BaseDecodersDecoders BaseEncodersEncodersNonesdecodesencodesobjects RecordSetsregister_classs_check_for_intsfloats ValueErrors check_nan(sdecodes_check_for_ints check_nans RecordSetspyamfsACTIONSCRIPT_TYPESsASTypessdatetimesutilsContextsDecodersencodesxsEncoderstypes((s*build/bdist.linux-x86_64/egg/pyamf/amf0.pys?s6  K : W  C"  PKK8`qhqh pyamf/amf0.py# -*- coding: utf-8 -*- # # Copyright (c) 2007-2008 The PyAMF Project. # See LICENSE for details. """ AMF0 implementation. C{AMF0} supports the basic data types used for the NetConnection, NetStream, LocalConnection, SharedObjects and other classes in the Flash Player. @see: U{Official AMF0 Specification in English (external) } @see: U{Official AMF0 Specification in Japanese (external) } @see: U{AMF documentation on OSFlash (external) } @author: U{Arnar Birgisson} @author: U{Thijs Triemstra} @author: U{Nick Joyce} @since: 0.1.0 """ import datetime, types import pyamf from pyamf import util class ASTypes: """ The AMF/RTMP data encoding format constants. @see: U{Data types on OSFlash (external) } """ #: Represented as 9 bytes: 1 byte for C{0×00} and 8 bytes a double #: representing the value of the number. NUMBER = 0x00 #: 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}. BOOL = 0x01 #: 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}. STRING = 0x02 #: 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}. OBJECT = 0x03 #: MovieClip does not seem to be supported by Remoting. #: It may be used by other AMF clients such as SharedObjects. MOVIECLIP = 0x04 #: 1 single byte, C{0×05} indicates null. NULL = 0x05 #: 1 single byte, C{0×06} indicates null. UNDEFINED = 0x06 #: 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. REFERENCE = 0x07 #: 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. MIXEDARRAY = 0x08 #: @see: L{OBJECT} OBJECTTERM = 0x09 #: 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. ARRAY = 0x0a #: 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. DATE = 0x0b #: LongString is reserved for strings larger then M{2^16} characters long. It #: is represented as C{00x0C} then a LongUTF. LONGSTRING = 0x0c #: 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. UNSUPPORTED = 0x0d #: Remoting Server -> Client only. #: @see: L{RecordSet} #: @see: U{RecordSet structure on OSFlash (external) #: } RECORDSET = 0x0e #: 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. XML = 0x0f #: 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. TYPEDOBJECT = 0x10 #: An AMF message sent from an AVM+ client such as the Flash Player 9 may break #: out into L{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). AMF3 = 0x11 #: List of available ActionScript types in AMF0. ACTIONSCRIPT_TYPES = [] for x in ASTypes.__dict__: if not x.startswith('_'): ACTIONSCRIPT_TYPES.append(ASTypes.__dict__[x]) del x class Context(pyamf.BaseContext): """ I hold the AMF0 context for en/decoding streams. AMF0 object references start at index 1. """ def clear(self): """ Resets the context. The C{amf3_objs} var keeps a list of objects that were encoded in L{AMF3}. """ pyamf.BaseContext.clear(self) self.amf3_objs = [] self.rev_amf3_objs = {} if hasattr(self, 'amf3_context'): self.amf3_context.clear() def _getObject(self, ref): return self.objects[ref + 1] def __copy__(self): copy = self.__class__() copy.amf3_objs = self.amf3_objs copy.rev_amf3_objs = self.rev_amf3_objs return copy def getAMF3ObjectReference(self, obj): """ Gets a reference for an object. @raise ReferenceError: Object reference could not be found. """ try: return self.rev_amf3_objs[id(obj)] except KeyError: raise ReferenceError def addAMF3Object(self, 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}. """ self.amf3_objs.append(obj) idx = len(self.amf3_objs) - 1 self.rev_amf3_objs[id(obj)] = idx return idx class Decoder(pyamf.BaseDecoder): """ Decodes an AMF0 stream. """ context_class = Context # XXX nick: Do we need to support ASTypes.MOVIECLIP here? type_map = { ASTypes.NUMBER: 'readNumber', ASTypes.BOOL: 'readBoolean', ASTypes.STRING: 'readString', ASTypes.OBJECT: 'readObject', ASTypes.NULL: 'readNull', ASTypes.UNDEFINED: 'readUndefined', ASTypes.REFERENCE: 'readReference', ASTypes.MIXEDARRAY: 'readMixedArray', ASTypes.ARRAY: 'readList', ASTypes.DATE: 'readDate', ASTypes.LONGSTRING: 'readLongString', # TODO: do we need a special value here? ASTypes.UNSUPPORTED:'readNull', ASTypes.XML: 'readXML', ASTypes.TYPEDOBJECT:'readTypedObject', ASTypes.AMF3: 'readAMF3' } def readType(self): """ Read and returns the next byte in the stream and determine its type. @raise DecodeError: AMF0 type not recognized. @return: AMF0 type. """ type = self.stream.read_uchar() if type not in ACTIONSCRIPT_TYPES: raise pyamf.DecodeError("Unknown AMF0 type 0x%02x at %d" % ( type, self.stream.tell() - 1)) return type def readNumber(self): """ 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} """ return _check_for_int(self.stream.read_double()) def readBoolean(self): """ Reads a ActionScript C{Boolean} value. @rtype: C{bool} @return: Boolean. """ return bool(self.stream.read_uchar()) def readNull(self): """ Reads a ActionScript C{null} value. @return: C{None} @rtype: C{None} """ return None def readUndefined(self): """ Reads an ActionScript C{undefined} value. @return: L{Undefined} """ return pyamf.Undefined def readMixedArray(self): """ Read mixed array. @rtype: C{dict} @return: C{dict} read from the stream """ len = self.stream.read_ulong() obj = pyamf.MixedArray() self.context.addObject(obj) self._readObject(obj) ikeys = [] for key in obj.keys(): try: ikey = int(key) ikeys.append((key, ikey)) obj[ikey] = obj[key] del obj[key] except ValueError: # XXX: do we want to ignore this? pass ikeys.sort() return obj def readList(self): """ Read a C{list} from the data stream. @rtype: C{list} @return: C{list} """ obj = [] self.context.addObject(obj) len = self.stream.read_ulong() for i in xrange(len): obj.append(self.readElement()) return obj def readTypedObject(self): """ Reads an ActionScript object from the stream and attempts to 'cast' it. @see: L{load_class} """ classname = self.readString() alias = pyamf.load_class(classname) ret = alias() self.context.addObject(ret) self._readObject(ret, alias) return ret def readAMF3(self): """ Read AMF3 elements from the data stream. @rtype: C{mixed} @return: The AMF3 element read from the stream """ if not hasattr(self.context, 'amf3_context'): from pyamf import amf3 self.context.amf3_context = amf3.Context() decoder = pyamf._get_decoder_class(pyamf.AMF3)(self.stream, self.context.amf3_context) element = decoder.readElement() self.context.addAMF3Object(element) return element def readString(self): """ Reads a string from the data stream. @rtype: C{str} @return: string """ len = self.stream.read_ushort() return self.stream.read_utf8_string(len) def _readObject(self, obj, alias=None): attrs = [] if alias is not None: attrs = alias.getAttrs(obj) key = self.readString() ot = chr(ASTypes.OBJECTTERM) obj_attrs = dict() while self.stream.peek() != ot: obj_attrs[key] = self.readElement() key = self.readString() # discard the end marker (ASTypes.OBJECTTERM) self.stream.read(len(ot)) if attrs is None: attrs = obj_attrs.keys() if alias: if hasattr(obj, '__setstate__'): obj.__setstate__(obj_attrs) return for key in filter(lambda x: x in attrs, obj_attrs.keys()): setattr(obj, key, obj_attrs[key]) else: f = obj.__setattr__ if isinstance(obj, (list, dict)): f = obj.__setitem__ for key, value in obj_attrs.iteritems(): f(key, value) return def readObject(self): """ Reads an object from the data stream. @rtype: L{ASObject} """ obj = pyamf.ASObject() self.context.addObject(obj) self._readObject(obj) return obj def readReference(self): """ Reads a reference from the data stream. """ idx = self.stream.read_ushort() return self.context.getObject(idx) def readDate(self): """ 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. """ ms = self.stream.read_double() / 1000.0 tz = self.stream.read_short() # Timezones are ignored d = datetime.datetime.utcfromtimestamp(ms) self.context.addObject(d) return d def readLongString(self): """ Read UTF8 string. """ len = self.stream.read_ulong() return self.stream.read_utf8_string(len) def readXML(self): """ Read XML. """ data = self.readLongString() xml = util.ET.fromstring(data) self.context.addObject(xml) return xml class Encoder(pyamf.BaseEncoder): """ Encodes an AMF0 stream. """ context_class = Context type_map = [ ((types.BuiltinFunctionType, types.BuiltinMethodType,), "writeUnsupported"), ((types.NoneType,), "writeNull"), ((bool,), "writeBoolean"), ((int,long,float), "writeNumber"), ((types.StringTypes,), "writeString"), ((pyamf.has_alias,pyamf.ASObject), "writeObject"), ((pyamf.MixedArray,), "writeMixedArray"), ((types.ListType, types.TupleType,), "writeArray"), ((datetime.date, datetime.datetime), "writeDate"), ((util.ET.iselement,), "writeXML"), ((lambda x: x is pyamf.Undefined,), "writeUndefined"), ((types.InstanceType,types.ObjectType,), "writeObject"), ] def writeType(self, type): """ Writes the type to the stream. @type type: C{int} @param type: ActionScript type. @raise pyamf.EncodeError: AMF0 type is not recognized. """ if type not in ACTIONSCRIPT_TYPES: raise pyamf.EncodeError("Unknown AMF0 type 0x%02x at %d" % ( type, self.stream.tell() - 1)) self.stream.write_uchar(type) def writeUndefined(self, data): """ Writes the undefined data type to the stream. """ self.writeType(ASTypes.UNDEFINED) def writeUnsupported(self, data): """ Writes unsupported data type to the stream. """ self.writeType(ASTypes.UNSUPPORTED) def _writeElementFunc(self, data): """ Gets a function based on the type of data. @see: L{pyamf.BaseEncoder._writeElementFunc} """ # There is a very specific use case that we must check for. # In the context there is an array of amf3_objs that contain # references to objects that are to be encoded in amf3. try: self.context.getAMF3ObjectReference(data) return self.writeAMF3 except ReferenceError: pass return pyamf.BaseEncoder._writeElementFunc(self, data) def writeElement(self, data): """ Writes the data. @type data: C{mixed} @param data: The data to be encoded to the AMF0 data stream. @raise EncodeError: Unable to encode the data. """ func = self._writeElementFunc(data) if func is None: # XXX nick: Should we be generating a warning here? self.writeUnsupported(data) else: try: func(data) except (KeyboardInterrupt, SystemExit): raise except pyamf.EncodeError: raise except: raise raise pyamf.EncodeError, "Unable to encode '%r'" % data def writeNull(self, n): """ Write null type to data stream. @type n: C{None} @param n: Is ignored. """ self.writeType(ASTypes.NULL) def writeArray(self, a): """ Write array to the stream. @type a: L{BufferedByteStream} @param a: AMF data. """ try: self.writeReference(a) return except pyamf.ReferenceError: self.context.addObject(a) self.writeType(ASTypes.ARRAY) self.stream.write_ulong(len(a)) for data in a: self.writeElement(data) def writeNumber(self, n): """ Write number to the data stream. @type n: L{BufferedByteStream} @param n: AMF data. """ self.writeType(ASTypes.NUMBER) self.stream.write_double(float(n)) def writeBoolean(self, b): """ Write boolean to the data stream. @type b: L{BufferedByteStream} @param b: AMF data. """ self.writeType(ASTypes.BOOL) if b: self.stream.write_uchar(1) else: self.stream.write_uchar(0) def _writeString(self, s): if not isinstance(s, basestring): s = unicode(s).encode('utf8') if len(s) > 0xffff: self.stream.write_ulong(len(s)) else: self.stream.write_ushort(len(s)) self.stream.write(s) def writeString(self, s, writeType=True): """ Write string to the data stream. @type s: L{BufferedByteStream} @param s: AMF data. @type writeType: C{bool} @param writeType: Write data type. """ if isinstance(s, unicode): s = s.encode('utf8') elif not isinstance(s, basestring): s = unicode(s).encode('utf8') if len(s) > 0xffff: if writeType: self.writeType(ASTypes.LONGSTRING) else: if writeType: self.stream.write_uchar(ASTypes.STRING) self._writeString(s) def writeReference(self, o): """ Write reference to the data stream. @type o: L{BufferedByteStream} @param o: AMF data. """ idx = self.context.getObjectReference(o) self.writeType(ASTypes.REFERENCE) self.stream.write_ushort(idx) def _writeDict(self, o): """ Write C{dict} to the data stream. @type o: C{iterable} @param o: AMF data. """ for key, val in o.iteritems(): self.writeString(key, False) self.writeElement(val) def writeMixedArray(self, o): """ Write mixed array to the data stream. @type o: L{BufferedByteStream} @param o: AMF data. """ try: self.writeReference(o) return except pyamf.ReferenceError: self.context.addObject(o) self.writeType(ASTypes.MIXEDARRAY) # TODO: optimise this # work out the highest integer index try: # list comprehensions to save the day max_index = max([y[0] for y in o.items() if isinstance(y[0], (int, long))]) if max_index < 0: max_index = 0 except ValueError, e: max_index = 0 self.stream.write_ulong(max_index) self._writeDict(o) self._writeEndObject() def _writeEndObject(self): # Write a null string, this is an optimisation so that we don't # have to waste precious cycles by encoding the string etc. self.stream.write('\x00\x00') self.writeType(ASTypes.OBJECTTERM) def _getObjectAttrs(self, o, alias): obj_attrs = None if alias is not None: attrs = alias.getAttrs(o) if attrs is not None: obj_attrs = {} for at in attrs: obj_attrs[at] = getattr(o, at) if obj_attrs is None: obj_attrs = util.get_attrs(o) if obj_attrs is None: raise pyamf.EncodeError('Unable to determine object attributes') return obj_attrs def writeObject(self, o): """ Write object to the stream. @type o: L{BufferedByteStream} @param o: AMF data. """ try: self.writeReference(o) return except pyamf.ReferenceError: self.context.addObject(o) alias = self.context.getClassAlias(o.__class__) if alias is None: self.writeType(ASTypes.OBJECT) else: if 'amf3' in alias.metadata: self.writeAMF3(o) return if 'anonymous' in alias.metadata: self.writeType(ASTypes.OBJECT) else: self.writeType(ASTypes.TYPEDOBJECT) self.writeString(alias.alias, False) obj_attrs = self._getObjectAttrs(o, alias) for key, value in obj_attrs.iteritems(): self.writeString(key, False) self.writeElement(value) self._writeEndObject() def writeDate(self, d): """ Writes a date to the data stream. @type d: Instance of C{datetime.datetime} @param d: The date to be written. """ # According to the Red5 implementation of AMF0, dates references are # created, but not used secs = util.get_timestamp(d) tz = 0 self.writeType(ASTypes.DATE) self.stream.write_double(secs * 1000.0) self.stream.write_short(tz) def writeXML(self, e): """ Write XML to the data stream. @type e: L{BufferedByteStream} @param e: AMF data. """ data = util.ET.tostring(e, 'utf-8') self.writeType(ASTypes.XML) self.stream.write_ulong(len(data)) self.stream.write(data) def writeAMF3(self, data): """ Writes an element to the datastream in L{AMF3} format. @type data: C{mixed} @param data: The data to be encoded. """ if not hasattr(self.context, 'amf3_context'): from pyamf import amf3 self.context.amf3_context = amf3.Context() self.context.addAMF3Object(data) encoder = pyamf._get_encoder_class(pyamf.AMF3)(self.stream, self.context.amf3_context) self.writeType(ASTypes.AMF3) encoder.writeElement(data) def decode(stream, context=None): """ A helper function to decode an AMF0 datastream. @type stream: L{BufferedByteStream} @param stream: AMF0 datastream. @type context: L{Context} @param context: AMF0 Context. """ decoder = Decoder(stream, context) while 1: try: yield decoder.readElement() except pyamf.EOStream: break def encode(*args, **kwargs): """ A helper function to encode an element into the AMF0 format. @type element: C{mixed} @param element: The element to encode @type context: L{Context} @param context: AMF0 C{Context} to use for the encoding. This holds previously referenced objects etc. @rtype: C{StringIO} @return: The encoded stream. """ context = kwargs.get('context', None) buf = util.BufferedByteStream() encoder = Encoder(buf, context) for element in args: encoder.writeElement(element) return buf class RecordSet(object): """ I represent the RecordSet class used in Flash Remoting to hold (amongst other things) SQL records. @ivar columns: The columns to send. @type columns: List of strings. @ivar items: The 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 recordset. @type service: @ivar id: The id of the recordset. @type id: C{str} @see: U{RecordSet on OSFlash (external) } """ def __init__(self, columns=[], items=[], service=None, id=None): self.columns = columns self.items = items self.service = service self.id = id def _get_server_info(self): ret = pyamf.ASObject(totalCount=len(self.items), cursor=1, version=1, initialData=self.items, columnNames=self.columns) if self.service is not None: ret.update({'serviceName': str(self.service['name'])}) if self.id is not None: ret.update({'id':str(self.id)}) return ret def _set_server_info(self, val): self.columns = val['columnNames'] self.items = val['initialData'] try: # TODO nick: find relevant service and link in here. self.service = dict(name=val['serviceName']) except KeyError: self.service = None try: self.id = val['id'] except KeyError: self.id = None serverInfo = property(_get_server_info, _set_server_info) def __repr__(self): ret = '<%s.%s object' % (self.__module__, self.__class__.__name__) if self.id is not None: ret += ' id=%s' % self.id if self.service is not None: ret += ' service=%s' % self.service ret += ' at 0x%x>' % id(self) return ret pyamf.register_class(RecordSet, 'RecordSet', attrs=['serverInfo'], metadata=['amf0']) def _check_for_int(x): """ This is a compatibility function that takes a C{float} and converts it to an C{int} if the values are equal. """ try: y = int(x) except OverflowError: pass else: # There is no way in AMF0 to distinguish between integers and floats if x == x and y == x: return y return x # check for some Python 2.3 problems with floats try: float('nan') except ValueError: pass else: if float('nan') == 0: def check_nan(func): def f2(x): if str(x).lower().find('nan') >= 0: return x return f2.func(x) f2.func = func return f2 _check_for_int = check_nan(_check_for_int) PKQ8MMpyamf/amf3.pyc; OHc@sdZdkZdkZdkZdkZdklZy eWn ej odkl ZnXdfdYZ gZ x:e i D]/Z e id oe ie i e qqW[ dZdfd YZd efd YZd efd YZdeieefdYZdefdYZdeifdYZdeifdYZdeifdYZedZdZ dZ!dS(s AMF3 implementation. C{AMF3} is the default serialization for U{ActionScript} 3.0 and provides various advantages over L{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) } @see: U{Official AMF3 Specification in Japanese (external) } @see: U{AMF3 documentation on OSFlash (external) } @author: U{Arnar Birgisson} @author: U{Thijs Triemstra} @author: U{Nick Joyce} @since: 0.1.0 N(sutil(sSetsASTypescBs\tZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZRS(s~ All AMF3 data types used in ActionScript 3.0. AMF represents ActionScript objects by a single byte representing type, and then by a type-specific byte array that may be of fixed length, may contain length information, or may come with its own end code. @see: U{AMF3 data types on OSFlash (external) } iiiiiiiiii i i i (s__name__s __module__s__doc__s UNDEFINEDsNULLs BOOL_FALSEs BOOL_TRUEsINTEGERsNUMBERsSTRINGsXMLsDATEsARRAYsOBJECTs XMLSTRINGs BYTEARRAY(((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysASTypes(s  s_isObjectEncodingcBs&tZdZdZdZdZdZRS(s AMF object encodings. iiii(s__name__s __module__s__doc__sSTATICsEXTERNALsDYNAMICsPROXY(((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysObjectEncodings s DataOutputcBs}tZdZdZdZdZdZdZdZdZ e dZ d Z d Z d Zd ZRS( s 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) } cCs0t|tpt||_|i|_dS(s{ @param encoder: Encoder containing the stream. @type encoder: L{amf3.Encoder} N(s isinstancesencodersEncodersAssertionErrorsselfsstream(sselfsencoder((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys__init__s cCsUt|to5|tjo|iidqQ|iidn tddS(s$ Writes a Boolean value. @type value: C{bool} @param value: A 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 is found. iisNon-boolean value foundN(s isinstancesvaluesboolsTruesselfsstreams write_uchars ValueError(sselfsvalue((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys writeBooleans  cCs|ii|dS(s= Writes a byte. @type value: C{int} N(sselfsstreams write_charsvalue(sselfsvalue((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys writeBytescCs|ii|dS(s} Writes an IEEE 754 double-precision (64-bit) floating point number. @type value: C{number} N(sselfsstreams write_doublesvalue(sselfsvalue((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys writeDoublescCs|ii|dS(s| Writes an IEEE 754 single-precision (32-bit) floating point number. @type value: C{float} N(sselfsstreams write_floatsvalue(sselfsvalue((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys writeFloatscCs|ii|dS(sN Writes a 32-bit signed integer. @type value: C{int} N(sselfsstreams write_longsvalue(sselfsvalue((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pyswriteIntscCs#|iit|i|dS(s 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. @see: U{Supported character sets on Livedocs (external) } N(sselfsstreamswritesunicodesvaluesencodescharset(sselfsvaluescharset((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pyswriteMultiBytes cCs|ii||dS(s Writes an object to data stream in AMF serialized format. @param value: The object to be serialized. @type use_references: C{bool} @param use_references: N(sselfsencoders writeElementsvaluesuse_references(sselfsvaluesuse_references((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys writeObjectscCs|ii|dS(sy Writes a 16-bit integer. @type value: C{int} @param value: A byte value as an integer. N(sselfsstreams write_shortsvalue(sselfsvalue((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys writeShortscCs|ii|dS(s Writes a 32-bit unsigned integer. @type value: C{int} @param value: A byte value as an unsigned integer. N(sselfsstreams write_ulongsvalue(sselfsvalue((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pyswriteUnsignedIntscCsst|t ot|d}nti}|i||i}|i i t ||i i |dS(s7 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. sutf8N(s isinstancesvaluesunicodesutilsBufferedByteStreamsbufswrite_utf8_stringsgetvaluesbytessselfsstreams write_ushortslenswrite(sselfsvaluesbytessbuf((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pyswriteUTFs    cCsCt}t|to |}nt|d}|ii|dS(s 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. sutf8N(sNonesvals isinstancesvaluesunicodesselfsstreamswrite_utf8_string(sselfsvaluesval((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys writeUTFBytes.s  (s__name__s __module__s__doc__s__init__s writeBooleans writeBytes writeDoubles writeFloatswriteIntswriteMultiBytesTrues writeObjects writeShortswriteUnsignedIntswriteUTFs writeUTFBytes(((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys DataOutputs      s DataInputcBstZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZRS(s1 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) } cCs0t|tpt||_|i|_dS(s @param decoder: AMF3 decoder containing the stream. @type decoder: L{amf3.Decoder} N(s isinstancesdecodersDecodersAssertionErrorsselfsstream(sselfsdecoder((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys__init__Is cCsL|iid}|djotSn"|djotSn tddS(s Read Boolean. @raise ValueError: Error reading Boolean. @rtype: C{bool} @return: A Boolean value, C{True} if the byte is nonzero, C{False} otherwise. isssError reading booleanN(sselfsstreamsreadsbytesFalsesTrues ValueError(sselfsbyte((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys readBooleanSs  cCs|iiSdS(s Reads a signed byte. @rtype: C{int} @return: The returned value is in the range -128 to 127. N(sselfsstreams read_char(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysreadByteescCs|iiSdS(s 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. N(sselfsstreams read_double(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys readDoublenscCs|iiSdS(s 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. N(sselfsstreams read_float(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys readFloatxscCs|iiSdS(s Reads a signed 32-bit integer from the data stream. @rtype: C{int} @return: The returned value is in the range -2147483648 to 2147483647. N(sselfsstreams read_long(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysreadIntscCs#|ii|}t||SdS(s 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. N(sselfsstreamsreadslengthsbytessunicodescharset(sselfslengthscharsetsbytes((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys readMultiBytes cCs|iiSdS(sb Reads an object from the data stream. @return: The deserialized object. N(sselfsdecoders readElement(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys readObjectscCs|iiSdS(s Reads a signed 16-bit integer from the data stream. @rtype: C{uint} @return: The returned value is in the range -32768 to 32767. N(sselfsstreams read_short(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys readShortscCs|iiSdS(s Reads an unsigned byte from the data stream. @rtype: C{uint} @return: The returned value is in the range 0 to 255. N(sselfsstreams read_uchar(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysreadUnsignedBytescCs|iiSdS(s Reads an unsigned 32-bit integer from the data stream. @rtype: C{uint} @return: The returned value is in the range 0 to 4294967295. N(sselfsstreams read_ulong(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysreadUnsignedIntscCs|iiSdS(s Reads an unsigned 16-bit integer from the data stream. @rtype: C{uint} @return: The returned value is in the range 0 to 65535. N(sselfsstreams read_ushort(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysreadUnsignedShortscCs#|ii}|ii|SdS(s 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. N(sselfsstreams read_ushortslengthsread_utf8_string(sselfslength((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysreadUTFs cCs|i|dSdS(s^ 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}. sutf-8N(sselfs readMultiByteslength(sselfslength((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys readUTFBytess (s__name__s __module__s__doc__s__init__s readBooleansreadBytes readDoubles readFloatsreadInts readMultiBytes readObjects readShortsreadUnsignedBytesreadUnsignedIntsreadUnsignedShortsreadUTFs readUTFBytes(((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys DataInput?s     s ByteArraycBs2tZdZdZdZdZdZRS(sZ 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. Possible uses of the C{ByteArray} class: - Creating a custom protocol to connect to a client. - Writing your own AMF/Remoting packet. - Optimizing the size of your data by using custom data types. @see: U{ByteArray on Livedocs (external) } cOss|idt|_tii|||t i|t ||it i|t ||it |_dS(Nscontext(skwargsspopsContextsselfscontextsutilsBufferedByteStreams__init__sargss DataInputsDecoders DataOutputsEncodersFalses compressed(sselfsargsskwargs((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys__init__s cCsAt|tot|i|iSnt|i|SdS(N(s isinstancesothers ByteArrayscmpsselfsgetvalues_buffer(sselfsother((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys__cmp__scCsG|i}|io)ti|}|dd|d}n|SdS(Nisi(sselfsgetvaluesbufs compressedszlibscompress(sselfsbuf((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys__str__s   cCs t|_dS(s> Forces compression of the underlying stream. N(sTruesselfs compressed(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pyscompresss(s__name__s __module__s__doc__s__init__s__cmp__s__str__scompress(((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys ByteArrays   sClassDefinitioncBsbtZdZeidZdZeeZdZ dZ dZ ee Z dZ RS(sh I contain meta relating to the class definition. @ivar alias: The alias to this class definition. If this value is C{None}, or an empty string, the class is considered to be anonymous. @type alias: L{ClassAlias} @ivar encoding: The type of encoding to use when serializing the object. @type encoding: C{int} cCs|tdfjo t|_n3t|tio ||_nti||_||_|io|iitj o|ii|_ n g|_ dS(Ns( saliassNonesselfs isinstancespyamfs ClassAliassget_class_aliassencodingsattrss static_attrs(sselfsaliassencoding((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys__init__s   cCsD|itjodSnd|iijodSnt|iSdS(Nss anonymous(sselfsaliassNonesmetadatasstr(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys _get_name-s cCs2|itdfjo tiSn|iiSdS(s If C{alias} is C{None}, an L{anonymous class} is returned, otherwise the class is loaded externally. sN(sselfsaliassNonespyamfsASObjects getClassAliassklass(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys _getClass9s cCsUt|d o9|idjotidnti|i|_n|iSdS(s, Gets the class alias that is held by this definition. @see: L{load_class}. @raise UnknownClassAlias: Anonymous class definitions do not have class aliases. @rtype: L{ClassAlias} @return: Class definition. s_aliasss5Anonymous class definitions do not have class aliasesN(shasattrsselfsnamespyamfsUnknownClassAliass load_classsaliass_alias(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys getClassAliasDs cCs5t|do |iSn|i|_|iSdS(sL Gets the referenced class that is held by this definition. s_aliasN(shasattrsselfs_aliass _getClasss_klass(sself((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysgetClassWs  cCsti||i}t}}|io|iio4h}x+|iiD]}t ||||y|ii|SWn#tj otid|nXdS(s Return string reference. @type s: C{str} @param s: The referenced string. @raise ReferenceError: The string reference could not be found. @return: The reference index to the string. @rtype: C{int} s!Reference for string %r not foundN(sselfsstringssindexsss ValueErrorspyamfsReferenceError(sselfss((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysgetStringReferences cCst|t o tnt|djo tdny|ii|SWn4tj o(|ii |t|idSnXdS(sD 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. @raise ValueError: Trying to store a reference to an empty string. @rtype: C{int} @return: The reference index. is+Cannot store a reference to an empty stringiN( s isinstancesss basestrings TypeErrorslens ValueErrorsselfsstringssindexsappend(sselfss((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pys addStrings   cCs9y|i|SWn#tj otid|nXdS(s Return class reference. @raise ReferenceError: The class reference could not be found. @return: Class reference. sClass reference %d not foundN(sselfsclassessrefs IndexErrorspyamfsReferenceError(sselfsref((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysgetClassDefinitions cCst|t ot|ttifo<y|i|SWqtj ot i d|qXn_t|ti ti foBy|i |iSWqtj ot i d|iqXntd|n?y|it|SWn&tj ot i d|inXdS(sJ Return class definition reference. @type class_def: L{ClassDefinition} or C{instance} or C{class} @param class_def: The class definition reference to be found. @raise ReferenceError: The reference could not be found. @return: The reference to C{class_def}. @rtype: C{int} s/Reference for class definition for %s not founds unable to determine class for %rs Reference for class %s not foundN(s isinstances class_defsClassDefinitionstypestypess ClassTypesselfsrev_class_defssKeyErrorspyamfsReferenceErrors InstanceTypes ObjectTypes class_defss __class__s TypeErrorsids ValueErrorsklass(sselfs class_def((s*build/bdist.linux-x86_64/egg/pyamf/amf3.pysgetClassDefinitionReferences" cCsy|it|SWnstj og|ii|t|id}||i t|<||i |i <||it|i <|SnXdS(s6 Creates a reference to C{class_def}. iN( sselfsrev_class_defssids class_defsKeyErrorsclassessappendslensidxs rev_classess class_defss __class__(s