U
    H$xe0                     @   s.   d dl Z G dd dZdeeedddZdS )	    Nc                   @   s   e Zd ZdZdd ZdS )OneLinezEWrap any value in this class to print it on one line in the JSON filec                 C   s
   || _ d S )N)value)selfr    r   ,lib/python3.8/site-packages/cutadapt/json.py__init__   s    zOneLine.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r      )indent_levelreturnc                    s   t | tttttfs| dkr6t | tr,| j} t| S d d  d  }d| }d  d  }t | t	t
fr| sxdS d| | fdd	| D  | d
 S t | tr| sdS d| | fdd	|  D  | d S td| jj dS )a  
    Encode an object hierarchy as JSON string. In addition to
    what json.dumps in the standard library provides, this function
    allows disabling indentation for selected parts of the hierarchy
    by marking lists or dicts with the "OneLine" class.

    Arguments:
        obj: object to encode
        indent: indentation level

    >>> print(dumps({"a": [1, 2], "b": OneLine([3, 4]), "c": dict(x=5, y=6), "d": OneLine(dict(x=7, y=8))}))
    {
      "a": [
        1,
        2
      ],
      "b": [3, 4],
      "c": {
        "x": 5,
        "y": 6
      },
      "d": {"x": 7, "y": 8}
    }
    >>> print(dumps({"a": []}))
    {
      "a": []
    }
    N
    ,z[][c                 3   s   | ]}t | d  V  qdS )r   N)dumps).0elemr   r   r   r   	<genexpr>6   s     zdumps.<locals>.<genexpr>]z{}{c                 3   s0   | ](\}}t |d  t| d  V  qdS )z: r   N)jsonr   )r   kvr   r   r   r   @   s   }zcannot serialize type )
isinstancefloatintstrboolr   r   r   r   tuplelistjoindictitems
ValueError	__class__r   )objr   r   startsependr   r   r   r      sH    


r   )r   r   )r   r   r"   r#   r   r   r   r   r   <module>   s   