σ
ίΘ[c           @` sM   d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d   Z d S(   uΦ   
Functions to do XML schema and DTD validation.  At the moment, this
makes a subprocess call to xmllint.  This could use a Python-based
library at some point in the future, if something appropriate could be
found.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNc   	      C` s
  t  j j |  \ } } | d k r1 d | } n% | d k rJ d | } n t d   t j d j | |   d t d t j d	 t j } | j	   \ } } | j
 d
 k rΉ t d   nA | j
 d k  rϊ d d l m } t d j | | j
     n  | j
 | | f S(   uy  
    Validates an XML file against a schema or DTD.

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

    schema_file : str
        The path to the XML schema or DTD

    Returns
    -------
    returncode, stdout, stderr : int, str, str
        Returns the returncode from xmllint and the stdout and stderr
        as strings
    u   .xsdu	   --schema u   .dtdu   --dtdvalid u2   schema_file must be a path to an XML Schema or DTDu   xmllint --noout --nonet {} {}t   shellt   stdoutt   stderri   u-   xmllint not found, so can not validate schemai    i   (   t   signal_number_to_nameu&   xmllint was terminated by signal '{0}'(   t   ost   patht   splitextt	   TypeErrort
   subprocesst   Popent   formatt   Truet   PIPEt   communicatet
   returncodet   OSErrort   miscR   (	   t   filenamet   schema_filet   baset   extt   schema_partt   pR   R   R   (    (    s9   lib/python2.7/site-packages/astropy/utils/xml/validate.pyt   validate_schema   s&    (	   t   __doc__t
   __future__R    R   R   R   R   R   R   (    (    (    s9   lib/python2.7/site-packages/astropy/utils/xml/validate.pyt   <module>   s   "