σ
ίΘ[c           @` s  d  Z  d d l m Z m Z m Z m Z d d l m Z d d l m	 Z	 d d l
 m Z d d l
 m Z d d	 l m Z m Z m Z m Z m Z m Z d
 d d d d d g Z d d d d  Z d d d  Z d Z d d d  Z d d d  Z d d d  Z d d  Z d S(   u   
Various XML-related utilities
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   log(   t   data(   t   check(   t   validatei   (   t   warn_or_raiset   vo_warnt   W02t   W03t   W04t   W05u   check_idu   fix_idu   check_tokenu   check_mime_content_typeu   check_anyuriu   validate_schemau   IDc         C` s@   |  d k	 r< t j |   r< t t t | |  f | |  t St S(   uΓ   
    Raises a `~astropy.io.votable.exceptions.VOTableSpecError` if *ID*
    is not a valid XML ID_.

    *name* is the name of the attribute being checked (used only for
    error messages).
    N(   t   Nonet	   xml_checkt   check_idR   R
   t   Falset   True(   t   IDt   namet   configt   pos(    (    s9   lib/python2.7/site-packages/astropy/io/votable/xmlutil.pyR      s    c         C` sK   |  d k r d St j |   } | |  k rG t t |  | f | |  n  | 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.
    N(   R   R   t   fix_idR	   R   (   R   R   R   t	   corrected(    (    s9   lib/python2.7/site-packages/astropy/io/votable/xmlutil.pyR   &   s    u$   (?![\r\l\t ])[^\r\l\t]*(?![\r\l\t ])c         C` s$   |  d k	 r  t j |   r  t St S(   uj   
    Raises a `ValueError` if *token* is not a valid XML token.

    As defined by XML Schema Part 2.
    N(   R   R   t   check_tokenR   R   (   t   tokent	   attr_nameR   R   (    (    s9   lib/python2.7/site-packages/astropy/io/votable/xmlutil.pyR   8   s    c         C` s:   |  d k	 r6 t j |   r6 t t t |  | |  t St S(   u³   
    Raises a `~astropy.io.votable.exceptions.VOTableSpecError` if
    *content_type* is not a valid MIME content type.

    As defined by RFC 2045 (syntactically, at least).
    N(   R   R   t   check_mime_content_typeR   R   R   R   (   t   content_typeR   R   (    (    s9   lib/python2.7/site-packages/astropy/io/votable/xmlutil.pyR   C   s
    c         C` s:   |  d k	 r6 t j |   r6 t t t |  | |  t St S(   u   
    Raises a `~astropy.io.votable.exceptions.VOTableSpecError` if
    *uri* is not a valid URI.

    As defined in RFC 2396.
    N(   R   R   t   check_anyuriR   R   R   R   (   t   uriR   R   (    (    s9   lib/python2.7/site-packages/astropy/io/votable/xmlutil.pyR   Q   s    u   1.1c         C` st   | d k r. t  j d j |  |   d } n  | d	 k rU t j d j |   } n t j d  } t j |  |  S(
   ux  
    Validates the given file against the appropriate VOTable schema.

    Parameters
    ----------
    filename : str
        The path to the XML file to validate

    version : str, optional
        The VOTABLE version to check, which must be a string "1.0",
        "1.1", "1.2" or "1.3".  If it is not one of these,
        version "1.1" is assumed.

        For version "1.0", it is checked against a DTD, since that
        version did not have an XML Schema.

    Returns
    -------
    returncode, stdout, stderr : int, str, str
        Returns the returncode from xmllint and the stdout and stderr
        as strings
    u   1.0u   1.1u   1.2u   1.3u%   {0} has version {1}, using schema 1.1u   data/VOTable.v{0}.xsdu   data/VOTable.dtd(   u   1.0u   1.1u   1.2u   1.3(   u   1.1u   1.2u   1.3(   R   t   infot   formatR   t   get_pkg_data_filenameR   t   validate_schema(   t   filenamet   versiont   schema_path(    (    s9   lib/python2.7/site-packages/astropy/io/votable/xmlutil.pyR#   ^   s    		N(   t   __doc__t
   __future__R    R   R   R   t   loggerR   t   utilsR   t	   utils.xmlR   R   R   t
   exceptionsR   R	   R
   R   R   R   t   __all__R   R   R   t   _token_regexR   R   R   R#   (    (    (    s9   lib/python2.7/site-packages/astropy/io/votable/xmlutil.pyt   <module>   s   ".