ó FRTc@sºdZddlZddlZddlmZddlmZddlmZddl m Z de fd„ƒYZ d e fd „ƒYZ d e fd „ƒYZd efd„ƒYZdS(sX SQS Message A Message represents the data stored in an SQS queue. The rules for what is allowed within an SQS Message are here: http://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QuerySendMessage.html So, at it's simplest level a Message just needs to allow a developer to store bytes in it and get the bytes back out. However, to allow messages to have richer semantics, the Message class must support the following interfaces: The constructor for the Message class must accept a keyword parameter "queue" which is an instance of a boto Queue object and represents the queue that the message will be stored in. The default value for this parameter is None. The constructor for the Message class must accept a keyword parameter "body" which represents the content or body of the message. The format of this parameter will depend on the behavior of the particular Message subclass. For example, if the Message subclass provides dictionary-like behavior to the user the body passed to the constructor should be a dict-like object that can be used to populate the initial state of the message. The Message class must provide an encode method that accepts a value of the same type as the body parameter of the constructor and returns a string of characters that are able to be stored in an SQS message body (see rules above). The Message class must provide a decode method that accepts a string of characters that can be stored (and probably were stored!) in an SQS message and return an object of a type that is consistent with the "body" parameter accepted on the class constructor. The Message class must provide a __len__ method that will return the size of the encoded message that would be stored in SQS based on the current state of the Message object. The Message class must provide a get_body method that will return the body of the message in the same format accepted in the constructor of the class. The Message class must provide a set_body method that accepts a message body in the same format accepted by the constructor of the class. This method should alter to the internal state of the Message object to reflect the state represented in the message body parameter. The Message class must provide a get_body_encoded method that returns the current body of the message in the format in which it would be stored in SQS. iÿÿÿÿN(tStringIO(t Attributes(tMessageAttributes(tSQSDecodeErrort RawMessagecBs€eZdZddd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „ZRS(s Base class for SQS messages. RawMessage does not encode the message in any way. Whatever you store in the body of the message is what will be written to SQS and whatever is returned from SQS is stored directly into the body of the message. tcCs\||_|j|ƒd|_d|_d|_t|ƒ|_t|ƒ|_ d|_ dS(N( tqueuetset_bodytNonetidtreceipt_handletmd5Rt attributesRtmessage_attributestmd5_message_attributes(tselfRtbody((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyt__init__Ss     cCst|j|jƒƒS(N(tlentencodet_body(R((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyt__len__]scCs*|dkr|jS|dkr&|jSdS(Nt AttributetMessageAttribute(R R R(Rtnametattrst connection((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyt startElement`s   cCs|dkr|j|ƒnp|dkr4||_nX|dkrL||_n@|dkrd||_n(|dkr|||_nt|||ƒdS(NtBodyt MessageIdt ReceiptHandlet MD5OfBodytMD5OfMessageAttributes(RR R R Rtsetattr(RRtvalueR((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyt endElementgs         cCs |j|j|jƒƒƒdS(N(Rtdecodetget_body(RR((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pytendNodeuscCs|S(s8Transform body object into serialized byte array format.((RR"((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyRxscCs|S(s/Transform seralized byte array into any object.((RR"((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR$|scCs ||_dS(s@Override the current body for this object, using decoded format.N(R(RR((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR€scCs|jS(N(R(R((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR%„scCs|j|jƒƒS(sí This method is really a semi-private method used by the Queue.write method when writing the contents of the message to SQS. You probably shouldn't need to call this method in the normal course of events. (RR%(R((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pytget_body_encoded‡scCs|jr|jj|ƒSdS(N(Rtdelete_message(R((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pytdeletes cCs/|jr+|jjj|j|j|ƒndS(N(RRtchange_message_visibilityR (Rtvisibility_timeout((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pytchange_visibility“s N(t__name__t __module__t__doc__RRRRR#R&RR$RR%R'R)R,(((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyRKs          tMessagecBs eZdZd„Zd„ZRS(sz The default Message class used for SQS queues. This class automatically encodes/decodes the message body using Base64 encoding to avoid any illegal characters in the message body. See: https://forums.aws.amazon.com/thread.jspa?threadID=13067 for details on why this is a good idea. The encode/decode is meant to be transparent to the end-user. cCstj|jdƒƒjdƒS(Nsutf-8(tbase64t b64encodeRR$(RR"((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR¥scCsDy%tj|jdƒƒjdƒ}Wntjjdƒ|SX|S(Nsutf-8sUnable to decode message(R1t b64decodeRR$tbototlogtwarning(RR"((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR$¨s %(R-R.R/RR$(((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR0™s  t MHMessagecBs†eZdZd d d d„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zd d „ZRS(sX The MHMessage class provides a message that provides RFC821-like headers like this: HeaderName: HeaderValue The encoding/decoding of this is handled automatically and after the message body has been read, the message instance can be treated like a mapping object, i.e. m['HeaderName'] would return 'HeaderValue'. cCs>|dks|dkr!i}ntt|ƒj||ƒdS(NR(RtsuperR7R(RRRt xml_attrs((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR¼s cCsžyi}t|ƒ}|jƒ}x\|r|jdƒ}|d|!}||djƒ}|jƒ||jƒ<|jƒ}q$WWntd|ƒ‚nX|S(Nt:iisUnable to decode message(RtreadlinetfindtstripR(RR"tmsgtfptlinetdelimtkey((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR$Ás    cCs=d}x0|jƒD]"}|d|d|df}qW|S(NRs%s: %s ii(titems(RR"tstitem((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyRÐs cCs ||jkS(N(R(RRB((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyt __contains__ÖscCs*||jkr|j|St|ƒ‚dS(N(RtKeyError(RRB((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyt __getitem__Ùs cCs!||j|<|j|jƒdS(N(RR(RRBR"((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyt __setitem__ßs cCs |jjƒS(N(Rtkeys(R((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyRJãscCs |jjƒS(N(Rtvalues(R((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyRKæscCs |jjƒS(N(RRC(R((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyRCéscCs ||jkS(N(R(RRB((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pythas_keyìscCs$|jj|ƒ|j|jƒdS(N(RtupdateR(Rtd((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyRMïscCs|jj||ƒS(N(Rtget(RRBtdefault((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyROósN(R-R.R/RRR$RRFRHRIRJRKRCRLRMRO(((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR7°s           tEncodedMHMessagecBs eZdZd„Zd„ZRS(sN The EncodedMHMessage class provides a message that provides RFC821-like headers like this: HeaderName: HeaderValue This variation encodes/decodes the body of the message in base64 automatically. The message instance can be treated like a mapping object, i.e. m['HeaderName'] would return 'HeaderValue'. cCsTy%tj|jdƒƒjdƒ}Wntd|ƒ‚nXtt|ƒj|ƒS(Nsutf-8sUnable to decode message(R1R3RR$RR8RQ(RR"((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR$s %cCs7tt|ƒj|ƒ}tj|jdƒƒjdƒS(Nsutf-8(R8RQRR1R2R$(RR"((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyR s(R-R.R/R$R(((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyRQös  (R/R1R4t boto.compatRtboto.sqs.attributesRtboto.sqs.messageattributesRtboto.exceptionRtobjectRR0R7RQ(((s=/opt/freeware/lib/python2.7/site-packages/boto/sqs/message.pyt@s  NF