B
    q\M                 @   s    d Z ddlZddlZdd ZdS )z
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.
    Nc       	      C   s   t j|\}}|dkr"d| }n|dkr4d| }ntdtjd|| dtjtjd}| \}}|j	d	krzt
d
n,|j	dk rddlm} t
d||j	 |j	||fS )ay  
    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
    z.xsdz	--schema z.dtdz--dtdvalid z2schema_file must be a path to an XML Schema or DTDzxmllint --noout --nonet {} {}T)shellstdoutstderr   z-xmllint not found, so can not validate schemar   )signal_number_to_namez&xmllint was terminated by signal '{0}')ospathsplitext	TypeError
subprocessPopenformatPIPEZcommunicate
returncodeOSErrorZastropy.utils.miscr   )	filenameZschema_filebaseZextZschema_partpr   r   r    r   9lib/python3.7/site-packages/astropy/utils/xml/validate.pyvalidate_schema   s&    




r   )__doc__r   r   r   r   r   r   r   <module>   s   