
    Ѯh-0                    J   d Z ddlmZ ddlZddlmZ ddlmZmZ dZ	dZ
dZd	Zd
Zedz  ZdZeez   Z ej"                  d      Z ej"                  d      Zg dZdj+                  d eD              Z ej"                  e      ZddZddZddZddZeZddZ G d de      Zy)zBUtilities for managing / converting field paths to / from strings.    )annotationsN)abc)Iterablecastz!{!r} is not contained in the dataz2{!r} is not contained in the data for the key {!r}zGThe data at {!r} is not a dictionary, so it cannot contain the key {!r}.\   `z^[_a-zA-Z][_a-zA-Z0-9]*$z ^[_a-zA-Z][_a-zA-Z0-9]*[~*/\[\]]))SIMPLEz[_a-zA-Z][_a-zA-Z0-9]*)QUOTEDz`(?:\\`|[^`])*?`)DOTz\.|c              #  :   K   | ]  } d j                   |   yw)z
(?P<{}>{})N)format).0pairs     v/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/field_path.py	<genexpr>r   (   s     U-,--t4Us   c              #  2  K   d}t         j                  } ||       }|Kt        t        |j                        }|j                  |      }| |j                         } || |      }|K|t        |       k7  rt        dj                  | | |d             yw)zLex a field path into tokens (including dots).

    Args:
        path (str): field path to be lexed.
    Returns:
        List(str): tokens
    r   Nz!Path {} not consumed, residue: {})
TOKENS_REGEXmatchr   str	lastgroupgroupendlen
ValueErrorr   )pathpos	get_tokenr   type_values         r   _tokenize_field_pathr#   ,   s      C""IdOE

S%//*E"iik$$ 
 c$i<CCD$st*UVV s   A'B*-Bc                   | sg S g }d}t        |       D ]X  }|r"|dk7  rt        dj                  |             d}'|dk(  rt        dj                  |             |j                  |       d}Z |r|st        dj                  |             |S )a  Split a field path into valid elements (without dots).

    Args:
        path (str): field path to be lexed.
    Returns:
        List(str): tokens
    Raises:
        ValueError: if the path does not match the elements-interspersed-
                    with-dots pattern.
    Fr   zInvalid path: {}T)r#   r   r   append)r   elementswant_dotelements       r   split_field_pathr)   A   s     	HH'- 
#~ !3!:!:4!@AA #~ !3!:!:4!@AAOOG$H
 8+224899O    c                    g }t        |       D ]\  }|d   dk(  rA|d   dk(  r9|dd }|j                  t        t              }|j                  t        t
              }|j                  |       ^ |S )a;  Parse a **field path** from into a list of nested field names.

    See :func:`field_path` for more on **field paths**.

    Args:
        api_repr (str):
            The unique Firestore api representation which consists of
            either simple or UTF-8 field names. It cannot exceed
            1500 bytes, and cannot be empty. Simple field names match
            ``'^[_a-zA-Z][_a-zA-Z0-9]*$'``. All other field names are
            escaped by surrounding them with backticks.

    Returns:
        List[str, ...]: The list of field names in the field path.
    r   r
      )r)   replace_ESCAPED_BACKTICK	_BACKTICK_ESCAPED_BACKSLASH
_BACKSLASHr%   )api_reprfield_names
field_names      r   parse_field_pathr6   d   s|    $ K&x0 '
a=CJrNc$9#Ab)J#++,=yIJ#++,>
KJ:&' r*   c                Z   g }| D ]  }t         j                  |      }|r&|j                  d      |k(  r|j                  |       @|j	                  t
        t              j	                  t        t              }|j                  t        |z   t        z           t        j                  |      S )aC  Create a **field path** from a list of nested field names.

    A **field path** is a ``.``-delimited concatenation of the field
    names. It is used to represent a nested field. For example,
    in the data

    .. code-block:: python

       data = {
          'aa': {
              'bb': {
                  'cc': 10,
              },
          },
       }

    the field path ``'aa.bb.cc'`` represents that data stored in
    ``data['aa']['bb']['cc']``.

    Args:
        field_names: The list of field names.

    Returns:
        str: The ``.``-delimited field path.
    r   )_SIMPLE_FIELD_NAMEr   r   r%   r.   r2   r1   r0   r/   _FIELD_PATH_DELIMITERjoin)r4   resultr5   r   replaceds        r   render_field_pathr=      s    4 F! <
"((4U[[^z1MM*%!))*6HIQQ,H MM)h.:;< !%%f--r*   c                   t        |       }|}t        |      D ]  \  }}t        |t        j                        r^||v r||   }*|dk(  r t
        j                  |      }t        |      t        |d|       }t        j                  ||      }t        |      t        |d|       }t        j                  ||      }t        |       |S )a  Get a (potentially nested) value from a dictionary.

    If the data is nested, for example:

    .. code-block:: python

       >>> data
       {
           'top1': {
               'middle2': {
                   'bottom3': 20,
                   'bottom4': 22,
               },
               'middle5': True,
           },
           'top6': b'  foo',
       }

    a **field path** can be used to access the nested data. For
    example:

    .. code-block:: python

       >>> get_nested_value('top1', data)
       {
           'middle2': {
               'bottom3': 20,
               'bottom4': 22,
           },
           'middle5': True,
       }
       >>> get_nested_value('top1.middle2', data)
       {
           'bottom3': 20,
           'bottom4': 22,
       }
       >>> get_nested_value('top1.middle2.bottom3', data)
       20

    See :meth:`~google.cloud.firestore_v1.client.Client.field_path` for
    more information on **field paths**.

    Args:
        field_path (str): A field path (``.``-delimited list of
            field names).
        data (Dict[str, Any]): The (possibly nested) data.

    Returns:
        Any: (A copy of) the value stored for the ``field_path``.

    Raises:
        KeyError: If the ``field_path`` does not match nested data.
    r   N)r6   	enumerate
isinstancer   Mapping_FIELD_PATH_MISSING_TOPr   KeyErrorr=   _FIELD_PATH_MISSING_KEY_FIELD_PATH_WRONG_TYPE)
field_pathdatar4   nested_dataindexr5   msgpartials           r   get_nested_valuerL      s    l #:.KK&{3  zk3;;/[()*5A:188DC"3-'/FU0CDG188WMC"3-''FU(;<G(//DC3- " r*   c                  z    e Zd ZdZd Zedd       Zedd       Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zed        Zy)	FieldPatha  Field Path object for client use.

    A field path is a sequence of element keys, separated by periods.
    Each element key can be either a simple identifier, or a full unicode
    string.

    In the string representation of a field path, non-identifier elements
    must be quoted using backticks, with internal backticks and backslashes
    escaped with a backslash.

    Args:
        parts: (one or more strings)
            Indicating path of the key to be used.
    c                p    |D ]!  }t        |t              r|rd}t        |       t        |      | _        y )Nz3One or more components is not a string or is empty.)r@   r   r   tupleparts)selfrQ   parterrors       r   __init__zFieldPath.__init__
  s:     	(DdC(M ''	( 5\
r*   c                X    |j                         }|st        d       | t        |       S )a  Factory: create a FieldPath from the string formatted per the API.

        Args:
            api_repr (str): a string path, with non-identifier elements quoted
            It cannot exceed 1500 characters, and cannot be empty.
        Returns:
            (:class:`FieldPath`) An instance parsed from ``api_repr``.
        Raises:
            ValueError if the parsing fails
        z.Field path API representation cannot be empty.)stripr   r6   )clsr3   s     r   from_api_reprzFieldPath.from_api_repr  s0     >>#MNN$X.//r*   c                    	 | j                  |      S # t        $ r_ |j                  d      }|D ]>  }|st        d      t        j	                  |      s&t        dj                  |             t        | cY S w xY w)a  Factory: create a FieldPath from a unicode string representation.

        This method splits on the character `.` and disallows the
        characters `~*/[]`. To create a FieldPath whose components have
        those characters, call the constructor.

        Args:
            path_string (str): A unicode string which cannot contain
            `~*/[]` characters, cannot exceed 1500 bytes, and cannot be empty.

        Returns:
            (:class:`FieldPath`) An instance parsed from ``path_string``.
        r   zEmpty elementz.Invalid char in element with leading alpha: {})rY   r   split_LEADING_ALPHA_INVALIDr   r   rN   )rX   path_stringr&   r(   s       r   from_stringzFieldPath.from_string"  s    	($$[11 		("((-H# $_55)//8$HOOPWX 	 h''		(s    AA;#A;:A;c                j    d}| j                   D ]  }|d|z   dz   z  } |d d }dj                  |      S )N 'z',r,   zFieldPath({}))rQ   r   )rR   pathsrS   s      r   __repr__zFieldPath.__repr__>  sI    JJ 	'DS4Z$&&E	'cr
%%e,,r*   c                4    t        | j                               S N)hashto_api_reprrR   s    r   __hash__zFieldPath.__hash__E  s    D$$&''r*   c                `    t        |t              r| j                  |j                  k(  S t        S re   r@   rN   rQ   NotImplementedrR   others     r   __eq__zFieldPath.__eq__H  s%    eY'::,,r*   c                `    t        |t              r| j                  |j                  k  S t        S re   rk   rm   s     r   __lt__zFieldPath.__lt__M  s%    eY'::++r*   c                    t        |t              r!| j                  |j                  z   }t        | S t        |t              r4| j                  t        j	                  |      j                  z   }t        | S t
        S )zAdds `other` field path to end of this field path.

        Args:
            other (~google.cloud.firestore_v1._helpers.FieldPath, str):
                The field path to add to the end of this `FieldPath`.
        )r@   rN   rQ   r   r^   rl   )rR   rn   rQ   s      r   __add__zFieldPath.__add__R  se     eY'JJ,Ee$$s#JJ!6!6u!=!C!CCEe$$!!r*   c                ,    t        | j                        S )zRender a quoted string representation of the FieldPath

        Returns:
            (str) Quoted string representation of the path stored
            within this FieldPath.
        )r=   rQ   rh   s    r   rg   zFieldPath.to_api_reprb  s     !,,r*   c                    | j                   dt        |j                          |j                   dt        | j                          k(  S )zCheck whether ``other`` is an ancestor.

        Returns:
            (bool) True IFF ``other`` is an ancestor or equal to ``self``,
            else False.
        N)rQ   r   rm   s     r   eq_or_parentzFieldPath.eq_or_parentk  s8     zz,C,-=Ns4::1OOOr*   c                    t        dt        | j                              }|D ch c]  }t        | j                  d|   c}S c c}w )zVReturn field paths for all parents.

        Returns: Set[:class:`FieldPath`]
        r-   N)ranger   rQ   rN   )rR   indexesrI   s      r   lineagezFieldPath.lineaget  s<    
 3tzz?+<CD5	4::fu-.DDDs   Ac                      y)zA special FieldPath value to refer to the ID of a document. It can be used
           in queries to sort or filter by the document ID.

        Returns: A special sentinel value to refer to the ID of a document.
        __name__ r}   r*   r   document_idzFieldPath.document_id|  s     r*   Nr3   r   )r]   r   )r|   
__module____qualname____doc__rU   classmethodrY   r^   rc   ri   ro   rq   rs   rg   rv   rz   staticmethodr~   r}   r*   r   rN   rN      sr    " 0 0  ( (6-(

" -PE  r*   rN   )r   r   )r   z
str | Noner   )r4   zIterable[str])rF   r   rG   dict) r   
__future__r   recollectionsr   typingr   r   rB   rD   rE   r9   r2   r1   r0   r/   compiler8   r\   PATH_ELEMENT_TOKENSr:   TOKENS_PATTERNr   r#   r)   r6   r=   get_field_pathrL   objectrN   r}   r*   r   <module>r      s    I " 	  != N M   
!^ 	* RZZ :; #$GH  
 UATUUrzz.)W* F:&.R #JZI Ir*   