a
    ߙfb                     @   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 g d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u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.9/site-packages/astropy/io/votable/xmlutil.pyr      s    r   c                 C   s4   | du 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    
r   z$(?![\r\l\t ])[^\r\l\t]*(?![\r\l\t ])c                 C   s   | du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    r   c                 C   s*   | du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    r   c                 C   s*   | du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    r   1.1c                 C   sT   |dvr"t |  d| d d}|dv r>td| 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.0r   1.21.3z has version z, using schema 1.1r   )r   r   r   zdata/VOTable.vz.xsdzdata/VOTable.dtd)r   infor   Zget_pkg_data_filenamer   r   )filenameversionZschema_pathr   r   r   r   ]   s    
r   )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    




