σ
ίΘ[c           @` s   d  Z  d d l m Z m Z m Z m Z d d l m Z m Z d d l	 Z	 d   Z
 d   Z d Z d	   Z d
   Z d   Z d S(   u^   
A collection of functions for checking various XML-related strings for
standards compliance.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   ranget   urllibNc         C` s   t  j d |   d k	 S(   u3   
    Returns `True` if *ID* is a valid XML ID.
    u   ^[A-Za-z_][A-Za-z0-9_\.\-]*$N(   t   ret   matcht   None(   t   ID(    (    s6   lib/python2.7/site-packages/astropy/utils/xml/check.pyt   check_id   s    c         C` s   t  j d |   r |  St |   r |  } t |  sK t  j d | d  rX d | } n  t  j d d | d  t  j d d | d  } | Sd S(	   uΎ   
    Given an arbitrary string, create one that can be used as an xml
    id.  This is rather simplistic at the moment, since it just
    replaces non-valid characters with underscores.
    u   ^[A-Za-z_][A-Za-z0-9_\.\-]*$u   ^[^A-Za-z_]$i    u   _u
   [^A-Za-z_]u   [^A-Za-z0-9_\.\-]i   u    (   R   R   t   lent   sub(   R	   t	   corrected(    (    s6   lib/python2.7/site-packages/astropy/utils/xml/check.pyt   fix_id   s    #u$   (?![\r\l\t ])[^\r\l\t]*(?![\r\l\t ])c         C` s"   |  d k p! t  j d |   d k	 S(   u^   
    Returns `True` if *token* is a valid XML token, as defined by XML
    Schema Part 2.
    u    u0   [^\r\n\t ]?([^\r\n\t ]| [^\r\n\t ])*[^\r\n\t ]?$N(   R   R   R   (   t   token(    (    s6   lib/python2.7/site-packages/astropy/utils/xml/check.pyt   check_token*   s    	c         C` sS   d j  d   t d d  D  } d j |  } t j d j | |  |   d k	 S(   u}   
    Returns `True` if *content_type* is a valid MIME content type
    (syntactically at least), as defined by RFC 2045.
    u    c         s` s   |  ] } t  |  Vq d  S(   N(   t   chr(   t   .0t   x(    (    s6   lib/python2.7/site-packages/astropy/utils/xml/check.pys	   <genexpr>:   s    i    i    u   [^()<>@,;:\"/[\]?= {}]+u   (?P<type>{})/(?P<subtype>{})$N(   t   joinR   t   formatR   R   R   (   t   content_typet   ctrlst   token_regex(    (    s6   lib/python2.7/site-packages/astropy/utils/xml/check.pyt   check_mime_content_type5   s
    "c         C` sM   t  j d d |   d k r  t Sy t j j |   Wn t k
 rH t SXt S(   uH   
    Returns `True` if *uri* is a valid URI as defined in RFC 2396.
    u/   (([a-zA-Z][0-9a-zA-Z+\-\.]*:)?/{0,2}[0-9a-zA-Z;u=   /?:@&=+$\.\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\.\-_!~*'()%]+)?N(	   R   R   R   t   FalseR   t   parset   urlparset	   Exceptiont   True(   t   uri(    (    s6   lib/python2.7/site-packages/astropy/utils/xml/check.pyt   check_anyuriA   s    (   t   __doc__t
   __future__R    R   R   R   t   extern.six.movesR   R   R   R
   R   t   _token_regexR   R   R    (    (    (    s6   lib/python2.7/site-packages/astropy/utils/xml/check.pyt   <module>   s   "				