ó
O'^c           @   sG   d  Z  d d l Z d d l m Z d   Z d d  Z d d  Z d S(   s&   
Helpers for dealing with HTML input.
i˙˙˙˙N(   t   MultiValueDictc         C   s   t  |  d  S(   Nt   getlist(   t   hasattr(   t
   dictionary(    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/html.pyt   is_html_input	   s    t    c   
      C   ső   i  } t  j d t  j |   } xŠ |  j   D] \ } } | j |  } | sV q/ n  | j   \ } } t |  } | s | | | <q/ t | j |  t	  r° | | | | <q/ t
 i | g | 6 | | <q/ Wg  t | j    D] }	 | |	 ^ qá S(   s  
    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'}
    ]
    s   ^%s\[([0-9]+)\](.*)$(   t   ret   compilet   escapet   itemst   matcht   groupst   intt
   isinstancet   gett   dictR    t   sortedt   keys(
   R   t   prefixt   rett   regext   fieldt   valueR
   t   indext   keyt   item(    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/html.pyt   parse_html_list   s    !c         C   s   t    } t j d t j |   } xX |  D]P } | j |  } | sM q, n  | j   d } |  j |  } | j | |  q, W| S(   s#  
    Used to support dictionary values in HTML forms.

    {
        'profile.username': 'example',
        'profile.email': 'example@example.com',
    }
        -->
    {
        'profile': {
            'username': 'example',
            'email': 'example@example.com'
        }
    }
    s
   ^%s\.(.+)$i    (   R    R   R   R   R
   R   R   t   setlist(   R   R   R   R   R   R
   R   R   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/html.pyt   parse_html_dictA   s    	(   t   __doc__R   t   django.utils.datastructuresR    R   R   R   (    (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/html.pyt   <module>   s
   	2