
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 m	 Z	 d d l
 m Z m Z m Z m Z m Z e s d d l Z n  e e e f Z e e  Z e e e e e e f  Z d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, d   Z- d   Z. e/ d  Z0 e/ d  Z1 d   Z2 d   Z3 d   Z4 d    Z5 d!   Z6 d"   Z7 e j8 d#  d$  Z8 d S(%   sk   Helper functions for pickling and unpickling.  Most functions assist in
determining the type of an object.
iN(   t   tags(   t   sett   unicodet   longt   bytest   PY3c         C   s-   t  r t |  t  St |  t t j f  Sd S(   s   Returns True is obj is a reference to a type.

    >>> is_type(1)
    False

    >>> is_type(object)
    True

    >>> class Klass: pass
    >>> is_type(Klass)
    True
    N(   R   t
   isinstancet   typet   typest	   ClassType(   t   obj(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_type   s    c         C   s=  t  |  |  s t St |  |  } t | t j  r8 t St | t j t j f  sW t St	 |   ri |  n |  j
 } d  } x< t j |  D]+ } t |  j |  } | d  k	 r Pq q W| d  k r t St | t  r t St r d n d } t  | |  s t St | |  } t | t  r*t | |  St |  t |   S(   Nt   __self__t   im_self(   t   hasattrt   Falset   getattrR   R   t   BuiltinMethodTypet   Truet
   MethodTypet   FunctionTypeR   t	   __class__t   Nonet   inspectt   getmrot   varst   gett   staticmethodR   t   classmethodt
   issubclassR   (   R
   t   namet   funct	   base_typet   originalt   subtypet	   self_attrt   bound_to(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt
   has_method3   s0    c         C   s&   t  |  t  o% t  |  t t j f  S(   s   Returns True is obj is a reference to an object instance.

    >>> is_object(1)
    True

    >>> is_object(object())
    True

    >>> is_object(lambda x: 1)
    False
    (   R   t   objectR   R   R   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt	   is_object_   s    c         C   s*   |  d k r t St |   t k r& t St S(   s  Helper method to see if the object is a basic data type. Unicode strings,
    integers, longs, floats, booleans, and None are considered primitive
    and will return True when passed into *is_primitive()*

    >>> is_primitive(3)
    True
    >>> is_primitive([4,4])
    False
    N(   R   R   R   t
   PRIMITIVESR   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_primitiveo   s
    
c         C   s   t  |   t k S(   so   Helper method for testing if the object is a dictionary.

    >>> is_dictionary({'key':'value'})
    True

    (   R   t   dict(   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_dictionary   s    c         C   s   t  |   t k S(   sp   Helper method to see if the object is a sequence (list, set, or tuple).

    >>> is_sequence([4])
    True

    (   R   t   SEQUENCES_SET(   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_sequence   s    c         C   s   t  |   t k S(   sX   Helper method to see if the object is a Python list.

    >>> is_list([4])
    True
    (   R   t   list(   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_list   s    c         C   s   t  |   t k S(   sX   Helper method to see if the object is a Python set.

    >>> is_set(set())
    True
    (   R   R   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_set   s    c         C   s   t  |   t k S(   s[   Helper method to see if the object is a bytestring.

    >>> is_bytes(b'foo')
    True
    (   R   R   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_bytes   s    c         C   s   t  |   t k S(   s6   Helper method to see if the object is a unicode string(   R   R   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt
   is_unicode   s    c         C   s   t  |   t k S(   s[   Helper method to see if the object is a Python tuple.

    >>> is_tuple((1,))
    True
    (   R   t   tuple(   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_tuple   s    c         C   s,   t  |  d  o+ t |  j t  o+ t |   S(   s   Returns True if *obj* is a subclass of the dict type. *obj* must be
    a subclass and not the actual builtin dict.

    >>> class Temp(dict): pass
    >>> is_dictionary_subclass(Temp())
    True
    R   (   R   R   R   R*   R+   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_dictionary_subclass   s    	c         C   s8   t  |  d  o7 t |  j t  s- t |   o7 t |   S(   s   Returns True if *obj* is a subclass of list, set or tuple.

    *obj* must be a subclass and not the actual builtin, such
    as list, set, tuple, etc..

    >>> class Temp(list): pass
    >>> is_sequence_subclass(Temp())
    True
    R   (   R   R   R   t	   SEQUENCESt   is_list_likeR-   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_sequence_subclass   s    
c         C   s   t  |   t j k r t St S(   s   Returns True if *obj* is a special (weird) class, that is more complex
    than primitive data types, but is not a full object. Including:

        * :class:`~time.struct_time`
    (   R   t   timet   struct_timeR   R   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_noncomplex   s    c         C   s{   t  |   t j t j t j t j t j f k r4 t St |  d  sG t	 St
 |  j j  } |  j j } | d k oz | d k S(   s   Returns true if passed a function

    >>> is_function(lambda x: 1)
    True

    >>> is_function(locals)
    True

    >>> def method(): pass
    >>> is_function(method)
    True

    >>> is_function(1)
    False
    R   t   __builtin__t   functiont   builtin_function_or_methodt   instancemethods   method-wrapper(   R=   R>   R?   s   method-wrapper(   R   R   R   R   t
   LambdaTypet   BuiltinFunctionTypeR   R   R   R   t   translate_module_nameR   t
   __module__t   __name__(   R
   t   moduleR   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_function   s      c         C   sL   t  |  d  oK t |  t j  oK t  |  d  oK t  |  d  oK |  j d k S(   s   Return True if `obj` is a module-global function

    >>> import os
    >>> is_module_function(os.path.exists)
    True

    >>> is_module_function(lambda: None)
    False

    R   RC   RD   s   <lambda>(   R   R   R   R   RD   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_module_function  s
    c         C   s   t  |  t j  S(   sW   Returns True if passed a module

    >>> import os
    >>> is_module(os)
    True

    (   R   R   t
   ModuleType(   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt	   is_module  s    c         C   s*   |  t  j k r t St |  p) t |  S(   s   Return True if an object can be pickled

    >>> import os
    >>> is_picklable('os', os)
    True

    >>> def foo(): pass
    >>> is_picklable('foo', foo)
    True

    >>> is_picklable('foo', lambda: None)
    False

    (   R    t   RESERVEDR   RG   RF   (   R   t   value(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_picklable$  s    c         C   s+   y t  |   t SWn t k
 r& t SXd S(   s   Tests to see if ``module`` is available on the sys.path

    >>> is_installed('sys')
    True
    >>> is_installed('hopefullythisisnotarealmodule')
    False

    N(   t
   __import__R   t   ImportErrorR   (   RE   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_installed8  s
    	
c         C   s   t  |  d  o t  |  d  S(   Nt   __getitem__t   append(   R   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyR7   H  s    c         C   sK   t  } t s! t |  t j  } n  t |  t j  oJ t |  t j  oJ | S(   N(	   R   R   R   R<   t   filet   collectionst   Iteratort   iot   IOBase(   R
   t   is_file(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_iteratorL  s
    c         C   s   t  |   p t |   p t |   p t |   p t |   p t |   p t |   p t |   p t |   p t	 |   p t
 |   p t |   p t |   p t |   p t |   t k p |  t k p t |   o |  j d k S(   su   
    Returns false if of a type which have special casing, and should not have their
    __reduce__ methods used
    t   datetime(   R/   R7   R)   R1   R2   R+   R-   R0   R4   R5   R8   R;   RF   RI   R   R&   R   RC   (   R
   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   is_reducibleU  s    $0$6c         C   s#   t  |  d d  r | |  j k S| S(   st   
    Returns true if key exists in obj.__dict__; false if not in.
    If obj.__dict__ is absent, return default
    t   __dict__N(   R   R   R[   (   R
   t   keyt   default(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   in_dictb  s    c         C   s#   t  |  d d  r | |  j k S| S(   sv   
    Returns true if key exists in obj.__slots__; false if not in.
    If obj.__slots__ is absent, return default
    t	   __slots__N(   R   R   R_   (   R
   R\   R]   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   in_slotsj  s    c         C   s   t  |   s t |   r# t t f St } t } d } d } t |  |  } t |  |  } | pk t |  |  } | p t |  |  } xf t |   j D]U } t  |  r | p t | |  } | p t | |  } n  | r | r t t f Sq W| | f S(   s   
    Tests if __reduce__ or __reduce_ex__ exists in the object dict or
    in the class dicts of every class in the MRO *except object*.

    Returns a tuple of booleans (has_reduce, has_reduce_ex)
    t
   __reduce__t   __reduce_ex__(   RZ   R   R   R^   R`   R   t   __mro__R   (   R
   t
   has_reducet   has_reduce_ext   REDUCEt	   REDUCE_EXt   base(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyRd   r  s"    
c         C   s*   t  r |  d k s |  d k r" d S|  Sd S(   s2  Rename builtin modules to a consistent (Python2) module name

    This is used so that references to Python's `builtins` module can
    be loaded in both Python 2 and 3.  We remap to the "__builtin__"
    name and unmap it when importing.

    See untranslate_module_name() for the reverse operation.

    t   builtinst
   exceptionsR<   N(   R   (   RE   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyRB     s    
c         C   s7   t  r3 |  d k r d }  q3 |  d k r3 d }  q3 n  |  S(   s   Rename module names mention in JSON to names that we can import

    This reverses the translation applied by translate_module_name() to
    a module name available to the current version of Python.

    R<   Ri   Rj   (   R   (   RE   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   untranslate_module_name  s    	c         C   s&   |  j  } t |  j  } d | | f S(   s  
    >>> class Example(object):
    ...     pass

    >>> ex = Example()
    >>> importable_name(ex.__class__)
    'jsonpickle.util.Example'

    >>> importable_name(type(25))
    '__builtin__.int'

    >>> importable_name(None.__class__)
    '__builtin__.NoneType'

    >>> importable_name(False.__class__)
    '__builtin__.bool'

    >>> importable_name(AttributeError)
    '__builtin__.AttributeError'

    s   %s.%s(   RD   RB   RC   (   t   clsR   RE   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   importable_name  s    	c         C   s=   t  j |   } t r9 t |  t k r9 | j d  } n  | S(   Nt   ascii(   t   base64t	   b64encodeR   R   R   t   decode(   t   datat   payload(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyRp     s    c         C   s7   t  r* t |   t k	 r* t |  d  }  n  t j |   S(   NRn   (   R   R   R   Ro   t	   b64decode(   Rs   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyRt     s    i    c         C   s   t  | |    S(   N(   R   (   R
   t   getter(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt
   itemgetter  s    (9   t   __doc__Ro   RS   RU   t   operatorR9   R   R   t
   jsonpickleR    t   jsonpickle.compatR   R   R   R   R   R<   R.   R3   R6   R,   t   boolt   floatt   intR(   R   R%   R'   R)   R+   R-   R/   R0   R1   R2   R4   R5   R8   R;   RF   RG   RI   RL   RO   R7   RX   RZ   R   R^   R`   Rd   RB   Rk   Rm   Rp   Rt   Rv   (    (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/jsonpickle/util.pyt   <module>   sZ   (		,			
	
													!									#					