U
    ÀÎ_Ú  ã                   @   sZ   d dl Z d dlZz
ejZW n ek
r2   eZY nX d dlmZ G dd„ dejƒZeZ	dS )é    N)Ú	constantsc                   @   sd   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )Ú
Attributesc                 O   s   t ƒ | _| j||Ž dS )aÆ  
        An Attributes object acts much like a dictionary.  However, values are
        always stored internally as lists, even if a single value is provided.

        Whether or not you get a list back depends on the
        `constants.always_return_list` setting, which can be set on-the-fly.
        If True, then one-item lists are returned.  This is best shown with an
        example:

        Set up an Attributes object:

            >>> attr = Attributes()

        Set the "Name" attribute with a string:

            >>> attr['Name'] = 'gene1'

        This is stored internally as a list, and by default, we'll get a list
        back:

            >>> assert attr['Name'] == ['gene1']

        The same thing happens if we set it with a list in the first place:

            >>> attr['Name'] = ['gene1']
            >>> assert attr['Name'] == ['gene1']

        Now, change the setting so that upon access, single-value lists are
        returned as the first item.

            >>> constants.always_return_list = False
            >>> assert attr['Name'] == 'gene1'

        Change it back again:

            >>> constants.always_return_list = True
            >>> assert attr['Name'] == ['gene1']

        N)ÚdictÚ_dÚupdate)ÚselfÚargsÚkwargs© r
   ú2lib/python3.8/site-packages/gffutils/attributes.pyÚ__init__   s    (zAttributes.__init__c                 C   s"   t |ttfƒs|g}|| j|< d S ©N)Ú
isinstanceÚlistÚtupler   ©r   ÚkÚvr
   r
   r   Ú__setitem__9   s    zAttributes.__setitem__c                 C   s6   | j | }tjr|S t|tƒr2t|ƒdkr2|d }|S )Né   r   )r   r   Zalways_return_listr   r   Úlenr   r
   r
   r   Ú__getitem__>   s    
zAttributes.__getitem__c                 C   s   | j |= d S r   )r   )r   Úkeyr
   r
   r   Ú__delitem__F   s    zAttributes.__delitem__c                 C   s   t |  ¡ ƒS r   )ÚiterÚkeys©r   r
   r
   r   Ú__iter__I   s    zAttributes.__iter__c                 C   s
   t | jƒS r   )r   r   r   r
   r
   r   Ú__len__L   s    zAttributes.__len__c                 C   s
   | j  ¡ S r   )r   r   r   r
   r
   r   r   O   s    zAttributes.keysc                    s   ‡ fdd„ˆ   ¡ D ƒS )Nc                    s   g | ]}ˆ   |¡‘qS r
   )r   )Ú.0r   r   r
   r   Ú
<listcomp>S   s     z%Attributes.values.<locals>.<listcomp>)r   r   r
   r   r   ÚvaluesR   s    zAttributes.valuesc                 C   s*   g }|   ¡ D ]}| ||  |¡f¡ q|S r   )r   Úappendr   )r   Úrr   r
   r
   r   ÚitemsU   s    zAttributes.itemsc                 C   s*   g }|   ¡ D ]}| d| ¡ qd |¡S )Nz%s: %sÚ
)r$   r"   Újoin)r   ÚsÚir
   r
   r   Ú__str__[   s    zAttributes.__str__c                 O   s&   t  t||Ž¡D ]\}}|| |< qd S r   )ÚsixZ	iteritemsr   )r   r   r	   r   r   r
   r
   r   r   a   s    zAttributes.updateN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r!   r$   r)   r   r
   r
   r
   r   r      s   +r   )
r*   ÚcollectionsÚabcZcollectionsAbcÚAttributeErrorZgffutilsr   ÚMutableMappingr   Z
dict_classr
   r
   r
   r   Ú<module>   s   

\