U
    e»{jÆ  ã                   @   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é   )ÚW02ÚW03ÚW04ÚW05Úvo_warnÚwarn_or_raiseÚ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   úY/var/www/html/bwave/python/venv/lib/python3.8/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   )ÚtokenÚ	attr_namer   r   r   r   r   r   :   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	   )Úcontent_typer   r   r   r   r   r   E   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
   )Úurir   r   r   r   r   r   R   s    ú1.1c                 C   sT   |dkr"t  | › d|› d�¡ d}|dk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   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&    ú





