404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.22.71.246: ~ $
3

�}:ah=�@s�dZddlZddlZddlZddlmZmZddlZddlm	Z	m
Z
mZmZej
e�ZGdd�d�ZGdd�dej�ZGd	d
�d
ejejed�Zeed�d
d�Zd dd�Zdd�Zd!dd�Zdd�Zdd�Zdd�Zdd�ZGdd�de�Z dS)"z�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/

�N)�Dict�Type)�b64�errors�
interfaces�utilc@sreZdZdZdZdd	d
�Zedd��Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
edd��Zedd��ZdS)�Fielda�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.

    �	json_name�default�	omitempty�fdec�fencNFcCs>||_||_||_|dkr |jn||_|dkr4|jn||_dS)N)r	r
r�default_decoderr�default_encoderr
)�selfr	r
r�decoder�encoder�r�/usr/lib/python3.6/json_util.py�__init__/s
zField.__init__cCst|t�o|S)z�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.

        )�
isinstance�bool)�cls�valuerrr�_empty9szField._emptycCs|j|�o|jS)zOmit the value in output?)rr)rrrrr�omitCsz
Field.omitcKs,|j|j|j|j|jd�|�}t|�f|�S)N)r	r
rrr)r	r
rrr
�type)r�kwargsZcurrentrrr�_update_paramsGs
zField._update_paramscCs|j|d�S)z6Descriptor to change the decoder on JSON object field.)r)r)rrrrrrPsz
Field.decodercCs|j|d�S)z6Descriptor to change the encoder on JSON object field.)r)r)rr
rrrrTsz
Field.encodercCs
|j|�S)z4Decode a value, optionally with context JSON object.)r)rrrrr�decodeXszField.decodecCs
|j|�S)z4Encode a value, optionally with context JSON object.)r
)rrrrr�encode\szField.encodecsNt|t�r t�fdd�|D��St|t�rFtj�fdd�|j�D��S|SdS)z�Default decoder.

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

        c3s|]}�j|�VqdS)N)r)�.0Zsubvalue)rrr�	<genexpr>ksz(Field.default_decoder.<locals>.<genexpr>cs"i|]\}}�j|��j|��qSr)r)r!�keyr)rrr�
<dictcomp>nsz)Field.default_decoder.<locals>.<dictcomp>N)r�list�tuple�dictrZ
frozendict�items)rrr)rrr`s



zField.default_decodercCs|S)zDefault (passthrough) encoder.r)rrrrrrsszField.default_encoder)r	r
rrr
)NFNN)�__name__�
__module__�__qualname__�__doc__�	__slots__r�classmethodrrrrrrr rrrrrrrs
	
	rc@s*eZdZUdZiZeeefdd�ZdS)�JSONObjectWithFieldsMetaa�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:
          __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).

    cCs�i}x|D]}|jt|di��q
Wx0t|j��D] \}}t|t�r2|j|�||<q2W|jdf�|d<tt|d�t|j	���|d<||d<t
jj||||�S)N�_fieldsr-Z_orig_slots)
�update�getattrr&r(rr�pop�getr%�keys�abc�ABCMeta�__new__)Zmcs�name�basesZdikt�fields�baser#rrrrr8�s

z JSONObjectWithFieldsMeta.__new__N)	r)r*r+r,r0r�strrr8rrrrr/{s
&r/csneZdZdZeed�dd��Z�fdd�Zdd�Zd	d
�Z	dd�Z
ed
d��Zedd��Zedd��Z
�ZS)�JSONObjectWithFieldsa�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'

    )�returncCsdd�|jj�D�S)zGet default fields values.cSsi|]\}}|j|�qSr)r
)r!�slot�fieldrrrr$�sz2JSONObjectWithFields._defaults.<locals>.<dictcomp>)r0r()rrrr�	_defaults�szJSONObjectWithFields._defaultscst�jf|j�|��dS)N)�superrrB)rr)�	__class__rrr�szJSONObjectWithFields.__init__cCsDy|j|}Wn$tk
r2tjdj|���YnX|jt||��S)z�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

        zField not found: {0})r0�KeyErrorr�Error�formatr r2)rr9rArrrr �s
	zJSONObjectWithFields.encodecCs�i}t�}x�|jj�D]z\}}t||�}|j|�rB|j||f�qy|j|�||j<Wqtj	k
r�}ztj	dj
|||���WYdd}~XqXqW|S)zSerialize fields to JSON.zCould not encode {0} ({1}): {2}N)�setr0r(r2r�addr r	rZSerializationErrorrG)r�jobjZomittedr@rAr�errorrrr�fields_to_partial_json�s

"z+JSONObjectWithFields.fields_to_partial_jsoncCs|j�S)N)rL)rrrr�to_partial_jsonsz$JSONObjectWithFields.to_partial_jsoncCsZt�}x4|jj�D]&\}}|jr|j|kr|j|j�qW|rVtjdjdj	|����dS)Nz&The following fields are required: {0}�,)
rHr0r(rr	rIr�DeserializationErrorrG�join)rrJZmissing�_rArrr�_check_requiredsz$JSONObjectWithFields._check_requiredcCs�|j|�i}x�|jj�D]z\}}|j|kr>|jr>|j||<q||j}y|j|�||<Wqtjk
r�}ztjdj	|||���WYdd}~XqXqW|S)zDeserialize fields from JSON.z#Could not decode {0!r} ({1!r}): {2}N)
rRr0r(r	rr
rrrOrG)rrJr;r@rArrKrrr�fields_from_jsons

"z%JSONObjectWithFields.fields_from_jsoncCs|f|j|��S)N)rS)rrJrrr�	from_json&szJSONObjectWithFields.from_json)r)r*r+r,r.rrBrr rLrMrRrSrT�
__classcell__rr)rDrr>�sr>)�	metaclass)�datar?cCstj|�jd�S)zJEncode JOSE Base-64 field.

    :param bytes data:
    :rtype: `str`

    �ascii)rZ	b64encoder)rWrrr�encode_b64jose+srYFcCs�ytj|j��}Wn.tjk
r@}ztj|��WYdd}~XnX|dk	r||r\t|�|ksl|r|t|�|kr|tjdj|���|S)aDecode 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

    Nz&Expected at least or exactly {0} bytes)	rZ	b64decoder �binasciirFrrO�lenrG)rW�size�minimumZdecodedrKrrr�decode_b64jose6sr^cCstj|�j�S)z;Hexlify.

    :param bytes value:
    :rtype: unicode

    )rZZhexlifyr)rrrr�encode_hex16Nsr_cCs�|j�}|dk	rB|r&t|�|dks:|rBt|�|dkrBtj��y
tj|�Stjk
rz}ztj|��WYdd}~XnXdS)aDecode 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

    N�)r r[rrOrZZ	unhexlifyrF)rr\r]rKrrr�decode_hex16Xs
racCsttjjtjj|j��S)z�Encode certificate as JOSE Base-64 DER.

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

    )rY�OpenSSL�cryptoZdump_certificate�
FILETYPE_ASN1�wrapped)Zcertrrr�encode_certmsrfcCsRytjtjjtjjt|���Stjjk
rL}ztj	|��WYdd}~XnXdS)z�Decode JOSE Base-64 DER-encoded certificate.

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

    N)
r�ComparableX509rbrcZload_certificaterdr^rFrrO)�b64derrKrrr�decode_certxs

ricCsttjjtjj|j��S)zEncode CSR as JOSE Base-64 DER.

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

    )rYrbrcZdump_certificate_requestrdre)Zcsrrrr�
encode_csr�srjcCsRytjtjjtjjt|���Stjjk
rL}ztj	|��WYdd}~XnXdS)z�Decode JOSE Base-64 DER-encoded CSR.

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

    N)
rrgrbrcZload_certificate_requestrdr^rFrrO)rhrKrrr�
decode_csr�s

rkc@s`eZdZUdZeZedZeeZe	ee
feddd��Zedd��Z
dd	�Zed
d��ZdS)
�TypedJSONObjectWithFieldszJSON object with type.rNcCs |dkr|jn|}||j|<|S)z(Register class for JSON deserialization.N)�typ�TYPES)r�type_clsrmrrr�register�s
z"TypedJSONObjectWithFields.registercCs�||jj�kr.|j|kr*tjdj|j���|St|t�sHtjdj|���y||j}Wntk
rttjd��YnXy
|j|Stk
r�tj	||��YnXdS)z&Get the registered class for ``jobj``.zMissing type field ({0})z{0} is not a dictionary objectzmissing type fieldN)
rn�values�type_field_namerrOrGrr'rEZUnrecognizedTypeError)rrJrmrrr�get_type_cls�s 


z&TypedJSONObjectWithFields.get_type_clscCs|j�}|j||j<|S)aGet 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

        )rLrmrr)rrJrrrrM�s	z)TypedJSONObjectWithFields.to_partial_jsoncCs|j|�}|f|j|��S)z�Deserialize ACME object from valid JSON object.

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

        )rsrS)rrJrorrrrT�s	
z#TypedJSONObjectWithFields.from_json)N)r)r*r+r,�NotImplementedrmr=rrrnrrr.rprsrMrTrrrrrl�s

rl)NF)NF)!r,r6rZZloggingZtypingrrrbZjosepyrrrrZ	getLoggerr)Zloggerrr7r/ZImmutableMapZJSONDeSerializabler>�bytesr=rYr^r_rarfrirjrkrlrrrr�<module>s*
f>p




Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 1.95 KB 0644
__init__.cpython-36.pyc File 1.95 KB 0644
b64.cpython-36.opt-1.pyc File 1.56 KB 0644
b64.cpython-36.pyc File 1.56 KB 0644
b64_test.cpython-36.opt-1.pyc File 3.47 KB 0644
b64_test.cpython-36.pyc File 3.47 KB 0644
errors.cpython-36.opt-1.pyc File 1.55 KB 0644
errors.cpython-36.pyc File 1.55 KB 0644
errors_test.cpython-36.opt-1.pyc File 854 B 0644
errors_test.cpython-36.pyc File 854 B 0644
interfaces.cpython-36.opt-1.pyc File 7.93 KB 0644
interfaces.cpython-36.pyc File 7.93 KB 0644
interfaces_test.cpython-36.opt-1.pyc File 5.38 KB 0644
interfaces_test.cpython-36.pyc File 5.38 KB 0644
json_util.cpython-36.opt-1.pyc File 14.93 KB 0644
json_util.cpython-36.pyc File 14.93 KB 0644
json_util_test.cpython-36.opt-1.pyc File 17.19 KB 0644
json_util_test.cpython-36.pyc File 17.19 KB 0644
jwa.cpython-36.opt-1.pyc File 7.73 KB 0644
jwa.cpython-36.pyc File 7.73 KB 0644
jwa_test.cpython-36.opt-1.pyc File 9.67 KB 0644
jwa_test.cpython-36.pyc File 9.67 KB 0644
jwk.cpython-36.opt-1.pyc File 11.66 KB 0644
jwk.cpython-36.pyc File 11.66 KB 0644
jwk_test.cpython-36.opt-1.pyc File 12.73 KB 0644
jwk_test.cpython-36.pyc File 12.73 KB 0644
jws.cpython-36.opt-1.pyc File 12.1 KB 0644
jws.cpython-36.pyc File 12.49 KB 0644
jws_test.cpython-36.opt-1.pyc File 9.4 KB 0644
jws_test.cpython-36.pyc File 9.4 KB 0644
magic_typing.cpython-36.opt-1.pyc File 775 B 0644
magic_typing.cpython-36.pyc File 775 B 0644
magic_typing_test.cpython-36.opt-1.pyc File 1.07 KB 0644
magic_typing_test.cpython-36.pyc File 1.07 KB 0644
test_util.cpython-36.opt-1.pyc File 2.77 KB 0644
test_util.cpython-36.pyc File 2.77 KB 0644
util.cpython-36.opt-1.pyc File 9.76 KB 0644
util.cpython-36.pyc File 9.84 KB 0644
util_test.cpython-36.opt-1.pyc File 11.62 KB 0644
util_test.cpython-36.pyc File 11.62 KB 0644