U
    ºñdZ*  ã                   @   sf   d dl mZmZ d dlmZ d dlmZmZ dd„ Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zedkrbeƒ  dS )é    )ÚdivisionÚprint_function)Ú
getargspec)ÚPYTHON3Úbytesc                 C   sz   dd„ |   ¡  ¡ D ƒ}| ¡  |  ¡ }|s>|s>t| j| ƒ ¡ S |rP|rP| d¡ d| jjd 	|¡d 	dd„ |D ƒ¡ f S )a÷  
    Return a helpful description of the object using
    self._repr_words() and self._repr_attrs() to add
    to the description.  This function may be used by
    adding code to your class like this:

    >>> class Foo(object):
    ...     __repr__ = split_repr
    ...     def _repr_words(self):
    ...         return ["words", "here"]
    ...     def _repr_attrs(self):
    ...         return {'attrs': "appear too"}
    >>> Foo()
    <Foo words here attrs='appear too'>
    >>> class Bar(Foo):
    ...     def _repr_words(self):
    ...         return Foo._repr_words(self) + ["too"]
    ...     def _repr_attrs(self):
    ...         return dict(Foo._repr_attrs(self), barttr=42)
    >>> Bar()
    <Bar words here too attrs='appear too' barttr=42>
    c                 S   s    g | ]\}}t |ƒt|ƒf‘qS © )ÚstrÚnormalize_repr©Ú.0ÚkÚvr   r   ú2/usr/lib/python3/dist-packages/urwid/split_repr.pyÚ
<listcomp>2   s   ÿzsplit_repr.<locals>.<listcomp>Ú z<%s %s>ú c                 S   s   g | ]}d | ‘qS )z%s=%sr   ©r   Zitmr   r   r   r   =   s     )
Z_repr_attrsÚitemsÚsortZ_repr_wordsÚsuperÚ	__class__Ú__repr__ÚappendÚ__name__Újoin)ÚselfZalistZwordsr   r   r   Ú
split_repr   s    
ÿ 
ÿÿr   c                 C   sH   t | tƒr@dd„ |  ¡ D ƒ}| ¡  dd dd„ |D ƒ¡ d S t| ƒS )z»
    Return dictionary repr sorted by keys, leave others unchanged

    >>> normalize_repr({1:2,3:4,5:6,7:8})
    '{1: 2, 3: 4, 5: 6, 7: 8}'
    >>> normalize_repr('foo')
    "'foo'"
    c                 S   s    g | ]\}}t |ƒt |ƒf‘qS r   )Úreprr
   r   r   r   r   I   s     z"normalize_repr.<locals>.<listcomp>ú{z, c                 S   s   g | ]}d | ‘qS )z%s: %sr   r   r   r   r   r   K   s    ú})Ú
isinstanceÚdictr   r   r   r   )r   r   r   r   r   r	   ?   s    	
ÿÿr	   c                 C   s8   t | ƒ}ts4t| tƒrd| S | d¡r4|dd… S |S )z˜
    Return strings and byte strings as they appear in Python 3

    >>> python3_repr(u"text")
    "'text'"
    >>> python3_repr(bytes())
    "b''"
    ÚbÚué   N)r   r   r    r   Ú
startswith)r   Úrr   r   r   Úpython3_reprP   s    	

r'   c                 C   s~   t |ƒ\}}}}|r|d= |r$|d= ttt|t|ƒt|ƒ d… |ƒƒƒ}t|  ¡ ƒD ]"}||krV|| | | krV| |= qV| S )a«  
    Remove keys in d that are set to the default values from
    fn.  This method is used to unclutter the _repr_attrs()
    return value.

    d will be modified by this function.

    Returns d.

    >>> class Foo(object):
    ...     def __init__(self, a=1, b=2):
    ...         self.values = a, b
    ...     __repr__ = split_repr
    ...     def _repr_words(self):
    ...         return ["object"]
    ...     def _repr_attrs(self):
    ...         d = dict(a=self.values[0], b=self.values[1])
    ...         return remove_defaults(d, Foo.__init__)
    >>> Foo(42, 100)
    <Foo object a=42 b=100>
    >>> Foo(10, 2)
    <Foo object a=10>
    >>> Foo()
    <Foo object>
    éÿÿÿÿN)r   r!   ÚlistÚzipÚlenÚkeys)ÚdÚfnÚargsZvarargsZvarkwÚdefaultsZddictr   r   r   r   Úremove_defaultsc   s    &r1   c                  C   s   dd l } |  ¡  d S )Nr   )ÚdoctestZtestmod)r2   r   r   r   Ú_test’   s    r3   Ú__main__N)Z
__future__r   r   Úinspectr   Zurwid.compatr   r   r   r	   r'   r1   r3   r   r   r   r   r   Ú<module>   s   $/