U
    j                     @   sJ   d dl mZ d dlmZ d
ddZdddZG dd	 d	eZddd	gZdS )    )
to_unicode)OrderedDictNc                    sV   dd t |pg D   fdd| D } fdd| D }t| fdddt| S )	zSorts leading keys according to canonical_order.  Keys not specified in
    canonical_order will appear alphabetically at the end.
    c                 S   s   i | ]\}}||qS  r   ).0ikr   r   :/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/caselessdict.py
<dictcomp>
   s      z"canonsort_keys.<locals>.<dictcomp>c                    s   g | ]}| kr|qS r   r   r   r   Zcanonical_mapr   r   
<listcomp>   s      z"canonsort_keys.<locals>.<listcomp>c                    s   g | ]}| kr|qS r   r   r
   r   r   r   r      s      c                    s    |  S Nr   )r   r   r   r   <lambda>       z canonsort_keys.<locals>.<lambda>)key)	enumeratesorted)keyscanonical_orderheadtailr   r   r   canonsort_keys   s    r   c                    s    fddt   |D S )z>Returns a list of items from dict1, sorted by canonical_order.c                    s   g | ]}| | fqS r   r   r
   dict1r   r   r      s     z#canonsort_items.<locals>.<listcomp>)r   r   )r   r   r   r   r   canonsort_items   s    r   c                       s   e Zd ZdZ fddZ fddZ fddZ fdd	Z fd
dZd% fdd	Z	d& fdd	Z
d' fdd	Z fddZ fddZdd Z fddZdd Zdd Zdd  ZdZd!d" Zd#d$ Z  ZS )(CaselessDictziA dictionary that isn't case sensitive, and only uses strings as keys.
    Values retain their case.
    c                    sL   t  j|| |  D ]0\}}t| }||krt  | || |< qdS )z#Set keys to upper for initial dict.N)super__init__itemsr   upper__delitem__)selfargskwargsr   valueZ	key_upper	__class__r   r   r      s    zCaselessDict.__init__c                    s   t |}t | S r   )r   r   __getitem__r   r!   r   r%   r   r   r'   #   s    zCaselessDict.__getitem__c                    s   t |}t | | d S r   )r   r   __setitem__r   r!   r   r$   r%   r   r   r)   '   s    zCaselessDict.__setitem__c                    s   t |}t |  d S r   )r   r   r    r   r(   r%   r   r   r    +   s    zCaselessDict.__delitem__c                    s   t |}t | S r   r   r   __contains__r   r(   r%   r   r   r,   /   s    zCaselessDict.__contains__Nc                    s   t |}t | |S r   )r   r   getr   r!   r   defaultr%   r   r   r-   3   s    zCaselessDict.getc                    s   t |}t | |S r   )r   r   
setdefaultr   r*   r%   r   r   r0   7   s    zCaselessDict.setdefaultc                    s   t |}t | |S r   )r   r   popr   r.   r%   r   r   r1   ;   s    zCaselessDict.popc                    s
   t   S r   )r   popitemr!   r%   r   r   r2   ?   s    zCaselessDict.popitemc                    s   t |}t | S r   r+   r(   r%   r   r   has_keyB   s    zCaselessDict.has_keyc                 O   sH   t ||g }|D ]0}t|dr,t| }|D ]\}}|| |< q0qd S )Nr   )listhasattriterr   )r!   r"   r#   Zmappingsmappingr   r$   r   r   r   updateF   s    
zCaselessDict.updatec                    s   t | t  S r   )typer   copyr3   r%   r   r   r;   O   s    zCaselessDict.copyc                 C   s   t | j dt|  dS )N())r:   __name__dictr3   r   r   r   __repr__R   s    zCaselessDict.__repr__c                 C   s    | |kpt |  t | kS r   )r?   r   r!   otherr   r   r   __eq__U   s    zCaselessDict.__eq__c                 C   s
   | |k S r   r   rA   r   r   r   __ne__X   s    zCaselessDict.__ne__c                 C   s   t |  | jS )zSorts keys according to the canonical_order for the derived class.
        Keys not specified in canonical_order will appear at the end.
        )r   r   r   r3   r   r   r   sorted_keys_   s    zCaselessDict.sorted_keysc                 C   s   t | | jS )zSorts items according to the canonical_order for the derived class.
        Items not specified in canonical_order will appear at the end.
        )r   r   r3   r   r   r   sorted_itemse   s    zCaselessDict.sorted_items)N)N)N)r>   
__module____qualname____doc__r   r'   r)   r    r,   r-   r0   r1   r2   r4   r9   r;   r@   rC   rD   r   rE   rF   __classcell__r   r   r%   r   r      s&   		r   )N)N)Zicalendar.parser_toolsr   collectionsr   r   r   r   __all__r   r   r   r   <module>   s
   


W