B
    £'=[h  ã               @   s8   d 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é    )ÚStruct)ÚMappingc                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚNotebookNodez&A dict-like node with attribute-accessc                s2   t |tƒrt |tƒst|ƒ}tt| ƒ ||¡ d S )N)Ú
isinstancer   r   Ú	from_dictÚsuperÚ__setitem__)ÚselfÚkeyÚvalue)Ú	__class__© ú4lib/python3.7/site-packages/nbformat/notebooknode.pyr   
   s    zNotebookNode.__setitem__c             O   s´   t |ƒdkrtdt |ƒ ƒ‚|r’|d }t|tƒrNx^|D ]}|| | |< q8W nDt|dƒrxx8| ¡ D ]}|| | |< qbW nx|D ]\}}|| |< q~W x| ¡ D ]\}}|| |< qœW dS )zf
        A dict-like update method based on CPython's MutableMapping `update`
        method.
        é   z+update expected at most 1 arguments, got %dr   ÚkeysN)ÚlenÚ	TypeErrorr   r   Úhasattrr   Ú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   sD   t | tƒr tdd„ |  ¡ D ƒƒS t | ttfƒr<dd„ | D ƒS | S d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>.   s    zfrom_dict.<locals>.<dictcomp>c             S   s   g | ]}t |ƒ‘qS r   )r   )r   Úir   r   r   ú
<listcomp>0   s    zfrom_dict.<locals>.<listcomp>N)r   Údictr   r   ÚtupleÚlist)Údr   r   r   r   &   s
    
r   N)r   Zipython_genutils.ipstructr   Úcollectionsr   r   r   r   r   r   r   Ú<module>   s   