ó
ýG>Qc           @   s—   d  Z  d d l m Z d d l m Z d Z d Z d Z d e f d „  ƒ  YZ	 e	 ƒ  Z
 e
 j Z e
 j Z e
 j Z e
 j Z e d d „ Z d „  Z d S(   sc  Python library for serializing any arbitrary object graph into JSON.
It can take almost any Python object and turn the object into JSON.
Additionally, it can reconstitute the object back into Python.

    >>> import jsonpickle
    >>> from samples import Thing

Create an object.

    >>> obj = Thing('A String')
    >>> print obj.name
    A String

Use jsonpickle to transform the object into a JSON string.

    >>> pickled = jsonpickle.encode(obj)
    >>> print pickled
    {"py/object": "samples.Thing", "name": "A String", "child": null}

Use jsonpickle to recreate a Python object from a JSON string

    >>> unpickled = jsonpickle.decode(pickled)
    >>> str(unpickled.name)
    'A String'

.. warning::

    Loading a JSON string from an untrusted source represents a potential
    security vulnerability.  jsonpickle makes no attempt to sanitize the input.

The new object has the same type and data, but essentially is now a copy of
the original.

    >>> obj == unpickled
    False
    >>> obj.name == unpickled.name
    True
    >>> type(obj) == type(unpickled)
    True

If you will never need to load (regenerate the Python class from JSON), you can
pass in the keyword unpicklable=False to prevent extra information from being
added to JSON.

    >>> oneway = jsonpickle.encode(obj, unpicklable=False)
    >>> print oneway
    {"name": "A String", "child": null}

iÿÿÿÿ(   t   Pickler(   t	   Unpicklers   0.4.0t   encodet   decodet   jsont
   simplejsont   demjsons   django.util.simplejsont   JSONPluginMgrc           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s6  The JSONPluginMgr handles encoding and decoding.

    It tries these modules in this order:
        simplejson, json, demjson

    simplejson is a fast and popular backend and is tried first.
    json comes with python2.6 and is tried second.
    demjson is the most permissive backend and is tried last.

    c         C   sÐ   g  |  _  i  |  _ i  |  _ d i t d 6f } i | d 6| d 6| d 6|  _ i  |  _ t |  _ |  j d d d t	 ƒ |  j d d d t	 ƒ |  j d d d	 d
 ƒ |  j d d d d ƒ |  j d d d t	 ƒ d  S(   Nt	   sort_keysR   R   s   django.util.simplejsont   dumpst   loadsR   R   R   t   JSONDecodeErrort   jsonlibt   writet   readt	   ReadErrort   yajl(    (
   t   _backend_namest	   _encoderst	   _decoderst   Truet   _encoder_optionst   _decoder_exceptionst   Falset	   _verifiedt   load_backendt
   ValueError(   t   selft	   json_opts(    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyt   __init__Q   s    					c         C   s   |  j  r d St d ƒ ‚ d S(   s4   Ensures that we've loaded at least one JSON backend.NsX   jsonpickle requires at least one of the following:
    python2.6, simplejson, or demjson(   R   t   AssertionError(   R   (    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyt   _verifyq   s    	c         C   sQ  y t  | ƒ } Wn t k
 r$ d SXy7 | j d ƒ } x! | d D] } t | | ƒ } qB WWn t k
 rp d SXy0 t | | ƒ |  j | <t | | ƒ |  j | <Wn t k
 rÂ |  j | ƒ d SXy< t | ƒ t	 k rñ t | | ƒ |  j
 | <n | |  j
 | <Wn t k
 r |  j | ƒ d SXg  i  f |  j | <|  j j | ƒ t |  _ d S(   s2  
        Load a JSON backend by name.

        This method loads a backend and sets up references to that
        backend's encode/decode functions and exception classes.
        
        :param encode_name: is the name of the backend's encode method.
          The method should take an object and return a string.
        :param decode_name: names the backend's method for the reverse
          operation -- returning a Python object from a string.
        :param decode_exc: can be either the name of the exception class
          used to denote decoding errors, or it can be a direct reference
          to the appropriate exception class itself.  If it is a name,
          then the assumption is that an exception class of that name
          can be found in the backend module's namespace.
            
        Nt   .i   (   t
   __import__t   ImportErrort   splitt   getattrt   AttributeErrorR   R   t   remove_backendt   typet   strR   R   R   t   appendR   R   (   R   t   namet   encode_namet   decode_namet
   decode_exct   modt
   componentst   comp(    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyR   y   s4    c         C   s„   |  j  j | d ƒ |  j j | d ƒ |  j j | d ƒ |  j j | d ƒ | |  j k rn |  j j | ƒ n  t |  j ƒ |  _	 d S(   s,   Remove all entries for a particular backend.N(
   R   t   popt   NoneR   R   R   R   t   removet   boolR   (   R   R*   (    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyR&   µ   s    c         C   s«   |  j  ƒ  xš t |  j ƒ D]‰ \ } } yJ |  j | \ } } | j ƒ  } | f t | ƒ } |  j | | | Ž  SWq t k
 r¢ | t |  j ƒ d k r£ ‚  q£ q Xq Wd S(   sÂ   
        Attempt to encode an object into JSON.

        This tries the loaded backends in order and passes along the last
        exception if no backend is able to encode the object.

        i   N(	   R   t	   enumerateR   R   t   copyt   tupleR   t	   Exceptiont   len(   R   t   objt   idxR*   t   optargst	   optkwargst   encoder_kwargst   encoder_args(    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyR   ¿   s    
c         C   s‚   |  j  ƒ  xq t |  j ƒ D]` \ } } y |  j | | ƒ SWq |  j | k
 ry } | t |  j ƒ d k rz | ‚ qz q Xq Wd S(   sÍ   
        Attempt to decode an object from a JSON string.

        This tries the loaded backends in order and passes along the last
        exception if no backends are able to decode the string.

        i   N(   R   R5   R   R   R   R9   (   R   t   stringR;   R*   t   e(    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyR   Ò   s    
	c         C   sO   | |  j  k r5 |  j  j | ƒ |  j  j d | ƒ n d | } t | ƒ ‚ d S(   sí  
        Set the preferred json backend.

        If a preferred backend is set then jsonpickle tries to use it
        before any other backend.

        For example::
        
            set_preferred_backend('simplejson')

        If the backend is not one of the built-in jsonpickle backends
        (json/simplejson, or demjson) then you must load the backend
        prior to calling set_preferred_backend.

        AssertionError is raised if the backend has not been loaded.

        i    s%   The "%s" backend has not been loaded.N(   R   R3   t   insertR   (   R   R*   t   errmsg(    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyt   set_preferred_backendä   s
    
c         O   s   | | f |  j  | <d S(   s%  
        Associate encoder-specific options with an encoder.

        After calling set_encoder_options, any calls to jsonpickle's
        encode method will pass the supplied args and kwargs along to
        the appropriate backend's encode method.

        For example::
        
            set_encoder_options('simplejson', sort_keys=True, indent=4)
            set_encoder_options('demjson', compactly=False)

        See the appropriate encoder's documentation for details about
        the supported arguments and keyword arguments.

        N(   R   (   R   R*   t   argst   kwargs(    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyt   set_encoder_optionsý   s    (   t   __name__t
   __module__t   __doc__R   R   R   R&   R   R   RD   RG   (    (    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyR   F   s   
	 		<	
			c         C   s+   t  d | d | ƒ } t j | j |  ƒ ƒ S(   s  
    Return a JSON formatted representation of value, a Python object.

    The keyword argument 'unpicklable' defaults to True.
    If set to False, the output will not contain the information
    necessary to turn the JSON data back into Python objects.

    The keyword argument 'max_depth' defaults to None.
    If set to a non-negative integer then jsonpickle will not recurse
    deeper than 'max_depth' steps into the object.  Anything deeper
    than 'max_depth' is represented using a Python repr() of the object.

    >>> encode('my string')
    '"my string"'
    >>> encode(36)
    '36'

    >>> encode({'foo': True})
    '{"foo": true}'

    >>> encode({'foo': True}, max_depth=0)
    '"{\'foo\': True}"'

    >>> encode({'foo': True}, max_depth=1)
    '{"foo": "True"}'


    t   unpicklablet	   max_depth(   R    R   R   t   flatten(   t   valueRK   RL   t   j(    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyR     s    	c         C   s   t  ƒ  } | j t j |  ƒ ƒ S(   s…   
    Convert a JSON string into a Python object.

    >>> str(decode('"my string"'))
    'my string'
    >>> decode('36')
    36
    (   R   t   restoreR   R   (   R@   RO   (    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyR   ;  s    		N(   s   encodes   decode(   s   jsons
   simplejsons   demjsons   django.util.simplejson(   RJ   t   jsonpickle.picklerR    t   jsonpickle.unpicklerR   t   __version__t   __all__t   SUPPORTED_BACKENDSt   objectR   R   RD   RG   R   R&   R   R2   R   R   (    (    (    sE   /home/genia/Projects/asteroid-lander/game/libs/jsonpickle/__init__.pyt   <module>9   s       Ë					!