/usr/local/lib/python3.6/site-packages/fsspec/implementations/__pycache__
NameSizeModeActions
arrow.cpython-36.pyc73280644editdlrm
cached.cpython-36.pyc230300644editdlrm
dask.cpython-36.pyc46560644editdlrm
dbfs.cpython-36.pyc133510644editdlrm
dvc.cpython-36.pyc26220644editdlrm
ftp.cpython-36.pyc104440644editdlrm
git.cpython-36.pyc37500644editdlrm
github.cpython-36.pyc74040644editdlrm
hdfs.cpython-36.pyc70930644editdlrm
http.cpython-36.pyc207520644editdlrm
jupyter.cpython-36.pyc41310644editdlrm
libarchive.cpython-36.pyc60050644editdlrm
local.cpython-36.pyc119120644editdlrm
memory.cpython-36.pyc66970644editdlrm
reference.cpython-36.pyc161420644editdlrm
sftp.cpython-36.pyc61040644editdlrm
smb.cpython-36.pyc105910644editdlrm
tar.cpython-36.pyc45020644editdlrm
webhdfs.cpython-36.pyc147120644editdlrm
zip.cpython-36.pyc32760644editdlrm
__init__.cpython-36.pyc1560644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/fsspec/implementations/__pycache__/dbfs.cpython-36.pyc (13351B)
3 8%Eg:9@sdddlZddlZddlZddlmZddlmZGdddeZGdddeZ Gdd d eZ dS) N)AbstractFileSystem)AbstractBufferedFilecs eZdZdZfddZZS)DatabricksExceptionz< Helper class for exceptions raised in this module. cstj|||_||_dS)z Create a new DatabricksExceptionN)super__init__ error_codemessage)selfrr) __class__E/usr/local/lib/python3.6/site-packages/fsspec/implementations/dbfs.pyrs zDatabricksException.__init__)__name__ __module__ __qualname____doc__r __classcell__r r )r r r srcseZdZdZfddZd!ddZd"ddZd#d d Zd$d d Zd%ddZ d&ddZ ddZ d'ddZ ddZ ddZddZd(fdd ZZS))DatabricksFileSystemz Get access to the Databricks filesystem implementation over HTTP. Can be used inside and outside of a databricks cluster. c sB||_||_tj|_|jjjdd|jitjf|dS)a Create a new DatabricksFileSystem. Parameters ---------- instance: str The instance URL of the databricks cluster. For example for an Azure databricks cluster, this has the form adb-..azuredatabricks.net. token: str Your personal token. Find out more here: https://docs.databricks.com/dev-tools/api/latest/authentication.html AuthorizationzBearer N) instancetokenrequestsSessionsessionheadersupdaterr)r rrkwargs)r r r rs  zDatabricksFileSystem.__init__TcCs|j|}|sy|jddd|id}Wn:tk r`}z|jdkrLt|j|WYdd}~XnX|d}dd |D}||j|<|r|Sd d |DS) a" List the contents of the given path. Parameters ---------- path: str Absolute path detail: bool Return not only the list of filenames, but also additional information on file sizes and types. getlistpath)methodendpointjsonRESOURCE_DOES_NOT_EXISTNfilescSs,g|]$}|d|drdnd|ddqS)ris_dir directoryfile file_size)nametypesizer ).0or r r Msz+DatabricksFileSystem.ls..cSsg|] }|dqS)r(r )r+r,r r r r-Xs)Z_ls_from_cache _send_to_apirrFileNotFoundErrorrdircache)r rZdetailoutrer#r r r ls3s    zDatabricksFileSystem.lscCs|sZy(|jddd|idtd|dWn,tk rX}z|jdkrHWYdd}~XnXy|jd d d|idWn:tk r}z|jd krt|j|WYdd}~XnX|j|j|dS) aE Create a given absolute path and all of its parents. Parameters ---------- path: str Absolute path to create exist_ok: bool If false, checks if the folder exists before creating it (and raises an Exception if this is the case) rz get-statusr)rr r!zPath z already existsr"NpostmkdirsRESOURCE_ALREADY_EXISTS)r.FileExistsErrorrrrinvalidate_cache_parent)r rexist_okr3r r r makedirsZs    zDatabricksFileSystem.makedirscKs|st|j|f|dS)a! Create a given absolute path and all of its parents. Parameters ---------- path: str Absolute path to create create_parents: bool Whether to create all parents or not. "False" is not implemented so far. N)NotImplementedErrorr6)r rZcreate_parentsrr r r mkdir{s zDatabricksFileSystem.mkdirFcCsy|jdd||ddWnTtk rn}z8|jdkrF|j||dn|jdkrZt|j|WYdd}~XnX|j|j|dS)z Remove the file or folder at the given absolute path. Parameters ---------- path: str Absolute path what to remove recursive: bool Recursively delete all files in a folder. r5delete)r recursive)rr r!ZPARTIAL_DELETEZIO_ERRORN)r.rrrmOSErrorrr9r:)r rr@r3r r r rAs    zDatabricksFileSystem.rmNcCs|rt|rty|jdd||ddWnPtk rz}z4|jdkrRt|jn|jdkrft|j|WYdd}~XnX|j|j||j|j|dS)a Move a source to a destination path. A note from the original [databricks API manual] (https://docs.databricks.com/dev-tools/api/latest/dbfs.html#move). When moving a large number of files the API call will time out after approximately 60s, potentially resulting in partially moved data. Therefore, for operations that move more than 10k files, we strongly discourage using the DBFS REST API. Parameters ---------- source_path: str From where to move (absolute path) destination_path: str To where to move (absolute path) recursive: bool Not implemented to far. maxdepth: Not implemented to far. r5move) source_pathdestination_path)rr r!r"r7N) r=r.rrr/rr8r9r:)r rDrEr@Zmaxdepthr3r r r mvs"    zDatabricksFileSystem.mvrbdefaultcKst||f||d|S)z Overwrite the base class method to make sure to create a DBFile. All arguments are copied from the base method. Only the default blocksize is allowed. )mode block_size)DatabricksFile)r rrIrJrr r r _openszDatabricksFileSystem._openc Cs|dkr|jj}n |dkr$|jj}ntd|tjjd|jd|}|||d}y |jWnVt j k r}z8y|j j }Wnt k r|YnXtf|WYdd}~XnX|j S)a Send the given json to the DBFS API using a get or post request (specified by the argument `method`). Parameters ---------- method: str Which http method to use for communication; "get" or "post". endpoint: str Where to send the request to (last part of the API URL) json: dict Dictionary of information to send r5rzDo not understand method zhttps://z/api/2.0/dbfs/)r!N)rr5r ValueErrorurllibparseurljoinrraise_for_statusr HTTPErrorresponser! Exceptionr) r rr r!Z session_callurlr2r3Zexception_jsonr r r r.s      z!DatabricksFileSystem._send_to_apicCs^y|jdd||dd}|dStk rX}z|jdkrDt|j|WYdd}~XnXdS)a{ Internal function to create a handle, which can be used to write blocks of a file to DBFS. A handle has a unique identifier which needs to be passed whenever written during this transaction. The handle is active for 10 minutes - after that a new write transaction needs to be created. Make sure to close the handle after you are finished. Parameters ---------- path: str Absolute path for this file. overwrite: bool If a file already exist at this location, either overwrite it or raise an exception. r5create)r overwrite)rr r!handler7N)r.rrr8r)r rrWr2r3r r r _create_handles  z#DatabricksFileSystem._create_handlecCsXy|jddd|idWn:tk rR}z|jdkr>t|j|WYdd}~XnXdS)z Close a handle, which was opened by :func:`_create_handle`. Parameters ---------- handle: str Which handle to close. r5closerX)rr r!r"N)r.rrr/r)r rXr3r r r _close_handle&s   z"DatabricksFileSystem._close_handlecCs~tj|j}y|jdd||ddWnPtk rx}z4|jdkrPt|jn|jdkrdt|j|WYdd}~XnXdS)a Upload data to an already opened file handle (opened by :func:`_create_handle`). The maximal allowed data size is 1MB after conversion to base64. Remember to close the handle when you are finished. Parameters ---------- handle: str Which handle to upload data to. data: bytes Block of data to add to the handle. r5z add-block)rXdata)rr r!r"ZMAX_BLOCK_SIZE_EXCEEDEDN) base64 b64encodedecoder.rrr/rrM)r rXr\r3r r r _add_data7s    zDatabricksFileSystem._add_datacCsy*|jdd||||dd}tj|dStk rz}z4|jdkrRt|jn|jd krft|j|WYd d }~XnXd S) a Download data in bytes from a given absolute path in a block from [start, start+length]. The maximum number of allowed bytes to read is 1MB. Parameters ---------- path: str Absolute path to download data from start: int Start position of the block end: int End position of the block rread)roffsetlength)rr r!r\r"INVALID_PARAMETER_VALUEMAX_READ_SIZE_EXCEEDEDN)rdre)r.r] b64decoderrr/rrM)r rstartendr2r3r r r _get_dataUs    zDatabricksFileSystem._get_datacs2|dkr|jjn|jj|dtj|dS)N)r0clearpoprr9)r r)r r r r9ss z%DatabricksFileSystem.invalidate_cache)T)T)T)F)FN)rGrH)T)N)r rrrrr4r<r>rArFrLr.rYr[r`rir9rr r )r r rs  ' !   , ) rcsHeZdZdZdZdfd d Zd d ZdddZddZddZ Z S)rKzH Helper class for files referenced in the DatabricksFileSystem. rGrHT readaheadNc  sX|dks|dkr|j}||jks.td|tj||f|||||pHid|dS)zr Create a new instance of the DatabricksFile. The blocksize needs to be the default one. NrHz,Only the default block size is allowed, not )rIrJ autocommit cache_type cache_options)DEFAULT_BLOCK_SIZEAssertionErrorrr) r fsrrIrJrprqrrr)r r r rs   zDatabricksFile.__init__cCs|jj|j|_dS)z(Internal function to start a file uploadN)rurYrrX)r r r r _initiate_uploadszDatabricksFile._initiate_uploadFcsn|jjd|jjfdd|jtD}x|D]}|jj|j|dq8W|rj|jj|jddSdS)z.)rXr\)rXTN) bufferseekgetvalue_to_sized_blockslenrur`rXr[)r finalZ data_chunks data_chunkr )r\r _upload_chunks   zDatabricksFile._upload_chunkcCs@d}||}x.|j|D] \}}||jj|j||d7}qW|S)z-Internal function to download a block of data)rrgrh)rzrurir)r rgrhZ return_buffer total_lengthZ chunk_startZ chunk_endr r r _fetch_ranges zDatabricksFile._fetch_rangeccs:x4td||jD]"}|}t|||j}||fVqWdS)zFHelper function to split a range from 0 to total_length into bloksizesrN)range blocksizemin)r rr}Z data_startZdata_endr r r rzszDatabricksFile._to_sized_blocksii)rGrHTroN)F) r rrrrsrrvr~rrzrr r )r r rK{s  rK) r]rNrZfsspecrZ fsspec.specrrTrrrKr r r r s   f