o
    h>                     @   s   d Z ddlZddlZddlmZmZ ddlmZmZ ddl	m
Z
 ddlZddlmZ ddlmZ G dd	 d	Zd
d Zefdee dee fddZdS )z!Decorators for Shapely functions.    N)CallableIterable)	lru_cachewraps)unwrap)libUnsupportedGEOSVersionErrorc                   @   s    e Zd ZdZdd Zdd ZdS )requires_geosz,Decorator to require a minimum GEOS version.c                 C   s4   | ddkrtdtdd |dD | _dS )z8Create a decorator that requires a minimum GEOS version..   z.Version must be <major>.<minor>.<patch> formatc                 s   s    | ]}t |V  qd S N)int).0x r   M/var/www/html/scripts/venv/lib/python3.10/site-packages/shapely/decorators.py	<genexpr>   s    z)requires_geos.__init__.<locals>.<genexpr>N)count
ValueErrortuplesplitversion)selfr   r   r   r   __init__   s   zrequires_geos.__init__c                    s   t j| jk}tjddk}|r|s S dj jg| jR  |r,t  fdd}n
t fdd}|j	}|rb|
dd }d	}	 |||  dkrR|d7 }nnqE|ddd| d|_	|S )zReturn the wrapped function.SPHINX_DOC_BUILD1z%'{}' requires at least GEOS {}.{}.{}.c                     s    | i |S r   r   argskwargsfuncr   r   wrapped$   s   z'requires_geos.__call__.<locals>.wrappedc                     s   t  r   r   r   )msgr   r   r"   *   s   z

r   r   T    z

{}.. note:: {}

)r   geos_versionr   osenvirongetformat__name__r   __doc__findreplace)r   r!   is_compatibleis_doc_buildr"   docpositionindentr   )r!   r#   r   __call__   s6   
zrequires_geos.__call__N)r+   
__module____qualname__r,   r   r4   r   r   r   r   r
      s    r
   c                    s   t   fdd}|S )zEnable multithreading.

    To do this, the writable flags of object type ndarrays are set to False.

    NB: multithreading also requires the GIL to be released, which is done in
    the C extension (ufuncs.c).
    c               	      s   dd | D dd |  D  }dd |D }z|D ]}d|j_q | i |W t||D ]\}}||j_q-S t||D ]\}}||j_q<w )Nc                 S   s&   g | ]}t |tjr|jtkr|qS r   
isinstancenpndarraydtypeobject)r   argr   r   r   
<listcomp>K   s    z;multithreading_enabled.<locals>.wrapped.<locals>.<listcomp>c                 S   s2   g | ]\}}|d vrt |tjr|jtkr|qS )>   outwherer7   )r   namer=   r   r   r   r>   M   s    

c                 S   s   g | ]}|j jqS r   )flags	writeable)r   arrr   r   r   r>   T   s    F)itemsrB   rC   zip)r   r   
array_args	old_flagsrD   old_flagr    r   r   r"   I   s"   	


z'multithreading_enabled.<locals>.wrapped)r   )r!   r"   r   r    r   multithreading_enabled@   s   	rJ   should_be_kwargscategoryc                    s   dt f fdd}|S )aS  Show warning if positional arguments are used that should be keyword.

    Parameters
    ----------
    should_be_kwargs : Iterable[str]
        Names of parameters that should be passed as keyword arguments.
    category : type[Warning], optional (default: DeprecationWarning)
        Warning category to use for deprecation warnings.

    Returns
    -------
    callable
        Decorator function that adds positional argument deprecation warnings.

    Examples
    --------
    >>> from shapely.decorators import deprecate_positional
    >>> @deprecate_positional(['b', 'c'])
    ... def example(a, b, c=None):
    ...     return a, b, c
    ...
    >>> example(1, 2)  # doctest: +SKIP
    DeprecationWarning: positional argument `b` for `example` is deprecated. ...
    (1, 2, None)
    >>> example(1, b=2)  # No warnings
    (1, 2, None)
    r!   c                    s   t j}|jd |j }dd t|D fddD   s#S t d tddtf fdd	tfd
d}|S )Nc                 S   s   i | ]\}}||qS r   r   r   idxrA   r   r   r   
<dictcomp>   s    z;deprecate_positional.<locals>.decorator.<locals>.<dictcomp>c                    s    g | ]}| v r | |fqS r   r   )r   rA   )name_to_idxr   r   r>      s
    
z;deprecate_positional.<locals>.decorator.<locals>.<listcomp>r   
   n_argsc                    s    fddD }t |dkrd|d  d}d}d}n-d}d	}t |d
kr1ddd |D }nddd |d d D }|d|d  d7 }d| d| dj d| d| dS )Nc                    s   g | ]
\}}| k r|qS r   r   rM   rR   r   r   r>      s    zMdeprecate_positional.<locals>.decorator.<locals>.make_msg.<locals>.<listcomp>r%   `r    issarer   z and c                 s       | ]	}d | d V  qdS rT   Nr   r   ur   r   r   r          zLdeprecate_positional.<locals>.decorator.<locals>.make_msg.<locals>.<genexpr>z, c                 s   rY   rZ   r   r[   r   r   r   r      r]   z, and `zpositional argumentr$   z for `z` z( deprecated. Please use keyword argumentz	 instead.)lenjoinr+   )rR   usedargs_txtplrisare)deprecate_positionsr!   rS   r   make_msg   s"   z9deprecate_positional.<locals>.decorator.<locals>.make_msgc                     s6   | i |}t | }|krtj| dd |S )Nr   )rL   
stacklevel)r_   warningswarn)r   r   resultn)rL   r!   rf   	warn_fromr   r   wrapper   s
   z8deprecate_positional.<locals>.decorator.<locals>.wrapper)	r   __code__co_varnamesco_argcount	enumerateminr   r   r   )r!   code	pos_namesrm   rL   rK   )re   r!   rf   rP   rl   r   	decorator   s   

	z'deprecate_positional.<locals>.decorator)r   )rK   rL   rv   r   ru   r   deprecate_positional`   s    7rw   )r,   r'   rh   collections.abcr   r   	functoolsr   r   inspectr   numpyr9   shapelyr   shapely.errorsr	   r
   rJ   DeprecationWarningstrtypeWarningrw   r   r   r   r   <module>   s"    1"