ó
O'—^c           @   sÑ  d  Z  d d l Z d- Z d j e e e d d !ƒ ƒ d j e d ƒ Z d Z d Z d	 Z	 d
 Z
 d a e j d d k rŒ d d l m Z n8 y d d l m Z Wn! e k
 rÃ d d l m Z n Xd d e d e d f d. d/ d d e d e d f d d e d e d f d d e d e d f d0 g Z d1 Z d$ e f d% „  ƒ  YZ d& „  Z e d' k rmd( GHe j d) ƒ n` x? e D]+ Z y e e ƒ a PWqte k
 ržqtXqtWe d* ƒ ‚ d+ „  Z e Z d, „  Z e Z d S(2   sL   Wraps the best available JSON implementation available in a common
interfaceiÿÿÿÿNi    i   t   .t    s   Rune Halvorsens   runefh@gmail.coms#   http://bitbucket.org/runeh/anyjson/t   restructuredtext(   t   StringIOt   yajlt   dumpst   loadst   loadt   jsonlib2t   writet
   WriteErrort   readt	   ReadErrort   jsonlibt
   simplejsont   jsons   django.utils.simplejsont   cjsont   encodet   EncodeErrort   decodet   DecodeErrort   modnamet   encodert   encerrort   decodert   decerrort   filedecodert   _JsonImplementationc           B   sG   e  Z d  Z d „  Z d „  Z d „  Z d „  Z e Z d „  Z e Z	 RS(   s"   Incapsulates a JSON implementationc         C   s5  t  t t | ƒ ƒ } | d d k rD d d  l } | j d t ƒ n  |  j | d ƒ } | d |  _ t | | d ƒ |  _	 t | | d ƒ |  _
 | d } | o¬ t | | ƒ |  _ | d |  _ | d	 |  _ t | d t ƒ rø t | | d ƒ |  _ n  t | d	 t ƒ r$t | | d	 ƒ |  _ n  | d |  _ d  S(
   NR   R   iÿÿÿÿsG   cjson is deprecated! See http://pypi.python.org/pypi/python-cjson/1.0.5R   R   R   R   R   (   t   dictt   zipt   _fieldst   warningst   warnt   DeprecationWarningt   _attempt_loadt   implementationt   getattrt   _encodet   _decodet   _filedecodet   _encode_errort   _decode_errort
   isinstancet
   basestringt   name(   t   selft   modspect   modinfoR   t   modulet   fdec(    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyt   __init__1   s"    
c         C   s   d |  j  S(   Ns'   <_JsonImplementation instance using %s>(   R,   (   R-   (    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyt   __repr__J   s    c         C   s   t  | ƒ t j | S(   sy   Attempt to load module name modname, returning it on success,
        throwing ImportError if module couldn't be imported(   t
   __import__t   syst   modules(   R-   R   (    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyR"   M   s    
c         C   sM   y |  j  | ƒ SWn5 |  j k
 rH } t t | j Œ  t j ƒ  d ‚ n Xd S(   sv   Serialize the datastructure to json. Returns a string. Raises
        TypeError if the object could not be serialized.i   N(   R%   R(   t	   TypeErrort   argsR5   t   exc_info(   R-   t   datat   exc(    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyR   S   s    c         C   sy   y= |  j  r/ t | t ƒ r/ |  j  t | ƒ ƒ S|  j | ƒ SWn5 |  j k
 rt } t t | j Œ  t j	 ƒ  d ‚ n Xd S(   si   deserialize the string to python data types. Raises
        ValueError if the string could not be parsed.i   N(
   R'   R*   R+   R   R&   R)   t
   ValueErrorR8   R5   R9   (   R-   t   sR;   (    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyR   \   s    (
   t   __name__t
   __module__t   __doc__R2   R3   R"   R   t	   serializeR   t   deserialize(    (    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyR   .   s   					
c         C   sd   xM g  t  D] } | d | f ^ q
 D]( \ } } | |  k r$ t | ƒ a d Sq$ Wt d |  ƒ ‚ d S(   s>   Forces anyjson to use a specific json module if it's availablei    Ns   No module named: %s(   t   _modulesR   R#   t   ImportError(   R   t   eR,   t   spec(    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyt   force_implementationi   s
    0t   __main__s8   Running anyjson as a stand alone script is not supportedi   s   No supported JSON module foundc         C   s   t  j |  ƒ S(   s   Serialize the object to JSON.(   R#   R   (   t   value(    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyR   …   s    c         C   s   t  j |  ƒ S(   s3   Deserialize JSON-encoded object to a Python object.(   R#   R   (   RI   (    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyR   ‹   s    (   i    i   i   (   R   R	   R
   R   R   N(   R   R	   R
   R   R   N(   R   R   R   R   R   N(   R   R   R   R   R   R   (    R@   R5   t   VERSIONt   joint   mapt   strt   __version__t
   __author__t   __contact__t   __homepage__t   __docformat__t   NoneR#   t   version_infot   ioR   t	   cStringIORD   R7   R<   RC   R   t   objectR   RG   R>   t   exitR.   R   RB   R   RA   (    (    (    s2   /tmp/pip-unpacked-wheel-sS4P6a/anyjson/__init__.pyt   <module>   sN   0	 ;	
		