
    -hR                        d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 erd dl
mZmZ d dlmZ ddZedd            ZdddZdS )    )annotationsN)contextmanager)import_module)TYPE_CHECKINGAny)IteratorSequence)PatherrorBaseExceptionobjpathstrreturnc                F    dt           j        d|d| j        j         d|  S )NzWith sys.path = z, accessing z raises z: )syspath	__class____name__)r   r   s     M/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/_griffe/importer.py_error_detailsr      s0    lchllgllIallejlll    paths
str | PathIterator[None]c               '     K   | sdV  dS t           j        }d | D             t           _        	 dV  |t           _        dS # |t           _        w xY w)zRedefine `sys.path` temporarily.

    Parameters:
        *paths: The paths to use when importing modules.
            If no paths are given, keep `sys.path` untouched.

    Yields:
        Nothing.
    Nc                ,    g | ]}t          |          S  )r   ).0r   s     r   
<listcomp>zsys_path.<locals>.<listcomp>$   s    ,,,dD		,,,r   )r   r   )r   old_paths     r   sys_pathr!      sf        xH,,e,,,CH8s   A   Aimport_pathimport_pathsSequence[str | Path] | Noner   c                   |                      d          }g }g }t          |pd 5  |rd                    |          }	 t          |          }n# t          $ rV}|                    t          ||                     |                    d|                    d                     Y d}~nd}~ww xY w|t          d                    |                    |}|D ]}		 t          ||	          }# t          $ rc}|                    t          ||dz   d                    |          z                        t          d                    |                    d}~ww xY w	 ddd           n# 1 swxY w Y   |S )a  Dynamically import the specified object.

    It can be a module, class, method, function, attribute,
    nested arbitrarily.

    It works like this:

    - for a given object path `a.b.x.y`
    - it tries to import `a.b.x.y` as a module (with `importlib.import_module`)
    - if it fails, it tries again with `a.b.x`, storing `y`
    - then `a.b`, storing `x.y`
    - then `a`, storing `b.x.y`
    - if nothing worked, it raises an error
    - if one of the iteration worked, it moves on, and...
    - it tries to get the remaining (stored) parts with `getattr`
    - for example it gets `b` from `a`, then `x` from `b`, etc.
    - if a single attribute access fails, it raises an error
    - if everything worked, it returns the last obtained attribute

    Since the function potentially tries multiple things before succeeding,
    all errors happening along the way are recorded, and re-emitted with
    an `ImportError` when it fails, to let users know what was tried.

    IMPORTANT: The paths given through the `import_paths` parameter are used
    to temporarily patch `sys.path`: this function is therefore not thread-safe.

    IMPORTANT: The paths given as `import_paths` must be *correct*.
    The contents of `sys.path` must be consistent to what a user of the imported code
    would expect. Given a set of paths, if the import fails for a user, it will fail here too,
    with potentially unintuitive errors. If we wanted to make this function more robust,
    we could add a loop to "roll the window" of given paths, shifting them to the left
    (for example: `("/a/a", "/a/b", "/a/c/")`, then `("/a/b", "/a/c", "/a/a/")`,
    then `("/a/c", "/a/a", "/a/b/")`), to make sure each entry is given highest priority
    at least once, maintaining relative order, but we deem this unnecessary for now.

    Parameters:
        import_path: The path of the object to import.
        import_paths: The (sys) paths to import the object from.

    Raises:
        ModuleNotFoundError: When the object's module could not be found.
        ImportError: When there was an import error or when couldn't get the attribute.

    Returns:
        The imported object.
    .r   r   Nz; :)splitr!   joinr   r   appendr   insertpopImportErrorgetattr)
r"   r#   module_partsobject_partserrorsmodule_pathmoduler   valueparts
             r   dynamic_importr7   +   s   ^ *//44L LF	L&B	( 5 5 	1((<00K&{33  ! = = = nUK@@AAA##A|'7'7';';<<<<<<<<	=	  	1 dii//000   	5 	5D5t,,  5 5 5nUK#4EQ]H^H^4^__```!$))F"3"34445	5-5 5 5 5 5 5 5 5 5 5 5 5 5 5 5: Ls`   E*AE*
B.AB)$E*)B..-E*C-,E*-
E7AEEE**E.1E.)r   r   r   r   r   r   )r   r   r   r   )N)r"   r   r#   r$   r   r   )
__future__r   r   
contextlibr   	importlibr   typingr   r   collections.abcr   r	   pathlibr
   r   r!   r7   r   r   r   <module>r>      s   
 # " " " " " 



 % % % % % % # # # # # # % % % % % % % % 22222222m m m m    *P P P P P P Pr   