U C^X@sbddlmZmZmZddlmZddlmZddlZe dZ GdddeZ Gdd d eZ dS) )print_functiondivisionabsolute_import)BytesIO)AbstractFileSystemNzfsspec.memoryfsc@sleZdZdZiZgZdZdZdddZddZ d d Z d d Z dddZ ddZ ddZddZddZdS)MemoryFileSystemz/A filesystem based on a dict of BytesIO objectsZmemoryFc Cs ||jkr&||j|jddg}ng}|dd}t}|jD]d}|drZdnd}|d}d|kr|ddd}nd}||kr||||j|jddqF|r:t ddt | d|d dDr:d | ddt | dd} | |kr||| ddd d|| qFt d dt | ddg|d dDrF|d ddd} | |krF||| ddd d|| qF|jD]8}||dd|kr||ddd dq|r|Std d |DS) Nfile)namesizetype/rrcss|]\}}||kVqdSN.0abrrA/tmp/pip-install-6_kvzl1k/fsspec/fsspec/implementations/memory.py /sz&MemoryFileSystem.ls.. directorycss|]\}}||kVqdSrrrrrrr=scSsg|] }|dqS)r r)rfrrr Qsz'MemoryFileSystem.ls..)store getbuffernbytesstriplstripset startswithrsplitappendallzipsplitjoinlenaddrstrip pseudo_dirs_parentsorted) selfpathZdetailoutpathsp2Z has_slashprootZppathrrrlssh    &       zMemoryFileSystem.lscCs$|d}||jkr |j|dS)Nr )r)r*r"r-r.rrrmkdirSs  zMemoryFileSystem.mkdircCsJ|d}||jkr>||gkr0|j|qFtd|nt|dS)Nr zDirectory %s not empty)r)r*r4removeOSErrorFileNotFoundErrorr5rrrrmdirXs   zMemoryFileSystem.rmdircCs ||jkSrrr5rrrexistsbszMemoryFileSystem.existsrbNTc Ksp|dkrH||jkr@|j|}|dkr0|dn |dd|St||dkrlt||}|jsh||SdS)N)r=abzrb+r=rwb)rseekr9 MemoryFileZ_intranscommit) r-r.mode block_sizeZ autocommitZ cache_optionskwargsrmrrr_openes      zMemoryFileSystem._opencKs t|||j||j|<dSr)rBrr)r-path1path2rFrrrcopy~szMemoryFileSystem.copycCs|j|Sr)rgetvaluer5rrrcatszMemoryFileSystem.catcCs |j|=dSrr;r5rrr_rmszMemoryFileSystem._rmcCs"||jkrt||j|jS)z!Size in bytes of the file at path)rr9rrr5rrrr s zMemoryFileSystem.size)F)r=NTN)__name__ __module__ __qualname____doc__rr*protocolZ root_markerr4r6r:r<rHrKrMrNr rrrrr s$ A  rc@s:eZdZdZd ddZddZddZd d Zd d ZdS)rBzA BytesIO which can't close and works as a context manager Can initialise with data No need to provide fs, path if auto-committing (default) NcCs2||_||_|r.||t||_|ddS)Nr)fsr.writer'r rA)r-rTr.datarrr__init__s   zMemoryFile.__init__cCs|Srrr-rrr __enter__szMemoryFile.__enter__cCs|dd|_dS)Nrr?)rAr rXrrrcloseszMemoryFile.closecCsdSrrrXrrrdiscardszMemoryFile.discardcCs||jj|j<dSr)rTrr.rXrrrrCszMemoryFile.commit)N) rOrPrQrRrWrYrZr[rCrrrrrBs  rB) __future__rrriorZfsspecrloggingLoggerloggerrrBrrrrs