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   [/var/www/html/optinet_system/venv/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