ó
Ý*µPc           @   sÁ   d  Z  d d l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ d e	 f d „  ƒ  YZ
 d	 e	 f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s;   
Module for abstract serializer/unserializer base classes.
iÿÿÿÿ(   t   models(   t
   smart_text(   t   sixt   SerializerDoesNotExistc           B   s   e  Z d  Z RS(   s'   The requested serializer was not found.(   t   __name__t
   __module__t   __doc__(    (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR   	   s   t   SerializationErrorc           B   s   e  Z d  Z RS(   s,   Something bad happened during serialization.(   R   R   R   (    (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR      s   t   DeserializationErrorc           B   s   e  Z d  Z RS(   s.   Something bad happened during deserialization.(   R   R   R   (    (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR      s   t
   Serializerc           B   se   e  Z d  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z RS(
   s)   
    Abstract serializer base class.
    c         K   s¹  | |  _  | j d t j ƒ  ƒ |  _ | j d d ƒ |  _ | j d t ƒ |  _ |  j	 ƒ  t
 |  _ xA| D]9} |  j | ƒ | j j } xž | j j D] } | j r” | j d k ré |  j d k sÓ | j |  j k r!|  j | | ƒ q!q$|  j d k s| j d  |  j k r$|  j | | ƒ q$q” q” WxT | j j D]F } | j r5|  j d k se| j |  j k r{|  j | | ƒ q{q5q5W|  j | ƒ |  j rh t |  _ qh qh W|  j ƒ  |  j ƒ  S(   s'   
        Serialize a queryset.
        t   streamt   fieldst   use_natural_keysiýÿÿÿN(   t   optionst   popR   t   StringIOR
   t   Nonet   selected_fieldst   FalseR   t   start_serializationt   Truet   firstt   start_objectt   _metat   concrete_modelt   local_fieldst	   serializet   relt   attnamet   handle_fieldt   handle_fk_fieldt   many_to_manyt   handle_m2m_fieldt
   end_objectt   end_serializationt   getvalue(   t   selft   querysetR   t   objR   t   field(    (    s5   ../Django//lib/python/django/core/serializers/base.pyR      s2    	
		!%	!	
c         C   s
   t  ‚ d S(   sA   
        Called when serializing of the queryset starts.
        N(   t   NotImplementedError(   R$   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR   A   s    c         C   s   d S(   s?   
        Called when serializing of the queryset ends.
        N(    (   R$   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR"   G   s    c         C   s
   t  ‚ d S(   s>   
        Called when serializing of an object starts.
        N(   R(   (   R$   R&   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR   M   s    c         C   s   d S(   s<   
        Called when serializing of an object ends.
        N(    (   R$   R&   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR!   S   s    c         C   s
   t  ‚ d S(   sW   
        Called to handle each individual (non-relational) field on an object.
        N(   R(   (   R$   R&   R'   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR   Y   s    c         C   s
   t  ‚ d S(   s6   
        Called to handle a ForeignKey field.
        N(   R(   (   R$   R&   R'   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR   _   s    c         C   s
   t  ‚ d S(   s5   
        Called to handle a ManyToManyField.
        N(   R(   (   R$   R&   R'   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR    e   s    c         C   s,   t  t |  j d d ƒ ƒ r( |  j j ƒ  Sd S(   sn   
        Return the fully serialized queryset (or None if the output stream is
        not seekable).
        R#   N(   t   callablet   getattrR
   R   R#   (   R$   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR#   k   s    (   R   R   R   R   t   internal_use_onlyR   R   R"   R   R!   R   R   R    R#   (    (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR	      s   	#							t   Deserializerc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s+   
    Abstract base deserializer class.
    c         K   sG   | |  _  t | t j ƒ r0 t j | ƒ |  _ n	 | |  _ t j ƒ  d S(   sA   
        Init this serializer given a stream or a string
        N(   R   t
   isinstanceR   t   string_typesR   R
   R    t   get_apps(   R$   t   stream_or_stringR   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyt   __init__x   s
    		c         C   s   |  S(   N(    (   R$   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyt   __iter__†   s    c         C   s
   t  ‚ d S(   s8   Iteration iterface -- return the next item in the streamN(   R(   (   R$   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyt   __next__‰   s    (   R   R   R   R1   R2   R3   (    (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR,   s   s   		t   DeserializedObjectc           B   s2   e  Z d  Z d d „ Z d „  Z e d d „ Z RS(   se  
    A deserialized model.

    Basically a container for holding the pre-saved deserialized data along
    with the many-to-many data saved with the object.

    Call ``save()`` to save the object (with the many-to-many data) to the
    database; call ``save(save_m2m=False)`` to save just the object fields
    (and not touch the many-to-many stuff.)
    c         C   s   | |  _  | |  _ d  S(   N(   t   objectt   m2m_data(   R$   R&   R6   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR1   ™   s    	c         C   s)   d |  j  j j |  j  j j |  j  j f S(   Ns"   <DeserializedObject: %s.%s(pk=%s)>(   R5   R   t	   app_labelt   object_namet   pk(   R$   (    (    s5   ../Django//lib/python/django/core/serializers/base.pyt   __repr__   s    c         C   sq   t  j j |  j d | d t ƒ|  j rd | rd x3 |  j j ƒ  D] \ } } t |  j | | ƒ q> Wn  d  |  _ d  S(   Nt   usingt   raw(	   R    t   Modelt	   save_baseR5   R   R6   t   itemst   setattrR   (   R$   t   save_m2mR;   t   accessor_namet   object_list(    (    s5   ../Django//lib/python/django/core/serializers/base.pyt   save¡   s
    N(   R   R   R   R   R1   R:   R   RD   (    (    (    s5   ../Django//lib/python/django/core/serializers/base.pyR4      s   
	N(   R   t	   django.dbR    t   django.utils.encodingR   t   django.utilsR   t   KeyErrorR   t	   ExceptionR   R   R5   R	   t   IteratorR,   R4   (    (    (    s5   ../Django//lib/python/django/core/serializers/base.pyt   <module>   s   ^