
    Nwg                     2    d Z ddlZddlmZ d ZddZddZy)	z&
Helpers for dealing with HTML input.
    N)MultiValueDictc                     t        | d      S )Ngetlist)hasattr)
dictionarys    P/var/www/horilla/myenv/lib/python3.12/site-packages/rest_framework/utils/html.pyis_html_inputr	   	   s     :y))    c                    i }t        j                  dt        j                  |      z        }| j                         D ]x  \  }}|j	                  |      }|s|j                         \  }}	t        |      }|	s|||<   @t        |j                  |      t              r	|||   |	<   ht        |	|gi      ||<   z |rt        |      D 
cg c]  }
||
   	 c}
S |S c c}
w )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]+)\](.*)$)recompileescapeitemsmatchgroupsint
isinstancegetdictr   sorted)r   prefixdefaultretregexfieldvaluer   indexkeyitems              r   parse_html_listr       s    F CJJ.61BBCE"((* 8uE"\\^
sE
CJ-#CJsO'ug7CJ8 36&+.$CI.B7B.s   Cc                    t               }t        j                  dt        j                  |      z        }| D ]L  }|j	                  |      }|s|j                         d   }| j                  |      }|j                  ||       N |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   s           r   parse_html_dictr#   E   s      
CJJ}ryy'889E  E"llnQ""5)C  Jr
   ) N)r$   )__doc__r   django.utils.datastructuresr   r	   r    r#    r
   r   <module>r(      s#    
 6*3Clr
   