U
    Y»{j.  ã                   @   s|   d dl mZmZ d dlZd dlmZ d dlT d dlT 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 )é    )Úabsolute_importÚdivisionN)ÚPrettyPrinter)Ú*éÈ   é   éP   c           
   	   C   s¾   t | tƒrd\}}n$t | tƒr(d\}}ntdt| ƒ ƒ‚t| ƒ|krJ| }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   úK/var/www/html/bwave/python/venv/lib/python3.8/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   Z	open_charZ
close_charZdisp_vZv_strZ	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__:   s    zElidedWrapper.__init__c                 C   s^   t dƒ}t| ttfƒr4t| ƒdkr4t| d tƒs4dS |rHt| |jƒrHdS t| tƒrVdS dS d S )NÚnumpyr   TF)Ú
get_moduler   r   r   r   ÚdictÚndarrayr   )r#   r,   r   r   r   Úis_wrappable?   s    (
zElidedWrapper.is_wrappablec                 C   s   t dƒ}t| jttfƒr0t| j| j| jd�}|S |rœt| j|jƒrœ| 	¡ }|j
f t|| jddd�Ž | j ¡ }| d¡}dd| j   |¡}|j
f |Ž |S t| jtƒròt| jƒdkrædt| jd d	… ƒ d
 t| jdd … ƒ d S | j ¡ S n
| j ¡ S d S )Nr,   )r$   r&   r   r   )r$   r%   Z	linewidthr   r   r   é   z ... iâÿÿÿr   )r-   r   r#   r   r   r'   r$   r&   r/   Zget_printoptionsZset_printoptionsr.   Ú__repr__Úsplitr   r   r   Úrepr)r*   r,   ÚresZ	orig_optsZ	res_linesr   r   r   r2   K   s.      ÿÿ

0zElidedWrapper.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r+   Ústaticmethodr0   r2   r   r   r   r   r(   3   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| f|ž|Ž d S )Nr$   r   )Úpopr$   r   r+   )r*   ÚargsÚkwargsr   r   r   r+   v   s    zElidedPrettyPrinter.__init__c              	   C   sF   t  |¡r,t || j|ƒ}|  ||||||¡S t | ||||||¡S d S r)   )r(   r0   r$   Ú_formatr   )r*   ÚvalÚstreamr&   Z	allowanceÚcontextÚlevelZ
elided_valr   r   r   r?   z   s    
      ÿzElidedPrettyPrinter._formatN)r6   r7   r8   r9   r+   r?   r   r   r   r   r;   q   s   r;   r   c                 c   sT   t | tƒsdS | |fV  |  ¡ D ].\}}t |tƒr t|||f ƒD ]
}|V  qBq 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   r.   ÚitemsÚnode_generator)ÚnodeÚpathÚkeyr@   Úitemr   r   r   rE   …   s    


rE   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   )ÚobjrG   rH   r   r   r   Úget_by_path¦   s    
rK   c              	   C   s  t | tƒrjt| ƒD ]T\}}t |ttfƒr6t|ƒ| |< qt |tƒrzt|ƒ| |< W q tk
rd   Y qX qn˜t | tƒ�rt|  ¡ ƒt|  ¡ ƒ }}t	||ƒD ]f\}}t |ttfƒr¾t|ƒ| |< n0t |tƒrîzt|ƒ| |< W n tk
rì   Y nX |  
|¡| t|ƒ< qš| S r)   )r   r   Ú	enumerater.   Údecode_unicoder   ÚUnicodeEncodeErrorÚkeysÚvaluesÚzipr<   )ZcollÚnoÚentryrO   ÚvalsrH   r@   r   r   r   rM   »   s*    



rM   )r   r   r   r   )r   )Ú
__future__r   r   r    Úpprintr   Z_plotly_utils.utilsZ_plotly_utils.data_utilsr'   Úobjectr(   r;   rE   rK   rM   r   r   r   r   Ú<module>   s   
)>
!