
    IR-e                         d Z ddlZddlZddlZddlZddlZg dZdZ ej                    Z	d Z
ej        d             Z eej                  fdZ G d d	          Zd
 ZdS )z,
Wrappers for PLY to provide thread safety.
    N)lexThreadSafeParseryaccad  # -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst

# This file was automatically generated from ply. To re-generate this file,
# remove it from this folder, then build astropy and run the tests in-place:
#
#   python setup.py build_ext --inplace
#   pytest {package}
#
# You can then commit the changes to this file.

c                 T   t          |           5 }|                                }d d d            n# 1 swxY w Y   t          | d          5 }|                    t                              |                     |                    |           d d d            d S # 1 swxY w Y   d S )Nw)package)openreadwrite_TAB_HEADERformat)filenamer   fcontentss       5lib/python3.11/site-packages/astropy/utils/parsing.py_add_tab_headerr      s   	h 16688               
h		 	""7"33444	                 s   155ABB!$B!c              #   |   K   | j         t          j                  fd            }|| _         dV  | _         dS )a<  Temporarily replace the module's get_caller_module_dict.

    This is a function inside ``ply.lex`` and ``ply.yacc`` (each has a copy)
    that is used to retrieve the caller's local symbols. Here, we patch the
    function to instead retrieve the grandparent's local symbols to account
    for a wrapper layer.
    c                       | dz             S )N    )levelsoriginals    r   wrapperz._patch_get_caller_module_dict.<locals>.wrapper2   s     x
###    N)get_caller_module_dict	functoolswraps)moduler   r   s     @r   _patch_get_caller_module_dictr   '   s`       ,H_X$ $ $ $ $ %,F!	EEE$,F!!!r   c           	      &   ddl m} |                    d          d         }t          j                            t          j                            |          | dz             }t          5  t          j                            |          }t          |          5  |                    d| t          j                            |          |          }ddd           n# 1 swxY w Y   |st          ||           |cddd           S # 1 swxY w Y   dS )	aq  Create a lexer from local variables.

    It automatically compiles the lexer in optimized mode, writing to
    ``lextab`` in the same directory as the calling file.

    This function is thread-safe. The returned lexer is *not* thread-safe, but
    if it is used exclusively with a single parser returned by :func:`yacc`
    then it will be safe.

    It is only intended to work with lexers defined within the calling
    function, rather than at class or module scope.

    Parameters
    ----------
    lextab : str
        Name for the file to write with the generated tables, if it does not
        already exist (without ``.py`` suffix).
    package : str
        Name of a test package which should be run with pytest to regenerate
        the output file. This is inserted into a comment in the generated
        file.
    reflags : int
        Passed to ``ply.lex``.
    r   )r   r   __file__.pyT)optimizelextab	outputdirreflagsN)astropy.extern.plyr   r   ospathjoindirname_LOCKexistsr   r   )r$   r   r&   r   caller_filelextab_filenamelextab_existslexers           r   r   r   <   s   2 '&&&&&,,Q//
;Kgll27??;#?#?%PPO	  77*3// 	 	GG'//+66	   E	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	6OW555                 s6   )/D7CDC	D"C	#DD
D
c                       e Zd ZdZd Zd ZdS )r   znWrap a parser produced by ``ply.yacc.yacc``.

    It provides a :meth:`parse` method that is thread-safe.
    c                 D    || _         t          j                    | _        d S )N)parser	threadingRLock_lock)selfr4   s     r   __init__zThreadSafeParser.__init__m   s    _&&


r   c                 h    | j         5   | j        j        |i |cddd           S # 1 swxY w Y   dS )z<Run the wrapped parser, with a lock to ensure serialization.N)r7   r4   parse)r8   argskwargss      r   r;   zThreadSafeParser.parseq   s    Z 	6 	6$4;$d5f55	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   '++N)__name__
__module____qualname____doc__r9   r;   r   r   r   r   r   g   s<         
' ' '6 6 6 6 6r   r   c           	      >   ddl m} |                    d          d         }t          j                            t          j                            |          | dz             }t          5  t          j                            |          }t          |          5  |                    | t          j                            |          ddd          }d	d	d	           n# 1 swxY w Y   |st          ||           d	d	d	           n# 1 swxY w Y   t          |          S )
a&  Create a parser from local variables.

    It automatically compiles the parser in optimized mode, writing to
    ``tabmodule`` in the same directory as the calling file.

    This function is thread-safe, and the returned parser is also thread-safe,
    provided that it does not share a lexer with any other parser.

    It is only intended to work with parsers defined within the calling
    function, rather than at class or module scope.

    Parameters
    ----------
    tabmodule : str
        Name for the file to write with the generated tables, if it does not
        already exist (without ``.py`` suffix).
    package : str
        Name of a test package which should be run with pytest to regenerate
        the output file. This is inserted into a comment in the generated
        file.
    r   )r   r   r!   r"   FT)	tabmoduler%   debugr#   write_tablesN)r'   r   r   r(   r)   r*   r+   r,   r-   r   r   r   )rC   r   r   r.   tab_filename
tab_existsr4   s          r   r   r   w   s   , ('''''--a00<K7<< < <i%>OPPL	 3 3W^^L11
*400 	 	YY#'//+66!   F	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	3L'2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 F###s6   )/D8CDC 	 D#C 	$DD	D	)rA   
contextlibr   r(   rer5   __all__r   r6   r,   r   contextmanagerr   intVERBOSEr   r   r   r   r   r   <module>rN      s             				 				    
-
-
- 		   - - -( "%RZ ( ( ( (V6 6 6 6 6 6 6 6 '$ '$ '$ '$ '$r   