ó
k4Vdc           @   s:   d  d l  m Z d  d l  m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   PY32(   t   unicodet   JSONBackendc           B   s›   e  Z d  Z e d „ Z d „  Z d „  Z d d e d „ Z d „  Z	 d „  Z
 e
 Z d	 „  Z d
 „  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s;  Manages encoding and decoding using various backends.

    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  |  _ i  |  _ t |  _	 t
 s† |  j d ƒ n  |  j d ƒ |  j d d d d ƒ |  j d	 d
 d d ƒ |  j d ƒ |  j d ƒ d  S(   Nt	   sort_keyst   jsont
   simplejsons   django.util.simplejsont   demjsont   encodet   decodet   JSONDecodeErrort   jsonlibt   writet   readt	   ReadErrort   yajlt   ujson(    (   t   _fallthrought   _backend_namest	   _encoderst	   _decoderst   Truet   _encoder_optionst   _decoder_optionst   _decoder_exceptionst   Falset	   _verifiedR    t   load_backend(   t   selft   fallthrought	   json_opts(    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyt   __init__   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   (    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyt   _verify5   s    	c         C   s   | |  _  d S(   s  
        Disable jsonpickle's fallthrough-on-error behavior

        By default, jsonpickle tries the next backend when decoding or
        encoding using a backend fails.

        This can make it difficult to force jsonpickle to use a specific
        backend, and catch errors, because the error will be suppressed and
        may not be raised by the subsequent backend.

        Calling `enable_backend(False)` will make jsonpickle immediately
        re-raise any exceptions raised by the backends.

        N(   R   (   R   t   enable(    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyt   enable_fallthrough=   s    t   dumpst   loadsc         C   s.  y t  | ƒ } Wn t k
 r$ t SXy1 x* | j d ƒ d D] } t | | ƒ } q< WWn t k
 rj t SX|  j |  j | | | ƒ s£ |  j |  j | | | ƒ r§ t St	 | t
 t f ƒ rÞ |  j |  j | | | ƒ së t Sn | |  j | <g  i  f |  j | <g  i  f |  j | <|  j j | ƒ t |  _ t S(   så  Load a JSON backend by name.

        This method loads a backend and sets up references to that
        backend's loads/dumps functions and exception classes.

        :param dumps: is the name of the backend's encode method.
          The method should take an object and return a string.
          Defaults to 'dumps'.
        :param loads: names the backend's method for the reverse
          operation -- returning a Python object from a string.
        :param loads_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.
        :param load: names the backend's 'load' method.
        :param dump: names the backend's 'dump' method.
        :rtype bool: True on success, False if the backend could not be loaded.

        t   .i   (   t
   __import__t   ImportErrorR   t   splitt   getattrt   AttributeErrort   _storeR   R   t
   isinstancet   strR   R   R   R   R   t   appendR   R   (   R   t   nameR#   R$   t	   loads_exct   modt   attr(    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyR   N   s*    	c         C   s—   |  j  j | d ƒ |  j j | d ƒ |  j j | d ƒ |  j j | d ƒ |  j j | d ƒ | |  j k r |  j j | ƒ n  t	 |  j ƒ |  _
 d S(   s,   Remove all entries for a particular backend.N(   R   t   popt   NoneR   R   R   R   R   t   removet   boolR   (   R   R/   (    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyt   remove_backend‰   s    c         C   s    |  j  ƒ  |  j s0 |  j d } |  j | | ƒ Sxi t |  j ƒ D]X \ } } y |  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    i   N(   R    R   R   t   backend_encodet	   enumeratet	   Exceptiont   len(   R   t   objR/   t   idxt   e(    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyR   ”   s    
	c         C   sF   |  j  | \ } } | j ƒ  } | f t | ƒ } |  j | | | Ž  S(   N(   R   t   copyt   tupleR   (   R   R/   R<   t   optargst	   optkwargst   encoder_kwargst   encoder_args(    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyR8   «   s    c         C   s§   |  j  ƒ  |  j s0 |  j d } |  j | | ƒ Sxp t |  j ƒ D]_ \ } } y |  j | | ƒ SWq@ |  j | k
 rž } | t |  j ƒ d k rŸ | ‚ qŸ 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    i   N(   R    R   R   t   backend_decodeR9   R   R;   (   R   t   stringR/   R=   R>   (    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyR   ±   s    
		c         C   sD   |  j  j | d i  f ƒ \ } } | j ƒ  } |  j | | | | Ž S(   N(    (   R   t   getR?   R   (   R   R/   RF   RA   RB   t   decoder_kwargs(    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyRE   Ê   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   R5   t   insertR   (   R   R/   t   errmsg(    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.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(    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyt   set_encoder_optionsè   s    c         O   s   | | f |  j  | <d S(   s   
        Associate decoder-specific options with a decoder.

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

        For example::

            set_decoder_options('simplejson', encoding='utf8', cls=JSONDecoder)
            set_decoder_options('demjson', strict=True)

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

        N(   R   (   R   R/   RL   RM   (    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyt   set_decoder_optionsû   s    c         C   s=   y t  | | ƒ | | <Wn t k
 r8 |  j | ƒ t SXt S(   N(   R)   R*   R7   R   R   (   R   t   dctt   backendR<   R/   (    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyR+     s    (   t   __name__t
   __module__t   __doc__R   R   R    R"   t
   ValueErrorR   R7   R   R#   R8   R   R$   RE   RK   RN   RO   R+   (    (    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyR      s    
#		:								N(   t   jsonpickle.compatR    R   t   objectR   (    (    (    s`   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/backend.pyt   <module>   s   