a
    1$eR                     @   sn  d Z ddlmZmZ ddlmZ ddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZmZmZmZmZmZmZmZmZ ddlmZmZmZ ddlmZmZ G dd	 d	e	jZe Zee Z!G d
d dZ"dd Z#dd Z$dd Z%dd Z&dd Z'dd Z(G dd dZ)dd Z*dd Z+dd Z,ej-d d!eG d"d# d#Z.d2d&d'Z/d(ej0vre 1 Z2e2re!3d)e2 ed(e2 n@e 4d*re!3d+ n&e 5 Z2e2red(e2 e!3d,e2 d-ej0v rej0d- Z2ee2 nd.ej0v rej0d. Z2ee2 nhe 1 r.e 1 Z2e!3d/e2 ee2 n<e 6 rFe!3d0 n$e 5 Z2e2rje!3d1e2 ee2 dS )3zFiona's GDAL/AWS environment    )wrapstotal_ordering)getfullargspecN)	GDALDataFinderGDALEnvPROJDataFindercalc_gdal_version_numget_gdal_configget_gdal_release_nameget_gdal_version_numset_gdal_configset_proj_data_search_path)EnvErrorFionaDeprecationWarningGDALVersionError)SessionDummySessionc                   @   s   e Zd Zdd ZdS )	ThreadEnvc                 C   s   d | _ d | _d S N)_env_discovered_optionsself r   E/var/www/html/django/DPS/env/lib/python3.9/site-packages/fiona/env.py__init__   s    zThreadEnv.__init__N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   sf   e Zd ZdZedd ZdddejfddZedd	 Z	d
d Z
dd Zdd Zdd ZdddZdS )Enva  Abstraction for GDAL and AWS configuration

    The GDAL library is stateful: it has a registry of format drivers,
    an error stack, and dozens of configuration options.

    Fiona's approach to working with GDAL is to wrap all the state
    up using a Python context manager (see PEP 343,
    https://www.python.org/dev/peps/pep-0343/). When the context is
    entered GDAL drivers are registered, error handlers are
    configured, and configuration options are set. When the context
    is exited, drivers are removed from the registry and other
    configurations are removed.

    Example:

        with fiona.Env(GDAL_CACHEMAX=512) as env:
            # All drivers are registered, GDAL's raster block cache
            # size is set to 512MB.
            # Commence processing...
            ...
            # End of processing.

        # At this point, configuration options are set to their
        # previous (possible unset) values.

    A boto3 session or boto3 session constructor arguments
    `aws_access_key_id`, `aws_secret_access_key`, `aws_session_token`
    may be passed to Env's constructor. In the latter case, a session
    will be created as soon as needed. AWS credentials are configured
    for GDAL as needed.
    c                 C   s   ddddS )zDefault configuration options

        Parameters
        ----------
        None

        Returns
        -------
        dict

        TF)ZCHECK_WITH_INVERT_PROJZGTIFF_IMPLICIT_JPEG_OVRZ	FIONA_ENVr   clsr   r   r   default_optionsa   s    zEnv.default_optionsNFc           
      K   s   | dd}|rtdt | dd}| dd}| dd}	ddh|sVtd	|rt|ts|td
t tj|d}|| _	nN|s|s|rtj||||	||d| _	n(ddh
tj rt | _	nt | _	| | _i | _dS )a   Create a new GDAL/AWS environment.
        Note: this class is a context manager. GDAL isn't configured
        until the context is entered via `with fiona.Env():`

        Parameters
        ----------
        session : optional
            A Session object.
        aws_unsigned : bool, optional
            Do not sign cloud requests.
        profile_name : str, optional
            A shared credentials profile name, as per boto3.
        session_class : Session, optional
            A sub-class of Session.
        **options : optional
            A mapping of GDAL configuration options, e.g.,
            `CPL_DEBUG=True, CHECK_WITH_INVERT_PROJ=False`.

        Returns
        -------
        Env

        Notes
        -----
        We raise EnvError if the GDAL config options
        AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY are given. AWS
        credentials are handled exclusively by boto3.

        Examples
        --------
        >>> with Env(CPL_DEBUG=True, CPL_CURL_VERBOSE=True):
        ...     with fiona.open("zip+https://example.com/a.zip") as col:
        ...         print(col.profile)

        For access to secured cloud resources, a Fiona Session or a
        foreign session object may be passed to the constructor.

        >>> import boto3
        >>> from fiona.session import AWSSession
        >>> boto3_session = boto3.Session(...)
        >>> with Env(AWSSession(boto3_session)):
        ...     with fiona.open("zip+s3://example/a.zip") as col:
        ...         print(col.profile

        aws_access_key_idNzaPassing abstract session keyword arguments is deprecated. Pass a Fiona AWSSession object instead.aws_secret_access_keyaws_session_tokenregion_nameAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYzdGDAL's AWS config options can not be directly set. AWS credentials are handled exclusively by boto3.zNPassing a boto3 session is deprecated. Pass a Fiona AWSSession object instead.session)r#   r$   r%   r&   profile_nameaws_unsigned)popwarningswarnr   
isdisjointr   
isinstancer   aws_or_dummyr*   issubsetosenvironkeysZfrom_environr   copyoptionscontext_options)
r   r*   r,   r+   Zsession_classr8   r#   r$   r%   r&   r   r   r   r   t   sF    5

	
zEnv.__init__c                 O   s&   t  }|jf i | t |i |S )au  Create an environment with default config options

        Parameters
        ----------
        args : optional
            Positional arguments for Env()
        kwargs : optional
            Keyword arguments for Env()

        Returns
        -------
        Env

        Notes
        -----
        The items in kwargs will be overlaid on the default values.

        )r   r"   update)r!   argskwargsr8   r   r   r   from_defaults   s    zEnv.from_defaultsc                 C   s.   | j  }| jjf i | tf i | dS )zGet credentials and configure GDAL

        Note well: this method is a no-op if the GDAL environment
        already has credentials, unless session is not None.

        Returns
        -------
        None

        N)r*   Zget_credential_optionsr8   r:   setenv)r   Z	cred_optsr   r   r   credentialize   s    
zEnv.credentializec                 C   s
   t j S )z'Return a mapping of registered drivers.)localr   driversr   r   r   r   rA     s    zEnv.driversc                 C   s
   t j S )zdWrites descriptions of open datasets to stderr

        For debugging and testing purposes.
        )r@   r   _dump_open_datasetsr   r   r   r   rB     s    zEnv._dump_open_datasetsc                 C   s   t jd u rjd| _i t _dd | j D }|D ]"}t|dd}|d ur.|t j|< q.tf i | j i | _nd| _t	 | _t
f i | j |   | S )NFc                 S   s   h | ]}|d kr|qS )ZRASTERIO_ENVr   ).0kr   r   r   	<setcomp>      z Env.__enter__.<locals>.<setcomp>	normalizeT)r@   r   _has_parent_envr   r8   r6   r	   defenvr9   getenvr>   r?   )r   Z	probe_envkeyvalr   r   r   	__enter__  s    
zEnv.__enter__c                 C   sR   t   | jr$t  tf i | j n*tjrHtj \}}t||dd q$d t_d S )NFrG   )	delenvrI   rJ   r>   r9   r@   r   popitemr   )r   exc_typeexc_valexc_tbrL   rM   r   r   r   __exit__&  s    zEnv.__exit__)NNN)r   r   r   __doc__classmethodr"   r   r2   r   r=   r?   rA   rB   rN   rT   r   r   r   r   r   @   s    

h
r   c                  K   s.   t js t t _t jjf i |  t j  dS )z*Create a default environment if necessary.N)r@   r   r   update_config_optionsstartr8   r   r   r   rJ   5  s    rJ   c                   C   s    t jstdnt jj S dS )z!Get a mapping of current options.No GDAL environment existsN)r@   r   r   r8   r7   r   r   r   r   rK   >  s    
rK   c                   C   s
   t tjS r   )boolr@   r   r   r   r   r   hasenvF  s    r\   c                  K   s&   t jstdnt jjf i |  dS )z(Set options in the existing environment.rZ   N)r@   r   r   rW   rY   r   r   r   r>   J  s    
r>   c                   C   s(   t dt tjd uo&tdd dD S )Nz)Please use Env.session.hascreds() insteadc                 s   s   | ]}|t j v V  qd S r   )r@   r   Zget_config_options)rC   rL   r   r   r   	<genexpr>T  s   zhascreds.<locals>.<genexpr>)r'   r(   )r.   r/   r   r@   r   allr   r   r   r   hascredsR  s    r_   c                   C   s.   t jstdn
t j  t j  dt _dS )z+Delete options in the existing environment.rZ   N)r@   r   r   Zclear_config_optionsstopr   r   r   r   rO   Z  s
    


rO   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )NullContextManagerc                 C   s   d S r   r   r   r   r   r   r   f  s    zNullContextManager.__init__c                 C   s   | S r   r   r   r   r   r   rN   i  s    zNullContextManager.__enter__c                 G   s   d S r   r   )r   r;   r   r   r   rT   l  s    zNullContextManager.__exit__N)r   r   r   r   rN   rT   r   r   r   r   ra   e  s   ra   c                   C   s   t jrt S t S dS )zjReturn an Env if one does not exist

    Returns
    -------
    Env or a do-nothing context manager

    N)r@   r   ra   r   r=   r   r   r   r   env_ctx_if_neededp  s    rb   c                    s   t   fdd}|S )ah  A decorator that ensures an env exists before a function
    calls any GDAL C functions.

    Parameters
    ----------
    f : function
        A function.

    Returns
    -------
    A function wrapper.

    Notes
    -----
    If there is already an existing environment, the wrapper does
    nothing and immediately calls f with the given arguments.

    c                     sN   t jr | i |S t   | i |W  d    S 1 s@0    Y  d S r   )r@   r   r   r=   )r;   r<   fr   r   wrapper  s    
zensure_env.<locals>.wrapperr   rd   re   r   rc   r   
ensure_env~  s    rh   c                    s   t   fdd}|S )a  Ensures a config environment exists and has credentials.

    Parameters
    ----------
    f : function
        A function.

    Returns
    -------
    A function wrapper.

    Notes
    -----
    The function wrapper checks the first argument of f and
    credentializes the environment if the first argument is a URI with
    scheme "s3".

    If there is already an existing environment, the wrapper does
    nothing and immediately calls f with the given arguments.

    c                     s   t jrt}ntj}|dd p$| d }t|trXt|}t jrP|	t
 rPt}| }nt }||d  | i |W  d    S 1 s0    Y  d S )Nfpr   r)   )r@   r   r   r=   getr1   strr   Zcls_from_pathr_   rK   r   )r;   kwdsZenv_ctorZfp_argZsession_clsr*   rc   r   r   re     s    

z,ensure_env_with_credentials.<locals>.wrapperrf   rg   r   rc   r   ensure_env_with_credentials  s    rm   T)slotsc                   @   s|   e Zd ZdZejdejedZ	ejdejedZ
dd Zdd Zdd	 Zd
d Zedd Zedd Zdd ZdS )GDALVersiona
  Convenience class for obtaining GDAL major and minor version
    components and comparing between versions.  This is highly
    simplistic and assumes a very normal numbering scheme for versions
    and ignores everything except the major and minor components.

    r   )default	validatorc                 C   s   | j | jft|j |jkS r   majorminortupler   otherr   r   r   __eq__  s    zGDALVersion.__eq__c                 C   s   | j | jft|j |jk S r   rr   rv   r   r   r   __lt__  s    zGDALVersion.__lt__c                 C   s   d| j  d| j dS )NzGDALVersion(major=z, minor=)rs   rt   r   r   r   r   __repr__  s    zGDALVersion.__repr__c                 C   s   | j  d| j S )N.r{   r   r   r   r   __str__  s    zGDALVersion.__str__c                 C   s|   t || r|S t |tr | | S t |trptd|}|sHtd|dd | dD \}}| ||dS t	ddS )	a+  
        Parses input tuple or string to GDALVersion. If input is a GDALVersion
        instance, it is returned.

        Parameters
        ----------
        input: tuple of (major, minor), string, or instance of GDALVersion

        Returns
        -------
        GDALVersion instance

        z	^\d+\.\d+z;value does not appear to be a valid GDAL version number: {}c                 s   s   | ]}t |V  qd S r   )int)rC   cr   r   r   r]     rF   z$GDALVersion.parse.<locals>.<genexpr>r}   r{   z5GDALVersion can only be parsed from a string or tupleN)
r1   ru   rk   research
ValueErrorformatgroupsplit	TypeError)r!   inputmatchrs   rt   r   r   r   parse  s    


zGDALVersion.parsec                 C   s   |  t S )z*Return GDALVersion of current GDAL runtime)r   r
   r    r   r   r   runtime  s    zGDALVersion.runtimec                 C   s   | j |}| |kS r   )	__class__r   rv   r   r   r   at_least  s    zGDALVersion.at_leastN)r   r   r   rU   attrib
validatorsinstance_ofr   rs   rt   rx   ry   r|   r~   rV   r   r   r   r   r   r   r   ro     s   
 
ro   F c                    s   dur0du rt dttttfs0t dtt k rNdnd r`d n fdd}|S )	a  A decorator that ensures the called function or parameters are supported
    by the runtime version of GDAL.  Raises GDALVersionError if conditions
    are not met.

    Examples:
    
        @require_gdal_version('2.2')
        def some_func():

    calling `some_func` with a runtime version of GDAL that is < 2.2 raises a
    GDALVersionErorr.

    
        @require_gdal_version('2.2', param='foo')
        def some_func(foo='bar'):

    calling `some_func` with parameter `foo` of any value on GDAL < 2.2 raises
    a GDALVersionError.

    
        @require_gdal_version('2.2', param='foo', values=('bar',))
        def some_func(foo=None):

    calling `some_func` with parameter `foo` and value `bar` on GDAL < 2.2
    raises a GDALVersionError.


    Parameters
    ------------
    version: tuple, string, or GDALVersion
    param: string (optional, default: None)
        If `values` are absent, then all use of this parameter with a value
        other than default value requires at least GDAL `version`.
    values: tuple, list, or set (optional, default: None)
        contains values that require at least GDAL `version`.  `param`
        is required for `values`.
    is_max_version: bool (optional, default: False)
        if `True` indicates that the version provided is the maximum version
        allowed, instead of requiring at least that version.
    reason: string (optional: default: '')
        custom error message presented to user in addition to message about
        GDAL version.  Use this to provide an explanation of what changed
        if necessary context to the user.

    Returns
    ---------
    wrapped function

    Nz8require_gdal_version: param must be provided with valuesz:require_gdal_version: values must be a tuple, list, or setz>=z<=
c              	      s&   t   fdd}|S )Nc                     s  k rrrkrd u r6t dtt }| }|jrn|tt|jd t	|  |  |j
rttt|jt|j
}ni }|v rd u r҈|vs| | krt dn&| v rt d|  | i |S )NzGDAL version must be {} {}{}z-usage of parameter "{}" requires GDAL {} {}{}z'parameter "{}={}" requires GDAL {} {}{})r   r   rk   r   r7   r;   r:   dictziplendefaultsreversed)r;   rl   ZargspecZ	full_kwdsr   )rd   
inequalityis_max_versionparamreasonr   valuesversionr   r   re   U  sJ    
"z8require_gdal_version.<locals>.decorator.<locals>.wrapperrf   rg   r   r   r   r   r   r   r   rc   r   	decoratorT  s    0z'require_gdal_version.<locals>.decorator)r   r1   ru   listsetro   r   r   )r   r   r   r   r   r   r   r   r   require_gdal_version  s    4
4r   Z	GDAL_DATAz$GDAL data found in package: path=%r.z
header.dxfz0GDAL data files are available at built-in paths.z,GDAL data found in other locations: path=%r.Z	PROJ_DATAZPROJ_LIBz$PROJ data found in package: path=%r.z0PROJ data files are available at built-in paths.z,PROJ data found in other locations: path=%r.)NNFr   )7rU   	functoolsr   r   inspectr   loggingr4   r   	threadingr.   r   Z
fiona._envr   r   r   r   r	   r
   r   r   r   Zfiona.errorsr   r   r   Zfiona.sessionr   r   r@   r   	getLoggerr   logr   rJ   rK   r\   r>   r_   rO   ra   rb   rh   rm   sro   r   r5   Zsearch_wheelpathdebugZ	find_filer   has_datar   r   r   r   <module>   st   ,
 v	1
C 
{









