
    rbi3J              
          d Z ddlmZ ddlmZ ddlmZmZ ddlZ	ddl
mZmZmZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZmZ ddlZ ee          j                                        d
z  Zdddddddddd	Zd e                                 D             Z!g dZ"dddddddZ#d e            v Z$d Z%ej&        '                    e d          Z(ej&        '                    e d          Z)ej&        '                    e pe d          Z*ej&        '                    e d          Z+ej&        '                    e d          Z,d Z- ej.        d          d              Z/ ej.        d!          d"             Z0 ej.        d!e"#          d$             Z1 ej.        d!d%g#          d&             Z2 ej.        d!          d'             Z3 ej.        d!          d(             Z4 ej.        d          d)             Z5 ej.        d          d*             Z6 ej.        d          d+             Z7 ej.        d          d,             Z8 ej.        d          d-             Z9 ej.        d!          d.             Z:d/ Z;d0 Z< ej.        d!d%d1g#          d2             Z= ej.        d!          d3             Z> ej.        d!          d4             Z? ej.        d!          d5             Z@ ej.        d!          d6             ZA ej.        d!          d7             ZB ej.        d!          d8             ZC ej.        d!          d9             ZD ej.        d!          d:             ZE ej.        d!          d;             ZF ej.        d!          d<             ZG ej.        dg d=#          d>             ZHdS )?zOModule with helper functions, fixtures, and common test data for pyogrio tests.    )BytesIO)Path)ZIP_DEFLATEDZipFileN)__gdal_version_string____version__list_drivers)
GDAL_GE_37HAS_ARROW_WRITE_APIHAS_GDAL_GEOSHAS_PYARROW
HAS_PYPROJHAS_SHAPELY)
vsi_rmtree)readwritefixtures
FlatGeobufGeoJSON
GeoJSONSeqGPKGzESRI Shapefile)	.fgb.geojson	.geojsonl	.geojsons.gpkg	.gpkg.zip.shpz.shp.zipz.shzc                     i | ]\  }}||	S  r    ).0extdrivers      f/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/pyogrio/tests/conftest.py
<dictcomp>r%   '   s    ===kc6fc===    )r   r   r   r   r      )r   r   r   r   r   r   Parquetc                     d                     d t          t                                                                D                       }dt           dt
           d| S )Nz, c              3   ,   K   | ]\  }}| d | dV  dS )()Nr    )r!   r#   
capabilitys      r$   	<genexpr>z'pytest_report_header.<locals>.<genexpr>8   sK        FJ !!J!!!     r&   zpyogrio z
GDAL z
Supported drivers: )joinsortedr	   itemsr   r   )configdriverss     r$   pytest_report_headerr4   7   sy    ii  "()=)=)?)?"@"@    G
	(; 	( 	('	( 	(%	( 	(r&   zpyarrow required)reasonzpyproj requiredz&GDAL>=3.8 required for Arrow write APIz GDAL compiled with GEOS requiredzShapely >= 2.0 requiredc                 .   |dk    rt           st          j        d           || j        k    r| S || j         | z  }|                                r|S t          |           \  }}}}|dk    rd|d<   d|d<   n|dv r
d|d<   d	|d<   t          |||fi | |S )
Nr   z&.gpkg.zip support requires GDAL >= 3.7r   Fspatial_indexUnknowngeometry_type)r   r   MultiPolygon)r
   pytestskipsuffixstemexistsr   r   )testfile_pathdst_dirr"   dst_pathmeta_geometry
field_datas           r$   prepare_testfilerG   T   s    
k*<===
m"""M.5555H $($7$7!D!Xz
f}} %_ )_	&	&	& %_ ._	(Hj11D111Or&   session)scopec                      t           S N	_data_dirr    r&   r$   data_dirrN   p   s    r&   functionc                 t    t          |dd          }t          t          d          z  }t          || |          S )Nparamr   +naturalearth_lowres/naturalearth_lowres.shp)getattrrM   r   rG   )tmp_pathrequestr"   r@   s       r$   naturalearth_lowresrV   u   s8    
'7F
+
+C%R S SSMM8S999r&   )rI   paramsc                 .    t          || |j                  S rK   rG   rQ   rT   rV   rU   s      r$   naturalearth_lowres_all_extr[   }       /7=IIIr&   r   c                 .    t          || |j                  S rK   rY   rZ   s      r$   naturalearth_lowres_geojsonr^      r\   r&   c                     | |j          dz  }t          |dt          d          5 }dD ],}|j         d| }|                    |j        |z  |           -	 ddd           n# 1 swxY w Y   |d| d	|j          fS )
z4Wrap naturalearth_lowres as a zip file for VSI testsz.zipw   )modecompressioncompresslevel)dbfprjshpshxcpg.Nz/vsizip//)namer   r   r>   r   parent)rT   rV   pathoutr"   filenames         r$   naturalearth_lowres_vsirq      s    ,17777D	C\	K	K	K Gs6 	G 	GC-2::S::HII)08;XFFFF	GG G G G G G G G G G G G G G G
 =D==#6#;====s   0A##A'*A'c              #      K   t          |           \  }}}}d| j         }t          d| d| d          }d|d<   d|d<   t          |||fd	d
i| |V  t	          |j                   dS )z8Write naturalearth_lowres to a vsimem file for VSI testspyogrio_fixture_z/vsimem/rk   r   Fr7   r:   r9   layerrV   N)r   r>   r   r   r   rm   )rV   rC   rD   rE   rF   rl   rB   s          r$   naturalearth_lowres_vsimemru      s       %))<$=$=!D!Xz81688D1t11d11122H!D*D	(HjNN0ENNNN
NNNxr&   c                      t           dz  S )Nzline_zm.gpkgrL   r    r&   r$   line_zm_filerw      s    ~%%r&   c                      t           dz  S )Nz
curve.gpkgrL   r    r&   r$   
curve_filery      s    |##r&   c                      t           dz  S )Nzcurvepolygon.gpkgrL   r    r&   r$   curve_polygon_filer{          ***r&   c                      t           dz  S )Nzmultisurface.gpkgrL   r    r&   r$   multisurface_filer~      r|   r&   c                      t           dz  S )Nztest_gpkg_nulls.gpkgrL   r    r&   r$   test_gpkg_nullsr      s    ---r&   c           	      d    | dz  }t          |dd t          j        g d          gdg           |S )Nztest_no_geometry.gpkgno_geometry)abccol)rt   rE   rF   fields)r   nparray)rT   rp   s     r$   no_geometry_filer      sO     11H	H___--.w    Or&   c                     d}| dz  }t          |d          5 }|                    |          }d d d            n# 1 swxY w Y   |S )Na	  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": {
                    "int": 1,
                    "list_int": [0, 1],
                    "list_double": [0.0, 1.0],
                    "list_string": ["string1", "string2"],
                    "list_int_with_null": [0, null],
                    "list_string_with_null": ["string1", null]
                },
                "geometry": { "type": "Point", "coordinates": [0, 2] }
            },
            {
                "type": "Feature",
                "properties": {
                    "int": 2,
                    "list_int": [2, 3],
                    "list_double": [2.0, 3.0],
                    "list_string": ["string3", "string4", ""],
                    "list_int_with_null": [2, 3],
                    "list_string_with_null": ["string3", "string4", ""]
                },
                "geometry": { "type": "Point", "coordinates": [1, 2] }
            },
            {
                "type": "Feature",
                "properties": {
                    "int": 3,
                    "list_int": [],
                    "list_double": [],
                    "list_string": [],
                    "list_int_with_null": [],
                    "list_string_with_null": []
                },
                "geometry": { "type": "Point", "coordinates": [2, 2] }
            },
            {
                "type": "Feature",
                "properties": {
                    "int": 4,
                    "list_int": null,
                    "list_double": null,
                    "list_string": null,
                    "list_int_with_null": null,
                    "list_string_with_null": null
                },
                "geometry": { "type": "Point", "coordinates": [2, 2] }
            },
            {
                "type": "Feature",
                "properties": {
                    "int": 5,
                    "list_int": null,
                    "list_double": null,
                    "list_string": [""],
                    "list_int_with_null": null,
                    "list_string_with_null": [""]
                },
                "geometry": { "type": "Point", "coordinates": [2, 2] }
            }
        ]
    }ztest_ogr_types_list.geojsonr`   openr   )rT   list_geojsonrp   frD   s        r$   list_field_values_geojson_filer      s    @	LD 77H	h		 "GGL!!" " " " " " " " " " " " " " " O   :>>c                     t           dz  } |                                 r| S 	 ddl}ddlm} ddl}n(# t
          $ r}t          d|  d| d          d}~ww xY w|                    |                    |	                    t          j        d                              g d	dd
gddgg ddgddgddgg ddgddgg dg ddggddgddgg ddgddgg dg ddggd          }|                    ||            | S )aE  Return the path to a Parquet file with list values in a property.

    Because in the CI environments pyarrow.parquet is typically not available, we save
    the file in the test data directory instead of always creating it from scratch.

    The code to create it is here though, in case it needs to be recreated later.
    zlist_field_values_file.parquetr   Nparquet
test file & does not exist, but error importing: rj   )ra      )r'   r         ra   r'   r   r   g        g      ?g       @g      @string1string2)string3string4 r   )rE   intlist_intlist_doublelist_stringlist_int_with_nulllist_string_with_nullrM   r?   pyarrowr   shapelyImportErrorRuntimeErrortableto_wkbpointsr   oneswrite_table)fixture_pathpapqr   exr   s         r$   list_field_values_parquet_filer     s    ??L 
)))))) 
 
 
RRRRRRR
 
 	


 HHw~~bgfoo'F'FGG"??Q!QT48 #Jc
BdCI&*** %&t9q!fb$"ED!***&	
 	
 E. NN5,'''   1 
AAA.parquetc                 l    |j         dk    rt          |           S |j         dk    rt                      S d S )Nr   r   )rQ   r   r   )rT   rU   s     r$   list_field_values_filesr   K  s>    }
""-h777	*	$	$-/// 
%	$r&   c                     d}| dz  }t          |d          5 }|                    |          }d d d            n# 1 swxY w Y   |S )Na.  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [0, 0]
                },
                "properties": {
                    "int_col": 1,
                    "float_col": 1.5,
                    "str_col": "string",
                    "bool_col": true,
                    "null_col": null,
                    "date_col": "2020-01-01",
                    "time_col": "12:00:00",
                    "datetime_col": "2020-01-01T12:00:00",
                    "list_int_col": [1, 2, 3],
                    "list_str_col": ["a", "b", "c"],
                    "list_mixed_col": [1, "a", null, true]
                }
            }
        ]
    }ztest_many_data_types.geojsonr`   r   )rT   many_types_geojsonrp   r   rD   s        r$   many_data_types_geojson_filer   S  s    	4 88H	h		 (GG&''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( Or   c                     d}| dz  }t          |d          5 }|                    |          }d d d            n# 1 swxY w Y   |S )Na  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [0, 0]
                },
                "properties": {
                    "top_level": "A",
                    "intermediate_level": {
                        "bottom_level": "B"
                    }
                }
            }
        ]
    }ztest_nested.geojsonr`   r   )rT   nested_geojsonrp   r   rD   s        r$   nested_geojson_filer   w  s    	N& //H	h		 $GGN##$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Or   c           	         t           dz  }|                                r|S 	 ddl}ddlm} ddl}n(# t
          $ r}t          d| d| d          d}~ww xY w|                    |                    |	                    t          j        d                              g d	d
ddgdz  d
ddgdz  gdz  g dgdz  d          }|                    ||           |S )aG  Create a Parquet file in tmp_path with nested values in a property.

    Because in the CI environments pyarrow.parquet is typically not available, we save
    the file in the test data directory instead of always creating it from scratch.

    The code to create it is here though, in case it needs to be recreated later.
    zlist_nested_struct_file.parquetr   Nr   r   r   rj   )r   r   )r   r'   r   r'   r   )r   r   r   )r'   r   r   )rE   col_flat
col_struct
col_nestedcol_listr   )rT   r   r   r   r   r   r   s          r$   list_nested_struct_parquet_filer     s>    @@L 
)))))) 
 
 
RRRRRRR
 
 	


 HHw~~bgfoo'F'FGG!		!"++,q0"#!,,-12Q6"a	
 	
 E NN5,'''r   c                     d}| dz  }t          |d          5 }|                    |          }d d d            n# 1 swxY w Y   |S )Na  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": { "col": "2020-01-01T09:00:00.123" },
                "geometry": { "type": "Point", "coordinates": [1, 1] }
            },
            {
                "type": "Feature",
                "properties": { "col": "2020-01-01T10:00:00" },
                "geometry": { "type": "Point", "coordinates": [2, 2] }
            }
        ]
    }ztest_datetime.geojsonr`   r   )rT   datetime_geojsonrp   r   rD   s        r$   datetime_filer     s    	  11H	h		 &GG$%%& & & & & & & & & & & & & & & Or   c                     d}| dz  }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   |S )Na  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": { "datetime_col": "2020-01-01T09:00:00.123-05:00" },
                "geometry": { "type": "Point", "coordinates": [1, 1] }
            },
            {
                "type": "Feature",
                "properties": { "datetime_col": "2020-01-01T10:00:00-05:00" },
                "geometry": { "type": "Point", "coordinates": [2, 2] }
            }
        ]
    }ztest_datetime_tz.geojsonr`   r   rT   datetime_tz_geojsonrp   r   s       r$   datetime_tz_filer     s    	  44H	h		 %	#$$$% % % % % % % % % % % % % % % Or   c                     t          t          t          d          z  d          \  }}}}| dz  }t          |||fi | t	          |d          5 }|                                 }ddd           n# 1 swxY w Y   |S )z\Extracts first 3 records from naturalearth_lowres and writes to GeoJSON,
    returning bytesrR   r   max_featurestest.geojsonrbNr   rM   r   r   r   )rT   rC   rD   rE   rF   rp   r   bytes_buffers           r$   geojson_bytesr     s     %)DFGGGVW% % %!D!Xz .(H	(Hj11D111	h		  vvxx                              s   A11A58A5c                     d}| dz  }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   |S )Na  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": { "datetime_col": "1670-01-01T09:00:00" },
                "geometry": { "type": "Point", "coordinates": [1, 1] }
            }
        ]
    }ztest_datetime_long_ago.geojsonr`   r   r   s       r$   geojson_datetime_long_agor      s    		 ::H	h		 %	#$$$% % % % % % % % % % % % % % % Or   c              #      K   t          t          t          d          z  d          \  }}}}| dz  }t          |||fddi| t	          |d          5 }|V  ddd           dS # 1 swxY w Y   dS )	zgExtracts first 3 records from naturalearth_lowres and writes to GeoJSON,
    returning open file handlerR   r   r   r   rt   testr   Nr   )rT   rC   rD   rE   rF   rp   r   s          r$   geojson_fileliker     s       %)DFGGGVW% % %!D!Xz .(H	(Hj???$???	h		                  s   A&&A*-A*c                     d}| dz  }t          |d          5 }|                    |          }d d d            n# 1 swxY w Y   |S )Na  <?xml version="1.0" encoding="utf-8" ?>
        <kml xmlns="http://www.opengis.net/kml/2.2">
        <Document id="root_doc">
            <Schema name="interfaces1" id="interfaces1">
                <SimpleField name="id" type="float"></SimpleField>
                <SimpleField name="formation" type="string"></SimpleField>
            </Schema>
            <Folder><name>interfaces1</name>
                <Placemark>
                    <ExtendedData><SchemaData schemaUrl="#interfaces1">
                        <SimpleData name="formation">Ton</SimpleData>
                    </SchemaData></ExtendedData>
                    <Point><coordinates>19.1501280458077,293.313485355882</coordinates></Point>
                </Placemark>
            </Folder>
        </Document>
        </kml>
    ztest.kmlr`   r   )rT   kml_datarp   r   rD   s        r$   kml_filer   $  s    H$ *$H	h		 GGH               Or   c                 h     G d dt                     }d} ||                    d                    S )Nc                       e Zd Zd Zd ZdS )-nonseekable_bytes.<locals>.NonSeekableBytesIOc                     dS )NFr    )selfs    r$   seekablez6nonseekable_bytes.<locals>.NonSeekableBytesIO.seekableD  s    5r&   c                      t          d          )Nzcannot seek)OSError)r   argskwargss      r$   seekz2nonseekable_bytes.<locals>.NonSeekableBytesIO.seekG  s    -(((r&   N)__name__
__module____qualname__r   r   r    r&   r$   NonSeekableBytesIOr   C  s2        	 	 		) 	) 	) 	) 	)r&   r   z{
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": { },
                "geometry": { "type": "Point", "coordinates": [1, 1] }
            }
        ]
    }zUTF-8)r   encode)rT   r   geojsons      r$   nonseekable_bytesr   @  sR    ) ) ) ) )W ) ) )		G gnnW55666r&   ))CP932u   ﾎ)CP936u   中文)CP1250u   Đ)CP1252   ÿ)CP1253u   Φ)CP1256u   شc                     | j         S )a'  Return tuple with encoding name and very short sample text in that encoding
    NOTE: it was determined through testing that code pages for MS-DOS do not
    consistently work across all Python installations (in particular, fail with conda),
    but ANSI code pages appear to work properly.
    )rQ   )rU   s    r$   encoded_textr   Y  s    . =r&   )I__doc__ior   pathlibr   zipfiler   r   numpyr   pyogrior   r   r	   pyogrio._compatr
   r   r   r   r   r   pyogrio.corer   pyogrio.rawr   r   r;   __file__rm   resolverM   DRIVERSr1   
DRIVER_EXTALL_EXTS	START_FIDGDAL_HAS_PARQUET_DRIVERr4   markskipifrequires_pyarrow_apirequires_pyprojrequires_arrow_write_apirequires_gdal_geosrequires_shapelyrG   fixturerN   rV   r[   r^   rq   ru   rw   ry   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r&   r$   <module>r     s   U U             ) ) ) ) ) ) ) )     F F F F F F F F F F                $ # # # # # # # # # # # # # DNN!))++j8	  
 
 >=W]]__===
===  	 $||~~5 	 	 	 {))k/BT)UU +$$^<M$NN!;--.;3 .   
 [''@ (    ;%%+o>W%XX   8 i     !  j!!!: : "!: j222J J 32J j*666J J 76J j!!!	> 	> "!	> j!!!    "!  i   & & ! & i   $ $ ! $ i   + + ! + i   + + ! + i   . . ! . j!!!  "!H H HV1 1 1h j*j)ABBB0 0 CB0 j!!!    "! F j!!!  "!8 j!!!# # "!#L j!!!  "!2 j!!!  "!2 j!!!  "!  j!!!  "!( j!!!  "! j!!!  "!6 j!!!7 7 "!70 
    " # "  r&   