/usr/local/lib/python3.6/site-packages/fsspec/__pycache__
NameSizeModeActions
archive.cpython-36.pyc26790644editdlrm
asyn.cpython-36.pyc232500644editdlrm
caching.cpython-36.pyc133250644editdlrm
callbacks.cpython-36.pyc59270644editdlrm
compression.cpython-36.pyc46450644editdlrm
config.cpython-36.pyc27400644editdlrm
conftest.cpython-36.pyc13610644editdlrm
core.cpython-36.pyc202340644editdlrm
dircache.cpython-36.pyc32920644editdlrm
exceptions.cpython-36.pyc7330644editdlrm
fuse.cpython-36.pyc101100644editdlrm
gui.cpython-36.pyc142140644editdlrm
mapping.cpython-36.pyc82080644editdlrm
parquet.cpython-36.pyc111810644editdlrm
registry.cpython-36.pyc76210644editdlrm
spec.cpython-36.pyc522480644editdlrm
transaction.cpython-36.pyc31780644editdlrm
utils.cpython-36.pyc144030644editdlrm
_version.cpython-36.pyc4640644editdlrm
__init__.cpython-36.pyc13940644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/fsspec/__pycache__/utils.cpython-36.pyc (14403B)
3 8%EgA@s&ddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z d7Zejd8kZd9d d Zd:d dZiZddZddZddZd;ddZddZddZddZddZdd4d5Z%dS)?N)contextmanager)partial)md5)urlsplitcCsZtjd|stjd|dkr&d|dSt|}|jp6d}|jrRdj|j|jg}n|j}|dkr|tjd|}|r|d|j}|dkr||dS||d}|jr"|jj d d dj d d d|d<|dkr|d|d|d<n |d|d<|j r|j |d<|j r|j |d<|j r"|j |d<|j r4|j |d<|jrF|j|d<|rVt|||S)aInfer storage options from URL path and merge it with existing storage options. Parameters ---------- urlpath: str or unicode Either local absolute file path or URL (hdfs://namenode:8020/file.csv) inherit_storage_options: dict (optional) Its contents will get merged with the inferred information from the given path Returns ------- Storage options dict. Examples -------- >>> infer_storage_options('/mnt/datasets/test.csv') # doctest: +SKIP {"protocol": "file", "path", "/mnt/datasets/test.csv"} >>> infer_storage_options( ... 'hdfs://username:pwd@node:123/mnt/datasets/test.csv?q=1', ... inherit_storage_options={'extra': 'value'}, ... ) # doctest: +SKIP {"protocol": "hdfs", "username": "username", "password": "pwd", "host": "node", "port": 123, "path": "/mnt/datasets/test.csv", "url_query": "q=1", "extra": "value"} z^[a-zA-Z]:[\\/]z^[a-zA-Z0-9]+://Nfile)protocolpath#z^/([a-zA-Z])[:|]([\\/].*)$z%s:%shttphttps@:rhosts3s3agcsgsr portusernamepasswordZ url_queryZ url_fragment)rr)rrrr)rematchrschemefragmentjoinr groupsnetlocrsplitrrrqueryupdate_storage_options)ZurlpathZinherit_storage_optionsZ parsed_pathr r Z windows_pathoptionsr(6/usr/local/lib/python3.6/site-packages/fsspec/utils.pyinfer_storage_optionssB       "       r*cCsX|si}t|t|@}|rJx,|D]$}|j||j|kr"td|q"W|j|dS)Nz;Collision between inferred and specified storage option: %s)setgetKeyErrorupdate)r'Z inheritedZ collisionsZ collisionr(r(r)r&bs  r&cCs.tjj|djdj}|tkr*t|SdS)aInfer compression, if available, from filename. Infer a named compression type, if registered and available, from filename extension. This includes builtin (gz, bz2, zip) compressions, as well as optional compressions. See fsspec.compression.register_compression. r.Nr)osr splitextstriplower compressions)filename extensionr(r(r)infer_compressiontsr7cs,|d7}ttjtj|fdd}|S)aReturns a function that receives a single integer and returns it as a string padded by enough zero characters to align with maximum possible integer >>> name_f = build_name_function(57) >>> name_f(7) '07' >>> name_f(31) '31' >>> build_name_function(1000)(42) '0042' >>> build_name_function(999)(42) '042' >>> build_name_function(0)(0) '0' g:0yE>cst|jS)N)strzfill)i) pad_lengthr(r) name_functionsz*build_name_function..name_function)intmathceillog10)Zmax_intr<r()r;r)build_name_functions rAc Cs|jdkrdSd}x|j|}|s(dS|r4||n|}yL||krr|j|}|j|jt||t|dSt||krdSWnttfk rYnX|t| d}qWdS)aSeek current file to file start, file end, or byte after delimiter seq. Seeks file to next chunk delimiter, where chunks are defined on file start, a delimiting sequence, and file end. Use file.tell() to see location afterwards. Note that file start is a valid split, so must be at offset > 0 to seek for delimiter. Parameters ---------- file: a file delimiter: bytes a delimiter like ``b'\n'`` or message sentinel, matching file .read() type blocksize: int Number of bytes to read from the file at once. Returns ------- Returns True if a delimiter was found, False if at file start or end. rFNT)tellreadindexseeklenOSError ValueError)r delimiter blocksizelastcurrentfullr:r(r(r)seek_delimiters$   " rNFc Cs|r|j|t||d}|dkr*|jS|j}|||8}|j||t||d}|j}|rt|rt|t|8}|r|r|t|8}|}||}|j||j|} | S)aRead a block of bytes from a file Parameters ---------- f: File Open file offset: int Byte offset to start read length: int Number of bytes to read, read through end of file if None delimiter: bytes (optional) Ensure reading starts and stops at delimiter bytestring split_before: bool (optional) Start/stop read *before* delimiter bytestring. If using the ``delimiter=`` keyword argument we ensure that the read starts and stops at delimiter boundaries that follow the locations ``offset`` and ``offset + length``. If ``offset`` is zero then we start at zero, regardless of delimiter. The bytestring returned WILL include the terminating delimiter string. Examples -------- >>> from io import BytesIO # doctest: +SKIP >>> f = BytesIO(b'Alice, 100\nBob, 200\nCharlie, 300') # doctest: +SKIP >>> read_block(f, 0, 13) # doctest: +SKIP b'Alice, 100\nBo' >>> read_block(f, 0, 13, delimiter=b'\n') # doctest: +SKIP b'Alice, 100\nBob, 200\n' >>> read_block(f, 10, 10, delimiter=b'\n') # doctest: +SKIP b'Bob, 200\nCharlie, 300' rNii)rErNrCrBrF) foffsetlengthrIZ split_beforeZfound_start_delimstartZfound_end_delimendbr(r(r) read_blocks&%        rVc OsP|r||f7}ytt|jjStk rJtt|jddjSXdS)zDeterministic token (modified from dask.base) >>> tokenize([1, 2, '3']) '9d71491b50023b06fc76928e6eddb952' >>> tokenize('Hello') == tokenize('Hello') True F)usedforsecurityN)rr8encode hexdigestrH)argskwargsr(r(r)tokenizes  r\cCsLt|tr|St|dr |jSt|tjr4t|St|drD|jS|SdS)aDAttempt to convert a path-like object to a string. Parameters ---------- filepath: object to be converted Returns ------- filepath_str: maybe a string version of the object Notes ----- Objects supporting the fspath protocol (Python 3.6+) are coerced according to its __fspath__ method. For backwards compatibility with older Python version, pathlib.Path objects are specially coerced. Any other object is passed through unchanged, which includes bytes, strings, buffers, or anything else that's not even path-like. __fspath__r N) isinstancer8hasattrr]pathlibPathr )filepathr(r(r)stringify_path#s    rccCs|||}|j|S)N)Z_determine_worker)clsrZr[instr(r(r) make_instanceEs rfcsrdd|DtddD}d}x.t|D]"tfddD}|s.Pq.W|7djddS) z;For a list of paths, find the shortest prefix common to allcSsg|]}|jdqS)/)split).0pr(r(r) Msz!common_prefix..css|]}t|VqdS)N)rF)rirjr(r(r) Nsz common_prefix..rc3s"|]}|dkVqdS)rNr()rirj)r:partsr(r)rlQsrgN)minrangeallr!)pathsZlmaxrTr()r:rmr) common_prefixKsrrcsttr|pjd}jdt|dkr`t||rJjdddfdd|Dq|rjdd|djddgqgnt|tkstS)aIn bulk file operations, construct a new file tree from a list of files Parameters ---------- paths: list of str The input file tree path2: str or list of str Root to construct the new list in. If this is already a list of str, we just assert it has the right number of elements. is_dir: bool (optional) For the special case where the input in one element, whether to regard the value as the target path, or as a directory to put a file path within. If None, a directory is inferred if the path ends in '/' exists: bool (optional) For a str destination, it is already exists (and is a dir), files should end up inside. Returns ------- list of str rgrrcsg|]}|jdqS)r)replace)rirj)cppath2r(r)rkuszother_paths..r)r^r8endswithrstriprFrrr$AssertionError)rqruis_direxistsr()rtrur) other_pathsXs   $r{cCs t|tS)N)r^ BaseException)objr(r(r) is_exceptionsr~cCs&tjd|d}t|dkr"|dSdS)Nz (\:\:|\://)rrr )rrhrF)urlrmr(r(r) get_protocols rc Cs>ddlm}yt|t|ddSttfk r8dSXdS)z*Can the given URL be used with open_local?r)get_filesystem_class local_fileFN)ZfsspecrgetattrrrH ImportError)r rr(r(r) can_be_locals  rcCs|tjkr$tj|}t|dr$|jStjdkrTyddl}|jj|jSYqvXn"yddl }|j|jSYnXyddl }|j |}|jSt t fk rdSXdS)aFor given package name, try to find the version without importing it Import and package.__version__ is still the backup here, so an import *might* happen. Returns either the version string, or None if the package or the version was not readily found. __version__r rN)r r)sysmodulesr_r version_infoZimportlib.metadatametadata distributionversionimportlib_metadata importlib import_modulerAttributeError)namemodrrr(r(r)"get_package_version_without_imports*      rDEBUGTcCsh|dkr|dkrtd|p$tj|}tj}tjd}|j||rP|jj|j||j ||S)Nz+Provide either logger object or logger namezD%(asctime)s - %(name)s - %(levelname)s - %(funcName)s -- %(message)s) rHlogging getLogger StreamHandler Formatter setFormatterhandlersclear addHandlersetLevel)loggerZ logger_namelevelrhandle formatterr(r(r) setup_loggings    rcCsTt|jtr*|j|jr|S|jd|S|jt|jr>|S|jdd|SdS)Nz://r)r^r r8 startswithtuple)rfsr(r(r)_unstrip_protocols  rcsfddfdd}|S)zqMirror attributes and methods from the given origin_name attribute of the instance to the decorated classcst|}t||S)N)r)methodselforigin) origin_namer(r) origin_getters z"mirror_from..origin_gettercs,x&D]}t|}t||t|qW|S)N)rsetattrproperty)rdrZwrapped_method)methodsrr(r)wrappers  zmirror_from..wrapperr()rrrr()rrrr) mirror_froms rccs |VdS)Nr()r}r(r(r) nullcontextsrc Cszt|tstt|ts&|gt|}t|ts>|gt|}t|t|ks^t|t|krbtt|dkrx|||fS|rddttt|||D\}}}|rp|dd}|dd}|dd}xtdt|D]} || || dks*|| |d|ks*|dk rV|| |d|krV|j|| |j|| |j|| q|| |d<qW|||fS|||fS)a}Merge adjacent byte-offset ranges when the inter-range gap is <= `max_gap`, and when the merged byte range does not exceed `max_block` (if specified). By default, this function will re-order the input paths and byte ranges to ensure sorted order. If the user can guarantee that the inputs are already sorted, passing `sort=False` will skip the re-ordering. rcSsg|] }t|qSr()list)rivr(r(r)rksz'merge_offset_ranges..Nrrr) r^r TypeErrorrFrHzipsortedroappend) rqZstartsZendsZmax_gapZ max_blocksortZ new_pathsZ new_startsZnew_endsr:r(r(r)merge_offset_rangess4      $     riiP)r r )N)N)NF)NF)NNrT)rNT)&rr>r0r`rr contextlibr functoolsrhashlibr urllib.parserZDEFAULT_BLOCK_SIZErZPY36r*r&r4r7rArNrVr\rcrfrrr{r~rrrrrrrrr(r(r(r)s@      R  1 A" ( $