U
    kufu  ã                   @  sD   d Z ddlmZ ddlmZ ddlmZ G dd„ deƒZdd	„ Zd
S )z/NotebookNode - adding attribute access to dictsé    )Úannotations)ÚMappingé   )ÚStructc                      s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚNotebookNodez&A dict-like node with attribute-accessc                   s.   t |tƒrt |tƒst|ƒ}tƒ  ||¡ dS )zSet an item on the notebook.N)Ú
isinstancer   r   Ú	from_dictÚsuperÚ__setitem__)ÚselfÚkeyÚvalue©Ú	__class__© ú9/tmp/pip-unpacked-wheel-zj9qk9v2/nbformat/notebooknode.pyr
      s    zNotebookNode.__setitem__c                 O  s    t |ƒdkrtdt |ƒ ƒ‚|r‚|d }t|tƒrJ|D ]}|| | |< q6n8t|dƒrl|D ]}|| | |< qXn|D ]\}}|| |< qp| ¡ D ]\}}|| |< qŠdS )zf
        A dict-like update method based on CPython's MutableMapping `update`
        method.
        r   z+update expected at most 1 arguments, got %dr   ÚkeysN)ÚlenÚ	TypeErrorr   r   ÚhasattrÚitems)r   ÚargsÚkwargsÚotherr   r   r   r   r   Úupdate   s    


zNotebookNode.update)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Ú__classcell__r   r   r   r   r   	   s   r   c                 C  s@   t | tƒr tdd„ |  ¡ D ƒƒS t | ttfƒr<dd„ | D ƒS | S )zßConvert dict to dict-like NotebookNode

    Recursively converts any dict in the container to a NotebookNode.
    This does not check that the contents of the dictionary make a valid
    notebook or part of a notebook.
    c                 S  s   i | ]\}}|t |ƒ“qS r   ©r   )Ú.0ÚkÚvr   r   r   Ú
<dictcomp>0   s      zfrom_dict.<locals>.<dictcomp>c                 S  s   g | ]}t |ƒ‘qS r   r    )r!   Úir   r   r   Ú
<listcomp>2   s     zfrom_dict.<locals>.<listcomp>)r   Údictr   r   ÚtupleÚlist)Údr   r   r   r   (   s
    
r   N)	r   Ú
__future__r   Úcollections.abcr   Ú_structr   r   r   r   r   r   r   Ú<module>   s
   