
 X                 @   s|   d  d l  m Z d  d l m Z d d l m Z m Z Gd d   d e  Z Gd d   d e  Z	 Gd	 d
   d
 e	  Z
 d S)    )HttpResponse)six   )get_templateselect_templatec               @   s   e  Z d  Z d S)ContentNotRenderedErrorN)__name__
__module____qualname__ r   r   F/home/ubuntu/projects/ifolica/build/django/django/template/response.pyr      s   r   c                   s   e  Z d  Z d d d g Z d d d d d   f d d  Z d d   Z d	 d
   Z d d   Z e d d    Z	 d d   Z
 d d   Z e d d    Z   f d d   Z e   f d d    Z e j d d    Z   S)SimpleTemplateResponsetemplate_namecontext_data_post_render_callbacksNc                sY   | |  _  | |  _ | |  _ g  |  _ d  |  _ t t |   j d | | |  d |  _ d  S)N F)	r   r   usingr   _requestsuperr   __init___is_rendered)selftemplatecontextcontent_typestatuscharsetr   )	__class__r   r   r      s    					zSimpleTemplateResponse.__init__c             C   sU   |  j  j   } |  j s' t d   n  x' |  j D] } | | k r1 | | =q1 q1 W| S)zPickling support function.

        Ensures that the object can't be pickled before it has been
        rendered, and that the pickled state only includes rendered
        data, not the data used to construct the response.
        z?The response content must be rendered before it can be pickled.)__dict__copyr   r   rendering_attrs)r   Zobj_dictattrr   r   r   __getstate__.   s    	z#SimpleTemplateResponse.__getstate__c             C   sU   t  | t t f  r( t | d |  j St  | t j  rM t | d |  j S| Sd S)z<Accepts a template object, path-to-template or list of pathsr   N)
isinstancelisttupler   r   r   string_typesr   )r   r   r   r   r   resolve_template?   s
    z'SimpleTemplateResponse.resolve_templatec             C   s   | S)Nr   )r   r   r   r   r   resolve_contextH   s    z&SimpleTemplateResponse.resolve_contextc             C   s=   |  j  |  j  } |  j |  j  } | j | |  j  } | S)aA  Returns the freshly rendered content for the template and context
        described by the TemplateResponse.

        This *does not* set the final content of the response. To set the
        response content, you must either call render(), or set the
        content explicitly using the value of this property.
        )r'   r   r(   r   renderr   )r   r   r   contentr   r   r   rendered_contentK   s    	z'SimpleTemplateResponse.rendered_contentc             C   s*   |  j  r | |   n |  j j |  d S)zAdds a new post-rendering callback.

        If the response has already been rendered,
        invoke the callback immediately.
        N)r   r   append)r   callbackr   r   r   add_post_render_callbackY   s    	z/SimpleTemplateResponse.add_post_render_callbackc             C   sW   |  } |  j  sS |  j |  _ x5 |  j D]' } | |  } | d k	 r% | } q% q% Wn  | S)zRenders (thereby finalizing) the content of the response.

        If the content has already been rendered, this is a no-op.

        Returns the baked response instance.
        N)r   r+   r*   r   )r   retvalZpost_callbackZ	newretvalr   r   r   r)   d   s    	zSimpleTemplateResponse.renderc             C   s   |  j  S)N)r   )r   r   r   r   is_renderedt   s    z"SimpleTemplateResponse.is_renderedc                s+   |  j  s t d   n  t t |   j   S)NzEThe response content must be rendered before it can be iterated over.)r   r   r   r   __iter__)r   )r   r   r   r1   x   s    	zSimpleTemplateResponse.__iter__c                s(   |  j  s t d   n  t t |   j S)Nz@The response content must be rendered before it can be accessed.)r   r   r   r   r*   )r   )r   r   r   r*      s    	zSimpleTemplateResponse.contentc             C   s    t  j j |  |  d |  _ d S)z*Sets the content for the response
        TN)r   r*   fsetr   )r   valuer   r   r   r*      s    )r   r	   r
   r    r   r"   r'   r(   propertyr+   r.   r)   r0   r1   r*   setterr   r   )r   r   r      s   		r   c                   sA   e  Z d  Z e j d g Z d d d d d   f d d  Z   S)TemplateResponser   Nc                s2   t  t |   j | | | | | |  | |  _ d  S)N)r   r6   r   r   )r   requestr   r   r   r   r   r   )r   r   r   r      s    zTemplateResponse.__init__)r   r	   r
   r   r    r   r   r   )r   r   r6      s   r6   N)Zdjango.httpr   Zdjango.utilsr   loaderr   r   	Exceptionr   r   r6   r   r   r   r   <module>   s
   