o
    MhY                     @   s|   d dl Z d dlmZ d dlmZmZmZ d dlmZ ddd	Z	G d
d de
ZG dd deZdddZdd Zdd ZdS )    N)PrettyPrinter)NotEncodablePlotlyJSONEncoder
get_module)image_array_to_data_uri      P   c           
   	   C   s   t | tr
d\}}nt | trd\}}ntdt|  t| |kr%| }nt| d| dg t| | d  }|ddd |D  | }d	tj||d
|d  d
|d  d	 }	|	S )a  
    Return a string representation for of a list where list is elided if
    it has more than n elements

    Parameters
    ----------
    v : list
        Input list
    threshold :
        Maximum number of elements to display

    Returns
    -------
    str
    )[])()zInvalid value of type: %sNz...z, c                 S   s   g | ]}t |qS  )str).0er   r   M/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/plotly/utils.py
<listcomp>%   s    z%_list_repr_elided.<locals>.<listcomp>
    )widthinitial_indentsubsequent_indent)

isinstancelisttuple
ValueErrortypelenjointextwrapwrapstrip)
v	threshold	edgeitemsindentr   	open_char
close_chardisp_vv_str	v_wrappedr   r   r   _list_repr_elided	   s(   



(

r-   c                   @   s,   e Zd ZdZdd Zedd Zdd ZdS )	ElidedWrapperz
    Helper class that wraps values of certain types and produces a custom
    __repr__() that may be elided and is suitable for use during pretty
    printing
    c                 C   s   || _ || _|| _d S N)r$   r'   r%   )selfr$   r%   r'   r   r   r   __init__9   s   
zElidedWrapper.__init__c                 C   sZ   t d}t| ttfrt| dkrt| d tsdS |r$t| |jr$dS t| tr+dS dS )Nnumpyr   TF)r   r   r   r   r   dictndarrayr   )r$   r2   r   r   r   is_wrappable>   s   (
zElidedWrapper.is_wrappablec              	   C   s  t d}t| jttfrt| j| j| jd}|S |rRt| j|jrR|	 }|j
di t|| jddd | j }|d}dd| j  |}|j
di | |S t| jtr|t| jdkrwdt| jd d	  d
 t| jdd   d S | j S | j S )Nr2   )r%   r'   r   r	   )r%   r&   	linewidthr   r   r      z ... ir   r   )r   r   r$   r   r   r-   r%   r'   r4   get_printoptionsset_printoptionsr3   __repr__splitr    r   r   repr)r0   r2   res	orig_opts	res_linesr   r   r   r:   J   s*   

0

zElidedWrapper.__repr__N)__name__
__module____qualname____doc__r1   staticmethodr5   r:   r   r   r   r   r.   2   s    
r.   c                   @   s    e Zd ZdZdd Zdd ZdS )ElidedPrettyPrinterzF
    PrettyPrinter subclass that elides long lists/arrays/strings
    c                 O   s*   | dd| _tj| g|R i | d S )Nr%   r   )popr%   r   r1   )r0   argskwargsr   r   r   r1   u   s   zElidedPrettyPrinter.__init__c              	   C   sB   t |rt || j|}| ||||||S t| ||||||S r/   )r.   r5   r%   _formatr   )r0   valstreamr'   	allowancecontextlevel
elided_valr   r   r   rI   y   s   
zElidedPrettyPrinter._formatN)r@   rA   rB   rC   r1   rI   r   r   r   r   rE   p   s    rE   r   c                 c   sV    t | tsdS | |fV  |  D ]\}}t |tr(t|||f D ]}|V  q"qdS )a  
    General, node-yielding generator.

    Yields (node, path) tuples when it finds values that are dict
    instances.

    A path is a sequence of hashable values that can be used as either keys to
    a mapping (dict) or indices to a sequence (list). A path is always wrt to
    some object. Given an object, a path explains how to get from the top level
    of that object to a nested value in the object.

    :param (dict) node: Part of a dict to be traversed.
    :param (tuple[str]) path: Defines the path of the current node.
    :return: (Generator)

    Example:

        >>> for node, path in node_generator({'a': {'b': 5}}):
        ...     print(node, path)
        {'a': {'b': 5}} ()
        {'b': 5} ('a',)

    N)r   r3   itemsnode_generator)nodepathkeyrJ   itemr   r   r   rQ      s   


rQ   c                 C   s   |D ]}| | } q| S )aR  
    Iteratively get on obj for each key in path.

    :param (list|dict) obj: The top-level object.
    :param (tuple[str]|tuple[int]) path: Keys to access parts of obj.

    :return: (*)

    Example:

        >>> figure = {'data': [{'x': [5]}]}
        >>> path = ('data', 0, 'x')
        >>> get_by_path(figure, path)
        [5]
    r   )objrS   rT   r   r   r   get_by_path   s   
rW   c              	   C   s  t | tr5t| D ])\}}t |ttfrt|| |< q	t |tr2zt|| |< W q	 ty1   Y q	w q	| S t | trt|  t|  }}t	||D ]2\}}t |ttfr^t|| |< nt |truzt|| |< W n	 tyt   Y nw | 
|| t|< qL| S r/   )r   r   	enumerater3   decode_unicoder   UnicodeEncodeErrorkeysvaluesziprF   )collnoentryr[   valsrT   rJ   r   r   r   rY      s2   



rY   )r   r   r   r	   )r   )r!   pprintr   _plotly_utils.utilsr   r   r   _plotly_utils.data_utilsr   r-   objectr.   rE   rQ   rW   rY   r   r   r   r   <module>   s    
)>
!