
    g                          d Z dZ G d d      Zy)a   Helper to enable simple lazy module import.

    'Lazy' means the actual import is deferred until an attribute is
    requested from the module's namespace. This has the advantage of
    allowing all imports to be done at the top of a script (in a
    prominent and visible place) without having a great impact
    on startup time.

    Copyright (c) 1999-2005, Marc-Andre Lemburg; mailto:mal@lemburg.com
    See the documentation for further information on copyrights,
    or contact the author. All Rights Reserved.
    c                   D    e Zd ZdZdZdZdZdZdZd
dZ	d Z
d Zd Zd	 Zy)
LazyModulea  Lazy module class.

    Lazy modules are imported into the given namespaces whenever a
    non-special attribute (there are some attributes like __doc__
    that class instances handle without calling __getattr__) is
    requested. The module is then registered under the given name
    in locals usually replacing the import wrapper instance. The
    import itself is done using globals as global namespace.

    Example of creating a lazy load module:

    ISO = LazyModule('ISO',locals(),globals())

    Later, requesting an attribute from ISO will load the module
    automatically into the locals() namespace, overriding the
    LazyModule instance:

    t = ISO.Week(1998,1,1)

    r    Nc                     || _         ||}|| _        |j                  dd      }|r|dz   |z   | _        || _        d| _        y|x| _        | _        d| _        y)zCreate a LazyModule instance wrapping module name.

        The module will later on be registered in locals under the
        given module name.

        globals is optional and defaults to locals.

        N__name__r   .   )_LazyModule__lazymodule_locals_LazyModule__lazymodule_globalsgetr   _LazyModule__lazymodule_name_LazyModule__lazymodule_init)selfnamelocalsglobalsmainnames        D/var/www/openai/venv/lib/python3.12/site-packages/nltk/lazyimport.py__init__zLazyModule.__init__>   sl     $* ?G$+!;;z2.$sNT1DM%)D" "# 6:9DMD2!"    c                    | j                   }| j                  }| j                  r| j                  |   S t        rt        d|z         t        || j                  | j                  d      x| j                  |<   }| j                  j                  |j                         d| j                  d<   t        rt        d|z         |S )zImport the module now.zLazyModule: Loading module %r*r	   __lazymodule_loadedzLazyModule: Module %r loaded)
r   r   _LazyModule__lazymodule_loadedr
   _debugprint
__import__r   __dict__update)r   
local_name	full_namemodules       r   __lazymodule_importzLazyModule.__lazymodule_importS   s     ++
MM	##++J771I=>8Bt//1J1JC9
 	
  ,v 	V__- 01+,09<=r   c                     | j                   rt        |      t        rt        d|z         | j	                         }t        ||      S )z2Import the module on demand and get the attribute.z=LazyModule: Module load triggered by attribute %r read access)r   AttributeErrorr   r   _LazyModule__lazymodule_importgetattr)r   r   r"   s      r   __getattr__zLazyModule.__getattr__k   sM    ## &&DFJK ))+vt$$r   c                    | j                   s|| j                  |<   y| j                  r)|| j                  | j                  <   || j                  |<   yt
        rt        d|z         | j                         }t        |||       y)z2Import the module on demand and set the attribute.Nz>LazyModule: Module load triggered by attribute %r write access)	r   r   r   r
   r   r   r   r&   setattr)r   r   valuer"   s       r   __setattr__zLazyModule.__setattr__w   s    %%"'DMM$##?DD$$T%;%;<"'DMM$EGKL ))+e$r   c                      d| j                   z  S )Nz<LazyModule '%s'>)r   )r   s    r   __repr__zLazyModule.__repr__   s    "T]]22r   )N)r   
__module____qualname____doc__r   r   r   r
   r   r   r&   r(   r,   r.    r   r   r   r      sH    ,      #*0
%%"3r   r   N)r1   r   r   r2   r   r   <module>r3      s   
 

p3 p3r   