
    DhT                         S r SSKrSSKJrJrJr  SSKJr  SSKJ	r	  SSK
Jr  \R                  " \5      r " S S\5      r " S	 S
\5      rg)z3Classes capable of reading and writing collections
    N)MemoryFileBase_listdir_listlayers)
Collection)supports_vsi)DriverErrorc                   n   ^  \ rS rSrSrS
U 4S jjr          SS jrSS jrSS jrS r	S r
S	rU =r$ )
MemoryFile   ao  A BytesIO-like object, backed by an in-memory file.

This allows formatted files to be read and written without I/O.

A MemoryFile created with initial bytes becomes immutable. A
MemoryFile created without initial bytes may be written to using
either file-like or dataset interfaces.

Parameters
----------
file_or_bytes : an open Python file, bytes, or None
    If not None, the MemoryFile becomes immutable and read-only.
    If None, it is write-only.
filename : str
    An optional filename. The default is a UUID-based name.
ext : str
    An optional file extension. Some format drivers require a
    specific value.

c                 f   > U(       a  UR                  S5      (       d  SU-   n[        TU ]	  XUS9  g )N.)file_or_bytesfilenameext)
startswithsuper__init__selfr   r   r   	__class__s       [C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\fiona/io.pyr   MemoryFile.__init__#   s5    s~~c**)C' 	 	E    c                    U R                   (       a  [        S5      eU
(       d"  Ub  [        U5      (       d  [        SU S35      eUS;   a   U R	                  5       (       d  [        S5      eUc&  US:X  a   U R	                  5       (       a  [        S5      eU R	                  5       (       a  US:X  a  Ub  U R                  U5        SnOUc  Sn[        U R                  U4UUUUUUU
U	S	.UD6$ )
a  Open the file and return a Fiona collection object.

If data has already been written, the file is opened in 'r'
mode. Otherwise, the file is opened in 'w' mode.

Parameters
----------
Note well that there is no `path` parameter: a `MemoryFile`
contains a single dataset and there is no need to specify a
path.

Other parameters are optional and have the same semantics as the
parameters of `fiona.open()`.
I/O operation on closed file.zDriver z  does not support virtual files.)razMemoryFile does not exist.wzMemoryFile already exists.r   )crsdriverschemaencodinglayerenabled_driversallow_unsupported_driverscrs_wkt)closedOSErrorr   r   exists_ensure_extensionr   name)r   moder    r!   r   r"   r#   vfsr$   r&   r%   kwargss               r   openMemoryFile.open)   s    8 ;;9:: *" ((x/OPQQ:dkkmm677=TS[T[[]]677{{}}!&&v.D\DII
 +&?
 
 	
r   c                     U R                   (       a  [        S5      eU(       a!  U R                   SUR                  S5       3nOU R                   n[	        U5      $ )zList files in a directory.

Parameters
----------
path : URI (str or pathlib.Path)
    A dataset resource identifier.

Returns
-------
list
    A list of filename strings.

r   /)r'   r(   r+   lstripr   r   pathvsi_paths      r   listdirMemoryFile.listdiri   sN     ;;9::))Adkk#&6%78H))H!!r   c                     U R                   (       a  [        S5      eU(       a!  U R                   SUR                  S5       3nOU R                   n[	        U5      $ )zList layer names in their index order

Parameters
----------
path : URI (str or pathlib.Path)
    A dataset resource identifier.

Returns
-------
list
    A list of layer name strings.

r   r2   )r'   r(   r+   r3   r   r4   s      r   
listlayersMemoryFile.listlayers   sN     ;;9::))Adkk#&6%78H))H8$$r   c                     U $ N )r   s    r   	__enter__MemoryFile.__enter__   s    r   c                 $    U R                  5         g r=   )close)r   argsr.   s      r   __exit__MemoryFile.__exit__   s    

r   r>   )NN )
NNNNNNNNNFr=   )__name__
__module____qualname____firstlineno____doc__r   r/   r7   r:   r?   rD   __static_attributes____classcell__r   s   @r   r
   r
      sM    (E "'>
@",%, r   r
   c                   F   ^  \ rS rSrSrSU 4S jjr      SS jrSrU =r$ )ZipMemoryFile   a  A read-only BytesIO-like object backed by an in-memory zip file.

This allows a zip file containing formatted files to be read
without I/O.

Parameters
----------
file_or_bytes : an open Python file, bytes, or None
    If not None, the MemoryFile becomes immutable and read-only. If
    None, it is write-only.
filename : str
    An optional filename. The default is a UUID-based name.
ext : str
    An optional file extension. Some format drivers require a
    specific value. The default is ".zip".
c                 J   > [         TU ]  XUS9  SU R                   3U l        g )N)r   r   /vsizip)r   r   r+   r   s       r   r   ZipMemoryFile.__init__   s'    sCdii[)	r   c           	      :   U(       a"  SU R                    SUR                  S5       3nOSU R                    3nU R                  (       a  [        S5      eU(       a!  U R                    SUR                  S5       3nOU R                    n[	        US4UUUUUS.UD6$ )zOpen a dataset within the zipped stream.

Parameters
----------
path : str
    Path to a dataset in the zip file, relative to the root of the
    archive.

Returns
-------
A Fiona collection object

rS   r2   r   r   )r    r"   r#   r$   r%   )r+   r3   r'   r(   r   )	r   r5   r    r"   r#   r$   r%   r.   r6   s	            r   r/   ZipMemoryFile.open   s    .  1T[[-=,>?H ,H;;9::))Adkk#&6%78H))H	
 +&?	
 	
 		
r   )r+   )NNz.zip)NNNNNF)	rG   rH   rI   rJ   rK   r   r/   rL   rM   rN   s   @r   rP   rP      s+    "* "',
 ,
r   rP   )rK   loggingfiona.ogrextr   r   r   fiona.collectionr   
fiona.metar   fiona.errorsr   	getLoggerrG   logr
   rP   r>   r   r   <module>r^      sK     > > ' # $!K K\B
J B
r   