o
    ).hö  ã                   @   s8   d Z ddlZddlmZ dd„ Zddd„Zdd	d
„ZdS )z&
Helpers for dealing with HTML input.
é    N)ÚMultiValueDictc                 C   s
   t | dƒS )NÚgetlist)Úhasattr)Ú
dictionary© r   úX/var/www/supernova/superenvnew/lib/python3.10/site-packages/rest_framework/utils/html.pyÚis_html_input	   s   
r   Ú c           	         sª   i ‰ t  dt  |¡ ¡}|  ¡ D ]5\}}| |¡}|sq| ¡ \}}t|ƒ}|s-|ˆ |< qtˆ  |¡t	ƒr<|ˆ | |< qt
||giƒˆ |< qˆ rS‡ fdd„tˆ ƒD ƒS |S )ad  
    Used to support list values in HTML forms.
    Supports lists of primitives and/or dictionaries.

    * List of primitives.

    {
        '[0]': 'abc',
        '[1]': 'def',
        '[2]': 'hij'
    }
        -->
    [
        'abc',
        'def',
        'hij'
    ]

    * List of dictionaries.

    {
        '[0]foo': 'abc',
        '[0]bar': 'def',
        '[1]foo': 'hij',
        '[1]bar': 'klm',
    }
        -->
    [
        {'foo': 'abc', 'bar': 'def'},
        {'foo': 'hij', 'bar': 'klm'}
    ]

    :returns a list of objects, or the value specified in ``default`` if the list is empty
    z^%s\[([0-9]+)\](.*)$c                    s   g | ]}ˆ | ‘qS r   r   )Ú.0Úitem©Úretr   r   Ú
<listcomp>B   s    z#parse_html_list.<locals>.<listcomp>)ÚreÚcompileÚescapeÚitemsÚmatchÚgroupsÚintÚ
isinstanceÚgetÚdictr   Úsorted)	r   ÚprefixÚdefaultÚregexÚfieldÚvaluer   ÚindexÚkeyr   r   r   Úparse_html_list   s   #

r!   c                 C   sZ   t ƒ }t dt |¡ ¡}| D ]}| |¡}|sq| ¡ d }|  |¡}| ||¡ q|S )a#  
    Used to support dictionary values in HTML forms.

    {
        'profile.username': 'example',
        'profile.email': 'example@example.com',
    }
        -->
    {
        'profile': {
            'username': 'example',
            'email': 'example@example.com'
        }
    }
    z
^%s\.(.+)$r   )r   r   r   r   r   r   r   Úsetlist)r   r   r   r   r   r   r    r   r   r   r   Úparse_html_dictE   s   

r#   )r	   N)r	   )Ú__doc__r   Údjango.utils.datastructuresr   r   r!   r#   r   r   r   r   Ú<module>   s    
6