ó
k4Vdc           @   sÊ  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 m
 Z
 d d l m Z d d l m Z d e f d „  ƒ  YZ e ƒ  Z e j Z e j Z e j Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ e j e j ƒ e j e j ƒ e j e j ƒ d e f d „  ƒ  YZ e j e e j d ƒ ƒ ƒ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e j e j ƒ e j e j ƒ e j e j ƒ e j  d k re j e j! ƒ e j  d k rûe j e j" ƒ qe j e j" ƒ n  e j  d  k r0e j e j# ƒ n  y  d d l$ Z$ e j e$ j% ƒ Wn e& k
 rcn Xd e f d „  ƒ  YZ' e' j e j( ƒ d e f d „  ƒ  YZ) d e f d „  ƒ  YZ* e* j e j+ ƒ d S(!   sƒ  
Custom handlers may be created to handle other objects. Each custom handler
must derive from :class:`jsonpickle.handlers.BaseHandler` and
implement ``flatten`` and ``restore``.

A handler can be bound to other types by calling :func:`jsonpickle.handlers.register`.

:class:`jsonpickle.customhandlers.SimpleReduceHandler` is suitable for handling
objects that implement the reduce protocol::

    from jsonpickle import handlers

    class MyCustomObject(handlers.BaseHandler):
        ...

        def __reduce__(self):
            return MyCustomObject, self._get_args()

    handlers.register(MyCustomObject, handlers.SimpleReduceHandler)

iÿÿÿÿN(   t   util(   t   unicode(   t   queuet   Registryc           B   s5   e  Z d  „  Z d d „ Z d e d „ Z d „  Z RS(   c         C   s   i  |  _  i  |  _ d  S(   N(   t	   _handlerst   _base_handlers(   t   self(    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt   __init__)   s    	c         C   sw   |  j  j | ƒ } | d k rc t j | ƒ rc x3 |  j j ƒ  D] \ } } t | | ƒ r= | Sq= Wn  | d k rs | S| S(   sL  
        :param cls_or_name: the type or its fully qualified name
        :param default: default value, if a matching handler is not found

        Looks up a handler by type reference or its fully qualified name. If a direct match
        is not found, the search is performed over all handlers registered with base=True.
        N(   R   t   gett   NoneR    t   is_typeR   t   itemst
   issubclass(   R   t   cls_or_namet   defaultt   handlert   clst   base_handler(    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR   -   s    c            s‡   | d k r% ‡  ‡ ‡ f d †  } | St j ˆ ƒ sL t d j ˆ ƒ ƒ ‚ n  | ˆ j t j ˆ ƒ <ˆ j ˆ <ˆ  rƒ | ˆ j ˆ <n  d S(   sþ  Register the a custom handler for a class

        :param cls: The custom object class to handle
        :param handler: The custom handler class (if None, a decorator wrapper is returned)
        :param base: Indicates whether the handler should be registered for all subclasses

        This function can be also used as a decorator by omitting the `handler` argument:

        @jsonpickle.handlers.register(Foo, base=True)
        class FooHandler(jsonpickle.handlers.BaseHandler):
            pass
        c            s   ˆ j  ˆ d |  d ˆ  ƒ|  S(   NR   t   base(   t   register(   t   handler_cls(   R   R   R   (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt	   _registerJ   s    s   {0!r} is not a class/typeN(   R	   R    R
   t	   TypeErrort   formatR   t   importable_nameR   (   R   R   R   R   R   (    (   R   R   R   sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR   <   s    !c         C   sF   |  j  j | d  ƒ |  j  j t j | ƒ d  ƒ |  j j | d  ƒ d  S(   N(   R   t   popR	   R    R   R   (   R   R   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt
   unregisterW   s    N(   t   __name__t
   __module__R   R	   R   t   FalseR   R   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR   '   s   	t   BaseHandlerc           B   s2   e  Z d  „  Z d „  Z d „  Z e d „  ƒ Z RS(   c         C   s   | |  _  d S(   s”   
        Initialize a new handler to handle a registered type.

        :Parameters:
          - `context`: reference to pickler/unpickler

        N(   t   context(   R   R   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR   e   s    c         C   s   t  d |  j ƒ ‚ d S(   s:  
        Flatten `obj` into a json-friendly form and write result to `data`.

        :param object obj: The object to be serialized.
        :param dict data: A partially filled dictionary which will contain the
            json-friendly representation of `obj` once this method has
            finished.
        s"   You must implement flatten() in %sN(   t   NotImplementedErrort	   __class__(   R   t   objt   data(    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt   flatteno   s    	c         C   s   t  d |  j ƒ ‚ d S(   s}   
        Restore an object of the registered type from the json-friendly
        representation `obj` and return it.
        s"   You must implement restore() in %sN(   R    R!   (   R   R"   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt   restore{   s    c         C   s   t  j | |  ƒ | S(   sí   
        Register this handler for the given class. Suitable as a decorator,
        e.g.::

            @SimpleReduceHandler.handles
            class MyCustomClass:
                def __reduce__(self):
                    ...
        (   t   registryR   (   R   R   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt   handlesƒ   s    (   R   R   R   R$   R%   t   classmethodR'   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR   c   s   	
		t   DatetimeHandlerc           B   s    e  Z d  Z d „  Z d „  Z RS(   sË   Custom handler for datetime objects

    Datetime objects use __reduce__, and they generate binary strings encoding
    the payload. This handler encodes that payload to reconstruct the
    object.

    c   	      C   sš   |  j  } | j s t | ƒ S| j ƒ  \ } } | j } t j | d ƒ } | g g  | d D] } | | d t ƒ^ q[ } | | d t ƒ| f | d <| S(   Ni    i   t   resett
   __reduce__(   R   t   unpicklableR   R+   R$   R    t	   b64encodeR   (	   R   R"   R#   t   picklerR   t   argsR$   t   payloadt   i(    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR$   ›   s    		
	0c   	      C   s   | d \ } } |  j  } | j } | | d t ƒ} t j | d ƒ } | f t g  | d D] } | | d t ƒ^ q[ ƒ } | j | | Œ S(   NR+   R*   i    i   (   R   R%   R   R    t	   b64decodet   tuplet   __new__(	   R   R#   R   R/   t	   unpicklerR%   t   valueR1   t   params(    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR%   ¦   s    		6(   R   R   t   __doc__R$   R%   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR)   ’   s   	t   RegexHandlerc           B   s    e  Z d  Z d „  Z d „  Z RS(   s1   Flatten _sre.SRE_Pattern (compiled regex) objectsc         C   s   | j  | d <| S(   Nt   pattern(   R:   (   R   R"   R#   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR$   ¸   s    c         C   s   t  j | d ƒ S(   NR:   (   t   ret   compile(   R   R#   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR%   ¼   s    (   R   R   R8   R$   R%   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR9   µ   s   	t    t   SimpleReduceHandlerc           B   s    e  Z d  Z d „  Z d „  Z RS(   s¾   Follow the __reduce__ protocol to pickle an object.

    As long as the factory and its arguments are pickleable, this should
    pickle any object that implements the reduce protocol.

    c         C   s?   |  j  j } g  | j ƒ  D] } | | d t ƒ^ q | d <| S(   NR*   R+   (   R   R$   R+   R   (   R   R"   R#   R$   R1   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR$   É   s    /c         C   sE   |  j  j } g  | d D] } | | d t ƒ^ q \ } } | | Œ  S(   NR+   R*   (   R   R%   R   (   R   R#   R%   R1   t   factoryR/   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR%   Î   s    /(   R   R   R8   R$   R%   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR>   Â   s   	t   OrderedDictReduceHandlerc           B   s   e  Z d  Z d „  Z RS(   sá   Serialize OrderedDict on Python 3.4+

    Python 3.4+ returns multiple entries in an OrderedDict's
    reduced form.  Previous versions return a two-item tuple.
    OrderedDictReduceHandler makes the formats compatible.

    c   	      C   sz   |  j  j } | j ƒ  } | | d d t ƒ} g  | d D] } t | ƒ ^ q9 } | | f d t ƒ} | | g | d <| S(   Ni    R*   iÿÿÿÿR+   (   R   R$   R+   R   t   list(	   R   R"   R#   R$   t   reducedR?   t   xt   pairsR/   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR$   Ü   s    #(   R   R   R8   R$   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR@   Ô   s   i   i   i   i   i    t   QueueHandlerc           B   s    e  Z d  Z d „  Z d „  Z RS(   s©   Opaquely serializes Queue objects

    Queues contains mutex and condition variables which cannot be serialized.
    Construct a new Queue instance when restoring.

    c         C   s   | S(   N(    (   R   R"   R#   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR$     s    c         C   s
   t  j ƒ  S(   N(   R   t   Queue(   R   R#   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR%     s    (   R   R   R8   R$   R%   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyRE   þ   s   	t   CloneFactoryc           B   s/   e  Z d  Z d „  Z e j d „ Z d „  Z RS(   sA   Serialization proxy for collections.defaultdict's default_factoryc         C   s   | |  _  d  S(   N(   t   exemplar(   R   RH   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR     s    c         C   s   | |  j  ƒ S(   s>   Create new instances by making copies of the provided exemplar(   RH   (   R   t   clone(    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt   __call__  s    c         C   s   d t  |  ƒ |  j f S(   Ns"   <CloneFactory object at 0x%x (%s)>(   t   idRH   (   R   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt   __repr__  s    (   R   R   R8   R   t   copyRJ   RL   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyRG     s   	t   UUIDHandlerc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   Serialize uuid.UUID objectsc         C   s   | j  | d <| S(   Nt   hex(   RO   (   R   R"   R#   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR$     s    c         C   s   t  j | d ƒ S(   NRO   (   t   uuidt   UUID(   R   R#   (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyR%   #  s    (   R   R   R8   R$   R%   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyRN     s   	(   i   i   (   i   i   (   i   i    (,   R8   t   collectionsRM   t   datetimet   decimalR;   t   syst   timeRP   t
   jsonpickleR    t   jsonpickle.compatR   R   t   objectR   R&   R   R   R   R   R)   R'   t   dateR9   t   typeR<   R>   R@   t   struct_timet	   timedeltat   dequet   version_infot   Countert   OrderedDictt   Decimalt   posixt   stat_resultt   ImportErrorRE   RF   RG   RN   RQ   (    (    (    sa   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/handlers.pyt   <module>   sZ   6				/

