??????????????????????
???  ?????????????????
 JFIF      ?? C      


!"$"$?? C    
?? p 
" ??     
         ??             ?   
   ????

(%	aA*?XYD?(J??E  RE,P XYae?)(E  2 B  R  	BQ    X?)X     ?  @  

adadasdasdasasdasdas


.....................................................................................................................................??????????????????????
???  
 JFIF      ?? C      


!"$"$?? C    
?? p 
" ??     
         ??             ?   
   ????

(%	aA*?XYD?(J??E  RE,P XYae?)(E  2 B  R  	BQ    X?)X     ?  @  

adadasdasdasasdasdas


.....................................................................................................................................ó
›t0^c           @   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 m Z m Z m	 Z	 m
 Z
 e j e ƒ Z d e f d „  ƒ  YZ d e j f d „  ƒ  YZ e j e ƒ d e
 j e	 j f d	 „  ƒ  Yƒ Z d
 „  Z d e d „ Z d „  Z d e d „ Z d „  Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ  d S(   sÜ   JSON (de)serialization framework.

The framework presented here is somewhat based on `Go's "json" package`_
(especially the ``omitempty`` functionality).

.. _`Go's "json" package`: http://golang.org/pkg/encoding/json/

iÿÿÿÿN(   t   b64t   errorst
   interfacest   utilt   Fieldc           B   sŒ   e  Z d  Z d Z d e d d d „ Z e d „  ƒ Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z RS(   sø  JSON object field.

    :class:`Field` is meant to be used together with
    :class:`JSONObjectWithFields`.

    ``encoder`` (``decoder``) is a callable that accepts a single
    parameter, i.e. a value to be encoded (decoded), and returns the
    serialized (deserialized) value. In case of errors it should raise
    :class:`~josepy.errors.SerializationError`
    (:class:`~josepy.errors.DeserializationError`).

    Note, that ``decoder`` should perform partial serialization only.

    :ivar str json_name: Name of the field when encoded to JSON.
    :ivar default: Default value (used when not present in JSON object).
    :ivar bool omitempty: If ``True`` and the field value is empty, then
        it will not be included in the serialized JSON object, and
        ``default`` will be used for deserialization. Otherwise, if ``False``,
        field is considered as required, value will always be included in the
        serialized JSON objected, and it must also be present when
        deserializing.

    t	   json_namet   defaultt	   omitemptyt   fdect   fencc         C   s[   | |  _  | |  _ | |  _ | d  k r0 |  j n | |  _ | d  k rN |  j n | |  _ d  S(   N(   R   R   R   t   Nonet   default_decoderR   t   default_encoderR	   (   t   selfR   R   R   t   decodert   encoder(    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   __init__/   s
    			c         C   s   t  | t ƒ o | S(   sÒ   Is the provided value considered "empty" for this field?

        This is useful for subclasses that might want to override the
        definition of being empty, e.g. for some more exotic data types.

        (   t
   isinstancet   bool(   t   clst   value(    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   _empty9   s    c         C   s   |  j  | ƒ o |  j S(   s   Omit the value in output?(   R   R   (   R   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   omitC   s    c         K   sS   t  d |  j d |  j d |  j d |  j d |  j ƒ } | j | ƒ t |  ƒ |   S(   NR   R   R   R   R   (   t   dictR   R   R   R   R	   t   updatet   type(   R   t   kwargst   current(    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   _update_paramsG   s
    	c         C   s   |  j  d | ƒ S(   s6   Descriptor to change the decoder on JSON object field.R   (   R   (   R   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR   N   s    c         C   s   |  j  d | ƒ S(   s6   Descriptor to change the encoder on JSON object field.R   (   R   (   R   R	   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR   R   s    c         C   s   |  j  | ƒ S(   s4   Decode a value, optionally with context JSON object.(   R   (   R   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   decodeV   s    c         C   s   |  j  | ƒ S(   s4   Encode a value, optionally with context JSON object.(   R	   (   R   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   encodeZ   s    c            sl   t  | t ƒ r) t ‡  f d †  | Dƒ ƒ St  | t ƒ rd t j t ‡  f d †  t j | ƒ Dƒ ƒ ƒ S| Sd S(   sÃ   Default decoder.

        Recursively deserialize into immutable types (
        :class:`josepy.util.frozendict` instead of
        :func:`dict`, :func:`tuple` instead of :func:`list`).

        c         3   s   |  ] } ˆ  j  | ƒ Vq d  S(   N(   R   (   t   .0t   subvalue(   R   (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pys	   <genexpr>i   s    c         3   s3   |  ]) \ } } ˆ  j  | ƒ ˆ  j  | ƒ f Vq d  S(   N(   R   (   R   t   keyR   (   R   (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pys	   <genexpr>l   s   N(   R   t   listt   tupleR   R   t
   frozendictt   sixt	   iteritems(   R   R   (    (   R   s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR   ^   s    
c         C   s   | S(   s   Default (passthrough) encoder.(    (   R   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR   q   s    (   s	   json_names   defaults	   omitemptys   fdecs   fencN(   t   __name__t
   __module__t   __doc__t	   __slots__R
   t   FalseR   t   classmethodR   R   R   R   R   R   R   R   R   (    (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR      s   	
						t   JSONObjectWithFieldsMetac           B   s   e  Z d  Z d „  Z RS(   sÃ  Metaclass for :class:`JSONObjectWithFields` and its subclasses.

    It makes sure that, for any class ``cls`` with ``__metaclass__``
    set to ``JSONObjectWithFieldsMeta``:

    1. All fields (attributes of type :class:`Field`) in the class
       definition are moved to the ``cls._fields`` dictionary, where
       keys are field attribute names and values are fields themselves.

    2. ``cls.__slots__`` is extended by all field attribute names
       (i.e. not :attr:`Field.json_name`). Original ``cls.__slots__``
       are stored in ``cls._orig_slots``.

    In a consequence, for a field attribute name ``some_field``,
    ``cls.some_field`` will be a slot descriptor and not an instance
    of :class:`Field`. For example::

      some_field = Field('someField', default=())

      class Foo(object):
          __metaclass__ = JSONObjectWithFieldsMeta
          __slots__ = ('baz',)
          some_field = some_field

      assert Foo.__slots__ == ('some_field', 'baz')
      assert Foo._orig_slots == ()
      assert Foo.some_field is not Field

      assert Foo._fields.keys() == ['some_field']
      assert Foo._fields['some_field'] is some_field

    As an implementation note, this metaclass inherits from
    :class:`abc.ABCMeta` (and not the usual :class:`type`) to mitigate
    the metaclass conflict (:class:`ImmutableMap` and
    :class:`JSONDeSerializable`, parents of :class:`JSONObjectWithFields`,
    use :class:`abc.ABCMeta` as its metaclass).

    c         C   sá   i  } x' | D] } | j  t | d i  ƒ ƒ q WxH t t j | ƒ ƒ D]1 \ } } t | t ƒ rF | j | ƒ | | <qF qF W| j d d ƒ | d <t t	 | d ƒ t	 t j
 | ƒ ƒ ƒ | d <| | d <t j j |  | | | ƒ S(   Nt   _fieldsR*   t   _orig_slots(    (   R   t   getattrR#   R%   R&   R   R   t   popt   getR"   t   iterkeyst   abct   ABCMetat   __new__(   t   mcst   namet   basest   diktt   fieldst   baseR!   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR6   ¡   s    "*
(   R'   R(   R)   R6   (    (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR-   y   s   &t   JSONObjectWithFieldsc           B   sn   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z RS(	   sÒ  JSON object with fields.

    Example::

      class Foo(JSONObjectWithFields):
          bar = Field('Bar')
          empty = Field('Empty', omitempty=True)

          @bar.encoder
          def bar(value):
              return value + 'bar'

          @bar.decoder
          def bar(value):
              if not value.endswith('bar'):
                  raise errors.DeserializationError('No bar suffix!')
              return value[:-3]

      assert Foo(bar='baz').to_partial_json() == {'Bar': 'bazbar'}
      assert Foo.from_json({'Bar': 'bazbar'}) == Foo(bar='baz')
      assert (Foo.from_json({'Bar': 'bazbar', 'Empty': '!'})
              == Foo(bar='baz', empty='!'))
      assert Foo(bar='baz').bar == 'baz'

    c         C   s8   t  g  t j |  j ƒ D] \ } } | | j f ^ q ƒ S(   s   Get default fields values.(   R   R%   R&   R.   R   (   R   t   slott   field(    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt	   _defaultsÑ   s    c         K   s)   t  t |  ƒ j t |  j ƒ  |    d  S(   N(   t   superR=   R   R   R@   (   R   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR   ×   s    c         C   sS   y |  j  | } Wn) t k
 r< t j d j | ƒ ƒ ‚ n X| j t |  | ƒ ƒ S(   sß   Encode a single field.

        :param str name: Name of the field to be encoded.

        :raises errors.SerializationError: if field cannot be serialized
        :raises errors.Error: if field could not be found

        s   Field not found: {0}(   R.   t   KeyErrorR   t   Errort   formatR   R0   (   R   R8   R?   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR   Ü   s
    	c         C   s»   i  } t  ƒ  } x¥ t j |  j ƒ D]‘ \ } } t |  | ƒ } | j | ƒ rb | j | | f ƒ q" y | j | ƒ | | j <Wq" t	 j
 k
 r² } t	 j
 d j | | | ƒ ƒ ‚ q" Xq" W| S(   s   Serialize fields to JSON.s   Could not encode {0} ({1}): {2}(   t   setR%   R&   R.   R0   R   t   addR   R   R   t   SerializationErrorRD   (   R   t   jobjt   omittedR>   R?   R   t   error(    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   fields_to_partial_jsonì   s    	c         C   s
   |  j  ƒ  S(   N(   RK   (   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   to_partial_jsonþ   s    c         C   s†   t  ƒ  } xL t j |  j ƒ D]8 \ } } | j r | j | k r | j | j ƒ q q W| r‚ t j d j	 d j
 | ƒ ƒ ƒ ‚ n  d  S(   Ns&   The following fields are required: {0}t   ,(   RE   R%   R&   R.   R   R   RF   R   t   DeserializationErrorRD   t   join(   R   RH   t   missingt   _R?   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   _check_required  s    	c         C   s½   |  j  | ƒ i  } x£ t j |  j ƒ D] \ } } | j | k rZ | j rZ | j | | <q& | | j } y | j | ƒ | | <Wq& t j	 k
 r´ } t j	 d j
 | | | ƒ ƒ ‚ q& Xq& W| S(   s   Deserialize fields from JSON.s#   Could not decode {0!r} ({1!r}): {2}(   RR   R%   R&   R.   R   R   R   R   R   RN   RD   (   R   RH   R;   R>   R?   R   RJ   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   fields_from_json  s    c         C   s   |  |  j  | ƒ   S(   N(   RS   (   R   RH   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt	   from_json  s    (   R'   R(   R)   R,   R@   R   R   RK   RL   RR   RS   RT   (    (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyR=   ´   s   				c         C   s   t  j |  ƒ j d ƒ S(   sN   Encode JOSE Base-64 field.

    :param bytes data:
    :rtype: `unicode`

    t   ascii(   R    t	   b64encodeR   (   t   data(    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   encode_b64jose$  s    c         C   s²   t  j r t n t j } y t j |  j ƒ  ƒ } Wn" | k
 rU } t j	 | ƒ ‚ n X| d k	 r® | r{ t | ƒ | k s“ | r® t | ƒ | k  r® t j	 d j | ƒ ƒ ‚ n  | S(   s  Decode JOSE Base-64 field.

    :param unicode data:
    :param int size: Required length (after decoding).
    :param bool minimum: If ``True``, then `size` will be treated as
        minimum required length, as opposed to exact equality.

    :rtype: bytes

    s&   Expected at least or exactly {0} bytesN(   R%   t   PY2t	   TypeErrort   binasciiRC   R    t	   b64decodeR   R   RN   R
   t   lenRD   (   RW   t   sizet   minimumt	   error_clst   decodedRJ   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   decode_b64jose/  s    %c         C   s   t  j |  ƒ j ƒ  S(   s;   Hexlify.

    :param bytes value:
    :rtype: unicode

    (   R[   t   hexlifyR   (   R   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   encode_hex16H  s    c      	   C   s²   |  j  ƒ  }  | d k	 r` | r5 t |  ƒ | d k sQ | r` t |  ƒ | d k  r` t j ƒ  ‚ n  t j ro t n t j	 } y t j
 |  ƒ SWn" | k
 r­ } t j | ƒ ‚ n Xd S(   s  Decode hexlified field.

    :param unicode value:
    :param int size: Required length (after decoding).
    :param bool minimum: If ``True``, then `size` will be treated as
        minimum required length, as opposed to exact equality.

    :rtype: bytes

    i   N(   R   R
   R]   R   RN   R%   RY   RZ   R[   RC   t	   unhexlify(   R   R^   R_   R`   RJ   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   decode_hex16R  s    )c         C   s"   t  t j j t j j |  j ƒ ƒ S(   s…   Encode certificate as JOSE Base-64 DER.

    :type cert: `OpenSSL.crypto.X509` wrapped in `.ComparableX509`
    :rtype: unicode

    (   RX   t   OpenSSLt   cryptot   dump_certificatet   FILETYPE_ASN1t   wrapped(   t   cert(    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   encode_certh  s    c         C   s[   y, t  j t j j t j j t |  ƒ ƒ ƒ SWn( t j j k
 rV } t j	 | ƒ ‚ n Xd S(   s   Decode JOSE Base-64 DER-encoded certificate.

    :param unicode b64der:
    :rtype: `OpenSSL.crypto.X509` wrapped in `.ComparableX509`

    N(
   R   t   ComparableX509Rg   Rh   t   load_certificateRj   Rb   RC   R   RN   (   t   b64derRJ   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   decode_certs  s
    c         C   s"   t  t j j t j j |  j ƒ ƒ S(   s   Encode CSR as JOSE Base-64 DER.

    :type csr: `OpenSSL.crypto.X509Req` wrapped in `.ComparableX509`
    :rtype: unicode

    (   RX   Rg   Rh   t   dump_certificate_requestRj   Rk   (   t   csr(    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt
   encode_csr  s    c         C   s[   y, t  j t j j t j j t |  ƒ ƒ ƒ SWn( t j j k
 rV } t j	 | ƒ ‚ n Xd S(   sˆ   Decode JOSE Base-64 DER-encoded CSR.

    :param unicode b64der:
    :rtype: `OpenSSL.crypto.X509Req` wrapped in `.ComparableX509`

    N(
   R   Rn   Rg   Rh   t   load_certificate_requestRj   Rb   RC   R   RN   (   Rp   RJ   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt
   decode_csrŒ  s
    t   TypedJSONObjectWithFieldsc           B   sY   e  Z d  Z e Z d Z e Z e d d „ ƒ Z	 e d „  ƒ Z
 d „  Z e d „  ƒ Z RS(   s   JSON object with type.R   c         C   s,   | d k r | j n | } | |  j | <| S(   s(   Register class for JSON deserialization.N(   R
   t   typt   TYPES(   R   t   type_clsRx   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   registerª  s    c         C   sà   |  t  j |  j ƒ k rI |  j | k rE t j d j |  j ƒ ƒ ‚ n  |  St | t ƒ ss t j d j | ƒ ƒ ‚ n  y | |  j } Wn  t	 k
 r¦ t j d ƒ ‚ n Xy |  j | SWn# t	 k
 rÛ t j
 | | ƒ ‚ n Xd S(   s&   Get the registered class for ``jobj``.s   Missing type field ({0})s   {0} is not a dictionary objects   missing type fieldN(   R%   t
   itervaluesRy   t   type_field_nameR   RN   RD   R   R   RB   t   UnrecognizedTypeError(   R   RH   Rx   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   get_type_cls±  s     c         C   s    |  j  ƒ  } |  j | |  j <| S(   s  Get JSON serializable object.

        :returns: Serializable JSON object representing ACME typed object.
            :meth:`validate` will almost certainly not work, due to reasons
            explained in :class:`josepy.interfaces.IJSONSerializable`.
        :rtype: dict

        (   RK   Rx   R}   (   R   RH   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyRL   Ê  s    	c         C   s"   |  j  | ƒ } | | j | ƒ   S(   s¯   Deserialize ACME object from valid JSON object.

        :raises josepy.errors.UnrecognizedTypeError: if type
            of the ACME object has not been registered.

        (   R   RS   (   R   RH   Rz   (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyRT   ×  s    	N(   R'   R(   R)   t   NotImplementedRx   R}   Ry   R,   R
   R{   R   RL   RT   (    (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyRw   š  s   	(!   R)   R4   R[   t   loggingRg   R%   t   josepyR    R   R   R   t	   getLoggerR'   t   loggert   objectR   R5   R-   t   add_metaclasst   ImmutableMapt   JSONDeSerializableR=   RX   R
   R+   Rb   Rd   Rf   Rm   Rq   Rt   Rv   Rw   (    (    (    s4   /usr/lib/python2.7/site-packages/josepy/json_util.pyt   <module>   s(   "d;o		
				