ó
TR¹Nc           @   sÍ   d  Z  d d l m Z d d l m Z i d d 6d d 6d d	 6Z y d d
 l Z d e d <Wn e k
 rn n Xi  a d
 d „ Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d
 S(   s‘  
Interfaces for serializing Django objects.

Usage::

    from django.core import serializers
    json = serializers.serialize("json", some_query_set)
    objects = list(serializers.deserialize("json", json))

To add your own serializers, use the SERIALIZATION_MODULES setting::

    SERIALIZATION_MODULES = {
        "csv" : "path.to.csv.serializer",
        "txt" : "path.to.txt.serializer",
    }

iÿÿÿÿ(   t   settings(   t	   importlibs&   django.core.serializers.xml_serializert   xmls   django.core.serializers.pythont   pythons   django.core.serializers.jsont   jsonNs   django.core.serializers.pyyamlt   yamlc         C   s6   t  j | ƒ } | d k r( | t |  <n
 | | |  <d S(   sž  "Register a new serializer.

    ``serializer_module`` should be the fully qualified module name
    for the serializer.

    If ``serializers`` is provided, the registration will be added
    to the provided dictionary.

    If ``serializers`` is not provided, the registration will be made
    directly into the global register of serializers. Adding serializers
    directly is not a thread-safe operation.
    N(   R   t   import_modulet   Nonet   _serializers(   t   formatt   serializer_modulet   serializerst   module(    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyt   register_serializer&   s    c         C   s   t  |  =d S(   sC   Unregister a given serializer. This is not a thread-safe operation.N(   R   (   R	   (    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyt   unregister_serializer9   s    c         C   s   t  s t ƒ  n  t  |  j S(   N(   R   t   _load_serializerst
   Serializer(   R	   (    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyt   get_serializer=   s    
c           C   s   t  s t ƒ  n  t  j ƒ  S(   N(   R   R   t   keys(    (    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyt   get_serializer_formatsB   s    
c          C   s?   t  s t ƒ  n  g  t  j ƒ  D] \ }  } | j j s |  ^ q S(   N(   R   R   t	   iteritemsR   t   internal_use_only(   t   kt   v(    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyt   get_public_serializer_formatsG   s    
c         C   s   t  s t ƒ  n  t  |  j S(   N(   R   R   t   Deserializer(   R	   (    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyt   get_deserializerL   s    
c         K   s)   t  |  ƒ ƒ  } | j | |  | j ƒ  S(   sn   
    Serialize a queryset (or any iterator that returns database objects) using
    a certain serializer.
    (   R   t	   serializet   getvalue(   R	   t   querysett   optionst   s(    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyR   Q   s    c         K   s   t  |  ƒ } | | |  S(   s  
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is a instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    (   R   (   R	   t   stream_or_stringR   t   d(    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyt   deserializeZ   s    c          C   sr   i  }  x" t  D] } t | t  | |  ƒ q Wt t d ƒ rh x+ t j D] } t | t j | |  ƒ qD Wn  |  a d S(   sÈ   
    Register built-in and settings-defined serializers. This is done lazily so
    that user code has a chance to (e.g.) set up custom settings without
    needing to be careful of import order.
    t   SERIALIZATION_MODULESN(   t   BUILTIN_SERIALIZERSR   t   hasattrR    R#   R   (   R   R	   (    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyR   d   s    (   t   __doc__t   django.confR    t   django.utilsR   R$   R   t   ImportErrorR   R   R   R   R   R   R   R   R   R"   R   (    (    (    sM   /home/panlixing/Python_Projects/gaeseries/django/core/serializers/__init__.pyt   <module>   s*   
								
