B
    q\                 @   s   d 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Zddd	ZdZddd
ZdddZdddZdddZdS )z
Various XML-related utilities
    )log)data)check)validate   )warn_or_raisevo_warnW02W03W04W05check_idfix_idcheck_tokencheck_mime_content_typecheck_anyurivalidate_schemaIDNc             C   s.   | dk	r*t | s*ttt|| f|| dS dS )z
    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).
    NFT)	xml_checkr   r   r	   )r   nameconfigpos r   9lib/python3.7/site-packages/astropy/io/votable/xmlutil.pyr      s    c             C   s4   | dkrdS t | }|| kr0tt| |f|| |S )z
    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   r   r
   )r   r   r   Z	correctedr   r   r   r   %   s    
z$(?![\r\l\t ])[^\r\l\t]*(?![\r\l\t ])c             C   s   | dk	rt | sdS dS )zj
    Raises a `ValueError` if *token* is not a valid XML token.

    As defined by XML Schema Part 2.
    NFT)r   r   )tokenZ	attr_namer   r   r   r   r   r   7   s    c             C   s*   | dk	r&t | s&ttt| || dS dS )z
    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).
    NFT)r   r   r   r   )Zcontent_typer   r   r   r   r   r   B   s
    
c             C   s*   | dk	r&t | s&ttt| || dS dS )z
    Raises a `~astropy.io.votable.exceptions.VOTableSpecError` if
    *uri* is not a valid URI.

    As defined in RFC 2396.
    NFT)r   r   r   r   )Zurir   r   r   r   r   r   P   s    1.1c             C   sN   |dkrt d| | d}|dkr8td|}n
td}t| |S )ax  
    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
    )z1.0z1.1z1.2z1.3z%{0} has version {1}, using schema 1.1z1.1)z1.1z1.2z1.3zdata/VOTable.v{0}.xsdzdata/VOTable.dtd)r   infoformatr   Zget_pkg_data_filenamer   r   )filenameversionZschema_pathr   r   r   r   ]   s    
)r   NN)NN)NN)NN)NN)r   )__doc__Zastropy.loggerr   Zastropy.utilsr   Zastropy.utils.xmlr   r   r   
exceptionsr   r   r	   r
   r   r   __all__r   r   Z_token_regexr   r   r   r   r   r   r   r   <module>   s    




