Your IP : 3.137.219.221


Current Path : /opt/alt/python34/lib64/python3.4/json/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/json/__pycache__/encoder.cpython-34.pyo

�
e f�=�@s�dZddlZyddlmZWnek
r@dZYnXyddlmZWnek
rodZYnXejd�Z	ejd�Z
ejd�Zidd	6d
d6dd
6dd6dd6dd6dd6Zx3e
d�D]%Zejee�dje��q�Wed�ZeZdd�Zdd�Zep=eZGdd�de�Zeeeeeeee e!dd �	Z"dS)!zImplementation of JSONEncoder
�N)�encode_basestring_ascii)�make_encoderz[\x00-\x1f\\"\b\f\n\r\t]z([\\"]|[^\ -~])s[�-�]z\\�\z\"�"z\b�z\f�z\n�
z\r�
z\t�	� z	\u{0:04x}�infcCs$dd�}dtj||�dS)z5Return a JSON representation of a Python string

    cSst|jd�S)Nr)�
ESCAPE_DCT�group)�match�r�1/opt/alt/python34/lib64/python3.4/json/encoder.py�replace%sz"encode_basestring.<locals>.replacer)�ESCAPE�sub)�srrrr�encode_basestring!srcCs$dd�}dtj||�dS)zAReturn an ASCII-only JSON representation of a Python string

    cSs�|jd�}yt|SWnqtk
r�t|�}|dkrPdj|�S|d8}d|d?d@B}d|d@B}dj||�SYnXdS)	Nriz	\u{0:04x}i��
i�i�z\u{0:04x}\u{1:04x})rr
�KeyError�ord�format)rr�n�s1�s2rrrr.s


z+py_encode_basestring_ascii.<locals>.replacer)�ESCAPE_ASCIIr)rrrrr�py_encode_basestring_ascii*src
@smeZdZdZdZdZdddddddddd�Zd	d
�Zdd�Zdd
d�Z	dS)�JSONEncoderaZExtensible JSON <http://json.org> encoder for Python data structures.

    Supports the following objects and types by default:

    +-------------------+---------------+
    | Python            | JSON          |
    +===================+===============+
    | dict              | object        |
    +-------------------+---------------+
    | list, tuple       | array         |
    +-------------------+---------------+
    | str               | string        |
    +-------------------+---------------+
    | int, float        | number        |
    +-------------------+---------------+
    | True              | true          |
    +-------------------+---------------+
    | False             | false         |
    +-------------------+---------------+
    | None              | null          |
    +-------------------+---------------+

    To extend this to recognize other objects, subclass and implement a
    ``.default()`` method with another method that returns a serializable
    object for ``o`` if possible, otherwise it should call the superclass
    implementation (to raise ``TypeError``).

    z, z: FTNc		Cs�||_||_||_||_||_||_|dk	rW|\|_|_n|dk	rod|_n|dk	r�||_ndS)a�Constructor for JSONEncoder, with sensible defaults.

        If skipkeys is false, then it is a TypeError to attempt
        encoding of keys that are not str, int, float or None.  If
        skipkeys is True, such items are simply skipped.

        If ensure_ascii is true, the output is guaranteed to be str
        objects with all incoming non-ASCII characters escaped.  If
        ensure_ascii is false, the output can contain non-ASCII characters.

        If check_circular is true, then lists, dicts, and custom encoded
        objects will be checked for circular references during encoding to
        prevent an infinite recursion (which would cause an OverflowError).
        Otherwise, no such check takes place.

        If allow_nan is true, then NaN, Infinity, and -Infinity will be
        encoded as such.  This behavior is not JSON specification compliant,
        but is consistent with most JavaScript based encoders and decoders.
        Otherwise, it will be a ValueError to encode such floats.

        If sort_keys is true, then the output of dictionaries will be
        sorted by key; this is useful for regression tests to ensure
        that JSON serializations can be compared on a day-to-day basis.

        If indent is a non-negative integer, then JSON array
        elements and object members will be pretty-printed with that
        indent level.  An indent level of 0 will only insert newlines.
        None is the most compact representation.

        If specified, separators should be an (item_separator, key_separator)
        tuple.  The default is (', ', ': ') if *indent* is ``None`` and
        (',', ': ') otherwise.  To get the most compact JSON representation,
        you should specify (',', ':') to eliminate whitespace.

        If specified, default is a function that gets called for objects
        that can't otherwise be serialized.  It should return a JSON encodable
        version of the object or raise a ``TypeError``.

        N�,)	�skipkeys�ensure_ascii�check_circular�	allow_nan�	sort_keys�indent�item_separator�
key_separator�default)	�selfr"r#r$r%r&r'Z
separatorsr*rrr�__init__bs+						zJSONEncoder.__init__cCstt|�d��dS)alImplement this method in a subclass such that it returns
        a serializable object for ``o``, or calls the base implementation
        (to raise a ``TypeError``).

        For example, to support arbitrary iterators, you could
        implement default like this::

            def default(self, o):
                try:
                    iterable = iter(o)
                except TypeError:
                    pass
                else:
                    return list(iterable)
                # Let the base class default method raise the TypeError
                return JSONEncoder.default(self, o)

        z is not JSON serializableN)�	TypeError�repr)r+�orrrr*�szJSONEncoder.defaultcCsut|t�r/|jr"t|�St|�Sn|j|dd�}t|ttf�sht|�}ndj|�S)z�Return a JSON string representation of a Python data structure.

        >>> from json.encoder import JSONEncoder
        >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
        '{"foo": ["bar", "baz"]}'

        �	_one_shotT�)	�
isinstance�strr#rr�
iterencode�list�tuple�join)r+r/�chunksrrr�encode�s		

zJSONEncoder.encodecCs�|jri}nd}|jr*t}nt}|jtttdd�}|r�tdk	r�|jdkr�t||j	||j|j
|j|j|j
|j�	}n9t||j	||j||j
|j|j|j
|�
}||d�S)z�Encode the given object and yield each string
        representation as available.

        For example::

            for chunk in JSONEncoder().iterencode(bigobject):
                mysocket.write(chunk)

        NcSsl||krd}n4||kr*d}n||kr?d}n
||�S|shtdt|���n|S)NZNaNZInfinityz	-Infinityz2Out of range float values are not JSON compliant: )�
ValueErrorr.)r/r%Z_reprZ_infZ_neginf�textrrr�floatstr�s			
z(JSONEncoder.iterencode.<locals>.floatstrr)r$r#rrr%�
FLOAT_REPR�INFINITY�c_make_encoderr'r*r)r(r&r"�_make_iterencode)r+r/r0�markers�_encoderr<�_iterencoderrrr4�s&
				zJSONEncoder.iterencode)
�__name__�
__module__�__qualname__�__doc__r(r)r,r*r9r4rrrrr Cs	6r cs��dk	r)����r)d��n����������
�������fdd�����������	�
���
�������fdd�����������
�������fdd���S)N� c	3s)|sdVdS�dk	rO�
|�}|�krB�d��n|�|<nd}�dk	r�|d7}d�|}�|}||7}nd}�}d}x?|D]7}|r�d}n|}�|��r�|�|�Vq�|dkr�|dVq�|dkr|d	Vq�|dkr-|d
Vq��|��rT|��|��Vq��|�	�r{|��	|��Vq�|V�|�
�f�r��||�}n0�|��r��||�}n�||�}|DdHq�W|dk	r
|d8}d�|VndV�dk	r%�|=ndS)Nz[]zCircular reference detected�[�rTF�null�true�false�]r)	Zlst�_current_indent_level�markeridZbuf�newline_indentZ	separator�first�valuer8)r:rB�	_floatstr�_indent�_item_separatorrC�_iterencode_dict�_iterencode_list�dict�float�id�intr2r5rAr3r6rrrX
s\




	

z*_make_iterencode.<locals>._iterencode_listc
3s
|sdVdS�dk	rO�
|�}|�krB�d��n|�|<ndV�dk	r�|d7}d�|}�|}|Vnd}�}d}�
r�t|j�ddd	��}n|j�}x�|D]�\}}�|��r�n��|��r��|��}n�|dkr-d
}nt|dkrBd}n_|dkrWd
}nJ�|��r{��|��}n&�	r�q�ntdt|�d��|r�d}n|V�|�V�V�|��r��|�Vq�|dkr�d
Vq�|dkr
d
Vq�|dkrdVq��|��rA��|��Vq��|��rd��|��Vq��|��f�r��||�}	n0�|��r��||�}	n�||�}	|	DdHq�W|dk	r�|d8}d�|VndV�dk	r	�|=ndS)Nz{}zCircular reference detected�{rJrT�keycSs|dS)Nrr)Zkvrrr�<lambda>Ysz<_make_iterencode.<locals>._iterencode_dict.<locals>.<lambda>rLFrMrKzkey z is not a string�})�sorted�itemsr-r.)
ZdctrOrPrQr(rRrbr^rSr8)r:rBrTrUrVrCrWrX�_key_separator�	_skipkeys�
_sort_keysrYrZr[r\r2r5rAr3r6rrrWEs�


!				

z*_make_iterencode.<locals>._iterencode_dictc3se�|��r�|�VnD|dkr1dVn0|dkrEdVn|dkrYdVn�|�
�r|��
|��Vn��|��r���|��Vn��|��f�r��||�DdHn��|��r��||�DdHnt�
dk	r-�	|�}|�
kr �d��n|�
|<n�|�}�||�DdH�
dk	ra�
|=ndS)NrKTrLFrMzCircular reference detectedr)r/rOrP)r:�_defaultrBrTrCrWrXrYrZr[r\r2r5rAr3r6rrrC�s2
z%_make_iterencode.<locals>._iterencoder)rArfrBrUrTrcrVrerdr0r:rYrZr[r\r2r5r3r6r)r:rfrBrTrUrVrCrWrXrcrdrerYrZr[r\r2r5rAr3r6rr@�s
B8KO?r@)#rG�reZ_jsonrZc_encode_basestring_ascii�ImportErrorrr?�compilerrZHAS_UTF8r
�range�i�
setdefault�chrrrZr>r.r=rr�objectr r:rYr[r\r2r5r3r6r@rrrr�<module>sJ


#	�

?>