
    SOgw                     :    S SK r SSKJr  SSKJr   " S S\5      rg)    N   )util)IPluginc                       \ rS rSrSr    SS jrSS jrS rS rS r	S	 r
S
 r\4S jrS rS rS rS rS rS rS rS rS rS rS rSrg)PluginManager   z
PluginManager manages the plugin state. It can automatically
instantiate classes and enforce uniqueness, which it does by default.
Nc                     Xl         X l        Uc  / nUc  / n[        R                  " U5      U l        [        R                  " U5      U l        g)al  
`unique_instances` determines if all plugins have to be unique.
This will also ensure that no two instances of the same class are
tracked internally.

`instantiate_classes` tracks to see if the class should automatically
instantiate class objects that are passed in.
`plugins` can be a single obj or iterable
`blacklisted plugins` can be a single obj or iterable
N)unique_instancesinstantiate_classesr   return_listpluginsblacklisted_plugins)selfr
   r   r   r   s        a/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/pluginmanager/plugin_manager.py__init__PluginManager.__init__   sL     !1#6 ?G&"$''0#'#3#34G#H     c                 4    U R                   nUb  U" U5      nU$ )z
Gets out the plugins from the internal state. Returns a list object.
If the optional filter_function is supplied, applies the filter
function to the arguments before returning them. Filters should
be callable and take a list argument of plugins.
)r   )r   filter_functionr   s      r   get_pluginsPluginManager.get_plugins%   s"     ,,&%g.Gr   c                 &    U R                  U5        g)aI  
Adds plugins to the internal state. `plugins` may be a single object
or an iterable.

If `instantiate_classes` is True and the plugins
have class instances in them, attempts to instatiate the classes.

If `unique_instances` is True and duplicate instances are passed in,
this method will not track the new instances internally.
N)_instance_parserr   r   s     r   add_pluginsPluginManager.add_plugins1   s     	g&r   c                 4    / U l         U R                  U5        g)aJ  
sets plugins to the internal state. `plugins` may be a single object
or an iterable.

If `instatntiate_classes` is True and the plugins
have class instances in them, attempts to instatiate the classes.

If `unique_instances` is True and duplicate instances are passed in,
this method will not track the new instances internally.
N)r   r   r   s     r   set_pluginsPluginManager.set_plugins>   s     g&r   c                 F    [         R                  " U R                  U5        g)z]
removes `plugins` from the internal state

`plugins` may be a single object or an iterable.
N)r   remove_from_listr   r   s     r   remove_pluginsPluginManager.remove_pluginsL   s     	dllG4r   c                 &    U R                  U5        g)z
removes `instances` from the internal state.

Note that this method is syntatic sugar for the
`remove_plugins` acts as a passthrough for that
function.
`instances` may be a single object or an iterable
N)r"   )r   	instancess     r   remove_instancePluginManager.remove_instanceT   s     	I&r   c                 j    U R                    Vs/ s H  n[        X!5      (       d  M  UPM     sn$ s  snf )z[
internal method that gets every instance of the klasses
out of the internal plugin state.
)r   
isinstance)r   klassesxs      r   _get_instancePluginManager._get_instance_   s'    
  <<B<a:a+A<BBBs   00c                     [        U[        [        45      (       a  U R                  U5      $ [        R
                  " U5      (       a  U R                  U5      $ Uc  U R                  $ U" U R                  5      $ )ak  
Gets instances out of the internal state using
the default filter supplied in filter_function.
By default, it is the class IPlugin.

Can optionally pass in a list or tuple of classes
in for `filter_function` which will accomplish
the same goal.

lastly, a callable can be passed in, however
it is up to the user to determine if the
objects are instances or not.
)r)   listtupler,   inspectisclassr   )r   r   s     r   get_instancesPluginManager.get_instancesf   se     oe}55%%o66___--%%o66$<<"4<<00r   c                 n    [         R                  " U5      nU H  n[        R                  " U5        M     g)zt
Register classes as plugins that are not subclassed from
IPlugin.
`classes` may be a single object or an iterable.
N)r   r   r   register)r   classesklasss      r   register_classesPluginManager.register_classes}   s,     ""7+EU# r   c                     [         R                  " U5      nU HB  n[        R                  " U5      (       a  U R	                  U5        M1  U R                  U5        MD     g)z
internal method to parse instances of plugins.

Determines if each class is a class instance or
object instance and calls the appropiate handler
method.
N)r   r   r1   r2   _handle_class_instance_handle_object_instance)r   r   instances      r   r   PluginManager._instance_parser   sI     ""7+Hx((++H5,,X6	  r   c                 N   XR                   ;   d  U R                  (       a
  U[        :X  a  gU R                  (       a7  U R	                  U5      (       a!  U R
                  R                  U" 5       5        gU R                  (       d!  U R
                  R                  U" 5       5        gg)z
handles class instances. If a class is blacklisted, returns.
If uniuqe_instances is True and the class is unique, instantiates
the class and adds the new object to plugins.

If not unique_instances, creates and adds new instance to plugin
state
N)r   r   r   r
   _unique_classr   append)r   r8   s     r   r<   $PluginManager._handle_class_instance   ss     ---(( ""t'9'9%'@'@LL(&&LL( 'r   c                     [        U5      nX R                  ;   a  g U R                  (       a3  U R                  U5      (       a  U R                  R                  U5        g g U R                  R                  U5        g N)typer   r
   rA   r   rB   )r   r>   r8   s      r   r=   %PluginManager._handle_object_instance   s[    X,,,""!!%((##H-LL)r   c                 x    U R                  5        H&  n[        US5      (       d  M  UR                  5         M(     g)zl
helper method that attempts to activate plugins
checks to see if plugin has method call before
calling it.
activateN)r3   hasattrrI   r   r>   s     r   activate_pluginsPluginManager.activate_plugins   s0     **,Hx,,!!# -r   c                 x    U R                  5        H&  n[        US5      (       d  M  UR                  5         M(     g)zo
helper method that attempts to deactivate plugins.
checks to see if plugin has method call before
calling it.

deactivateN)r3   rJ   rO   rK   s     r   deactivate_plugins PluginManager.deactivate_plugins   s0     **,Hx..##% -r   c                 L   ^ [        U4S jU R                   5       5      (       + $ )zM
internal method to check if any of the plugins are instances
of a given cls
c              3   <   >#    U  H  n[        UT5      v   M     g 7frE   )r)   ).0objclss     r   	<genexpr>.PluginManager._unique_class.<locals>.<genexpr>   s     D|z#s++|s   )anyr   )r   rV   s    `r   rA   PluginManager._unique_class   s    
 Dt||DDDDr   c                 f    [         R                  " U5      nU R                  R                  U5        g)zH
add blacklisted plugins.
`plugins` may be a single object or iterable.
N)r   r   r   extendr   s     r   add_blacklisted_plugins%PluginManager.add_blacklisted_plugins   s(    
 ""7+  ''0r   c                 <    [         R                  " U5      nXl        g)zI
sets blacklisted plugins.
`plugins` may be a single object or iterable.
N)r   r   r   r   s     r   set_blacklisted_plugins%PluginManager.set_blacklisted_plugins   s    
 ""7+#* r   c                     U R                   $ )zO
gets blacklisted plugins tracked in the internal state
Returns a list object.
)r   )r   s    r   get_blacklisted_plugins%PluginManager.get_blacklisted_plugins   s    
 '''r   c                 F    [         R                  " U R                  U5        g)z_
removes `plugins` from the blacklisted plugins.
`plugins` may be a single object or iterable.
N)r   r!   r   r   s     r   remove_blacklisted_plugins(PluginManager.remove_blacklisted_plugins   s    
 	d66@r   )r   r   r   r
   )TTNNrE   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r"   r&   r,   r   r3   r9   r   r<   r=   rL   rP   rA   r]   r`   rc   rf   __static_attributes__ r   r   r   r      s}    
 #'%)%)	I4
''5	'C -4 1.$7)$*$&E1+(Ar   r   )r1    r   ipluginr   objectr   rn   r   r   <module>rr      s      fAF fAr   