o
    Ph                     @   s   d Z dZddlZddlZddlZh dZdZdZ					ddej	d	ej
e d
ej
e dej
eje  dedej	fddZee dS )u  
# 🌱 Turn any object into a module 🌱

Callable modules!  Indexable modules!?

Ever wanted to call a module directly, or index it?  Or just sick of seeing
`from foo import foo` in your examples?

Give your module the awesome power of an object, or maybe just save a
little typing, with `xmod`.

`xmod` is a tiny library that lets a module to do things that normally
only a class could do - handy for modules that "just do one thing".

## Example: Make a module callable like a function!

    # In your_module.py
    import xmod

    @xmod
    def a_function():
        return 'HERE!!'


    # Test at the command line
    >>> import your_module
    >>> your_module()
    HERE!!

## Example: Make a module look like a list!?!

    # In your_module.py
    import xmod

    xmod(list(), __name__)

    # Test at the command line
    >>> import your_module
    >>> assert your_module == []
    >>> your_module.extend(range(3))
    >>> print(your_module)
    [0, 1, 2]
)xmod    N>   __new____init__	__class____getattr____setattr____getattribute____init_subclass___xmod_extension_xmod_wrappedF	extensionnamefullomitmutablereturnc                    s   du rt jt|||dS dtjfdddtjffdddtf fdd	}|p3t d
d}|s:tdtj	| dtj
f fdd}d fdd}d fdd}td|d|d|dtdit r d< t t< n|du rtd t< d}|du rtnt|}	|rt ndD ]}
|
|	vrt |
}|
dot|}|r||
< q	 qdtjffdd}|d< t|tf}| tj	|<  S ) ax  
    Extend the system module at `name` with any Python object.

    The original module is replaced in `sys.modules` by a proxy class
    which delegates attributes to the original module, and then adds
    attributes from the extension.

    In the most common use case, the extension is a callable and only the
    `__call__` method is delegated, so `xmod` can also be used as a
    decorator, both with and without parameters.

    Args:
      extension: The object whose methods and properties extend the namespace.
        This includes magic methods like __call__ and __getitem__.

      name: The name of this symbol in `sys.modules`.  If this is `None`
        then `xmod` will use `extension.__module__`.

        This only needs to be be set if `extension` is _not_ a function or
        class defined in the module that's being extended.

        If the `name` argument is given, it should almost certainly be
        `__name__`.

      full: If `False`, just add extension as a callable.

        If `True`, extend the module with all members of `extension`.

        If `None`, the default, add the extension if it's a callable, otherwise
        extend the module with all members of `extension`.

      mutable: If `True`, the attributes on the proxy are mutable and write
        through to the underlying module.  If `False`, the default, attributes
        on the proxy cannot be changed.

      omit: A list of methods _not_ to delegate from the proxy to the extension

        If `omit` is None, it defaults to `xmod._OMIT`, which seems to
        work well.

    Returns:
        `extension`, the original item that got decorated
    N)r   r   r   r   r   c                    s   t   fdd}|S )Nc                    s    |i |S N )selfargskwargsfr   H/var/www/html/env_mimamsha/lib/python3.10/site-packages/xmod/__init__.pywrappedy   s   z%xmod.<locals>.method.<locals>.wrapped)	functoolswraps)r   r   r   r   r   methodx   s   zxmod.<locals>.methodc                    s   dd }r
 | S |S )Nc                  _   s   t d|  d| )NzClass is immutable  )	TypeError)r   r   r   r   r   fail   s   z#xmod.<locals>.mutator.<locals>.failr   )r   r    )r   r   r   r   mutator   s   zxmod.<locals>.mutatorc                    s6   t  fdd fdd fddS )Nc                      
   t  S r   )getattrr   r   kr   r   <lambda>      
 z$xmod.<locals>.prop.<locals>.<lambda>c                    s   t  | S r   )setattr)vr$   r   r   r&      s    c                      r"   r   )delattrr   r$   r   r   r&      r'   )propertyr%   )r   r   r!   r,   r   prop   s
   zxmod.<locals>.prop
__module__z`name` parameter must be setc                    s*   zt  | W S  ty   t |  Y S w r   )r#   AttributeErrorr,   r   moduler   r   _getattr   s
   zxmod.<locals>._getattrc                    s*   t  | rt | | d S t| | d S r   )hasattrr(   )r%   r)   r0   r   r   _setattr   s   
zxmod.<locals>._setattrc                    sV   d}zt  |  W n ty   d}Y nw zt |  W d S  ty*   |s' Y d S w )NTF)r*   r/   )r%   successr0   r   r   _delattr   s   zxmod.<locals>._delattrr   r   __delattr____doc____call__Fz+extension must be callable if full is FalseTr   __c                    s   t t tS r   )sortedsetuniondir)r   )membersr1   r   r   	directory   s   zxmod.<locals>.directory__dir__)r   N)r   partialr   tCallabler+   r#   
ValueErrorsysmodulesAny_WRAPPED_ATTRIBUTEcallablestaticmethod_EXTENSION_ATTRIBUTE_OMITr<   r>   
startswithListtypeobject)r   r   r   r   r   r-   r2   r4   r6   omavalueis_magicr@   proxy_classr   )r   r?   r   r1   r   r!   r   r   @   sR   2



r   )NNNNF)r8   __all__r   rF   typingrC   rM   rL   rI   rH   OptionalstrboolSequencer   r   r   r   r   <module>   s8    +

 