a
    =_                     @   s   d Z ddlZddlZddlZddlmZ dZedZedZ	edZ
ed	Zd
Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zedkre  dS )zFunctionality related with node paths in a PyTables file.

Variables
=========

`__docformat`__
    The format of documentation strings in this module.

    N   )NaturalNameWarningZreStructuredTextz^[a-zA-Z_][a-zA-Z0-9_]*$z	^_[cfgv]_z^_[pi]_z/_[pi]_zmyou will not be able to use natural naming to access this object; using ``getattr()`` will still work, thoughc                 C   s   t | tstd| f | dkr(tdt| sRtjd| tjt	f t
dd dS t| rxtjd| t	f t
dd dS t| rtd	| tjf | d
krtddS )ai  Check the validity of the `name` of an attribute in AttributeSet.

    If the name is not valid, a ``ValueError`` is raised.  If it is
    valid but it can not be used with natural naming, a
    `NaturalNameWarning` is issued.

    >>> check_attribute_name('a')
    >>> check_attribute_name('a_b')
    >>> check_attribute_name('a:b')
    >>> check_attribute_name('/a/b')
    >>> check_attribute_name('/')
    >>> check_attribute_name('.')
    >>> check_attribute_name('__members__')
    Traceback (most recent call last):
     ...
    ValueError: ``__members__`` is not allowed as an object name
    >>> check_attribute_name(1)
    Traceback (most recent call last):
     ...
    TypeError: object name is not a string: 1
    >>> check_attribute_name('')
    Traceback (most recent call last):
     ...
    ValueError: the empty string is not allowed as an object name
    zobject name is not a string: %r z1the empty string is not allowed as an object namezZobject name is not a valid Python identifier: %r; it does not match the pattern ``%s``; %s   )
stacklevelNz'object name is a Python keyword: %r; %szLobject name starts with a reserved prefix: %r; it matches the pattern ``%s``__members__z0``__members__`` is not allowed as an object name)
isinstancestr	TypeError
ValueError_python_id_rematchwarningswarnpattern	_warnInfor   keyword	iskeyword_reserved_id_rename r   *lib/python3.9/site-packages/tables/path.pycheck_attribute_nameI   s0    




r   c                 C   s2   t |  | dkrtdnd| v r.td|  dS )a'  Check the validity of the `name` of a Node object, which more limited
    than attribute names.

    If the name is not valid, a ``ValueError`` is raised.  If it is
    valid but it can not be used with natural naming, a
    `NaturalNameWarning` is issued.

    >>> check_name_validity('a')
    >>> check_name_validity('a_b')
    >>> check_name_validity('a:b')
    >>> check_name_validity('/a/b')
    Traceback (most recent call last):
     ...
    ValueError: the ``/`` character is not allowed in object names: '/a/b'
    >>> check_name_validity('.')
    Traceback (most recent call last):
     ...
    ValueError: ``.`` is not allowed as an object name
    >>> check_name_validity('')
    Traceback (most recent call last):
     ...
    ValueError: the empty string is not allowed as an object name

    .z&``.`` is not allowed as an object name/z6the ``/`` character is not allowed in object names: %rN)r   r   r   r   r   r   check_name_validity   s    
r   c                 C   sx   | dr|dd }| dkr2| dr2d| }n,| dksD| drRd| |f }nd| |f }|drt|dd }|S )	ab  Join a *canonical* `parentpath` with a *non-empty* `name`.

    .. versionchanged:: 3.0
       The *parentPath* parameter has been renamed into *parentpath*.

    >>> join_path('/', 'foo')
    '/foo'
    >>> join_path('/foo', 'bar')
    '/foo/bar'
    >>> join_path('/foo', '/foo2/bar')
    '/foo/foo2/bar'
    >>> join_path('/foo', '/')
    '/foo'

    z./r   Nr   z%sz%s%sz%s/%s)
startswithendswith)Z
parentpathr   Zpstrr   r   r   	join_path   s    


r    c                 C   s:   |  d}| d| }| |d d }|dkr2d}||fS )zSplit a *canonical* `path` into a parent path and a node name.

    The result is returned as a tuple.  The parent path does not
    include a trailing slash.

    >>> split_path('/')
    ('/', '')
    >>> split_path('/foo/bar')
    ('/foo', 'bar')

    r   Nr   r   )rfind)pathZ	lastslashZppathr   r   r   r   
split_path   s    
r#   c                 C   s   t | du S )z3Does this `name` make the named node a visible one?N)_hidden_name_rer   r   r   r   r   isvisiblename   s    r%   c                 C   s   t | du S )z3Does this `path` make the named node a visible one?N)_hidden_path_research)r"   r   r   r   isvisiblepath   s    r(   c                  C   s   ddl } |   dS )zRun ``doctest`` on this module.r   N)doctestZtestmod)r)   r   r   r   _test   s    r*   __main__)__doc__rer   r   
exceptionsr   Z__docformat__compiler   r   r$   r&   r   r   r   r    r#   r%   r(   r*   __name__r   r   r   r   <module>   s(   

	

	9(	