ó
č?F[c           @   sR   d  d l  Z  d  d l Z d  d l m Z d  d l m Z d e f d     YZ d S(   iĸĸĸĸN(   t
   RawMessage(   t   SQSDecodeErrort
   BigMessagec           B   sM   e  Z d  Z d d d d  Z d   Z d   Z d   Z d   Z d   Z	 RS(   są  
    The BigMessage class provides large payloads (up to 5GB)
    by storing the payload itself in S3 and then placing a reference
    to the S3 object in the actual SQS message payload.

    To create a BigMessage, you should create a BigMessage object
    and pass in a file-like object as the ``body`` param and also
    pass in the an S3 URL specifying the bucket in which to store
    the message body::

        import boto.sqs
        from boto.sqs.bigmessage import BigMessage

        sqs = boto.sqs.connect_to_region('us-west-2')
        queue = sqs.get_queue('myqueue')
        fp = open('/path/to/bigmessage/data')
        msg = BigMessage(queue, fp, 's3://mybucket')
        queue.write(msg)

    Passing in a fully-qualified S3 URL (e.g. s3://mybucket/foo)
    is interpreted to mean that the body of the message is already
    stored in S3 and the that S3 URL is then used directly with no
    content uploaded by BigMessage.
    c         C   s&   | |  _  t t |   j | |  d  S(   N(   t   s3_urlt   superR   t   __init__(   t   selft   queuet   bodyR   (    (    s2   lib/python2.7/site-packages/boto/sqs/bigmessage.pyR   8   s    	c         C   s   d  } } | r | j d  rn | d j d d  } | d } t |  d k r | d rk | d } qk q q d } t | |    n  | | f S(   Ns   s3://i   t   /i   i    s(   s3_url parameter should start with s3://(   t   Nonet
   startswitht   splitt   lenR   (   R   R   t   bucket_namet   key_namet   s3_componentst   msg(    (    s2   lib/python2.7/site-packages/boto/sqs/bigmessage.pyt   _get_bucket_key<   s    


c         C   s   |  j  |  j  \ } } | r+ | r+ |  j St j   } t j   } | j |  } | j |  } | j |  d | | f |  _ |  j S(   s  
        :type value: file-like object
        :param value: A file-like object containing the content
            of the message.  The actual content will be stored
            in S3 and a link to the S3 object will be stored in
            the message body.
        s
   s3://%s/%s(	   R   R   t   uuidt   uuid4t   botot
   connect_s3t
   get_buckett   new_keyt   set_contents_from_file(   R   t   valueR   R   t   s3_connt	   s3_buckett   key(    (    s2   lib/python2.7/site-packages/boto/sqs/bigmessage.pyt   encodeN   s    c         C   sl   |  j  |  \ } } | rO | rO t j   } | j |  } | j |  } | Sd | } t | |    d  S(   Ns   Unable to decode S3 URL: %s(   R   R   R   R   t   get_keyR   (   R   R   R   R   R   R   R   R   (    (    s2   lib/python2.7/site-packages/boto/sqs/bigmessage.pyt   _get_s3_objecta   s    
c         C   s"   | |  _  |  j |  } | j   S(   N(   R   R    t   get_contents_as_string(   R   R   R   (    (    s2   lib/python2.7/site-packages/boto/sqs/bigmessage.pyt   decodel   s    	c         C   s?   |  j  r( |  j |  j   } | j   n  t t |   j   d  S(   N(   R   R    t   deleteR   R   (   R   R   (    (    s2   lib/python2.7/site-packages/boto/sqs/bigmessage.pyR#   q   s    	N(
   t   __name__t
   __module__t   __doc__R
   R   R   R   R    R"   R#   (    (    (    s2   lib/python2.7/site-packages/boto/sqs/bigmessage.pyR      s   				(   R   R   t   boto.sqs.messageR    t   boto.exceptionR   R   (    (    (    s2   lib/python2.7/site-packages/boto/sqs/bigmessage.pyt   <module>   s   