/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__/webhdfs.cpython-36.pyc (14712B)
3 8%Eg:@sddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl Z ddl m Z m Z ddlmZejdZGdd d e ZGd d d e ZdS) N)suppress)quote)AbstractBufferedFileAbstractFileSystem)infer_storage_optionswebhdfscs eZdZdZeejZdd dZ d?ddZ e ddZeddZe ddZddZd@ddZddZddZd d!ZdAd"d#Zd$d%Zd&d'Zd(d)ZdBd*d+Zd,d-Zd.d/ZdCd0d1Zd2d3ZdDd4d5Z d6d7Z!d8d9Z"d:d;Z#Z$S)EWebHDFSa| Interface to HDFS over HTTP using the WebHDFS API. Supports also HttpFS gateways. Three auth mechanisms are supported: insecure: no auth is done, and the user is assumed to be whoever they say they are (parameter `user`), or a predefined value such as "dr.who" if not given spnego: when kerberos authentication is enabled, auth is negotiated by requests_kerberos https://github.com/requests/requests-kerberos . This establishes a session based on existing kinit login and/or specified principal/password; parameters are passed with ``kerb_kwargs`` token: uses an existing Hadoop delegation token from another secured service. Indeed, this client can also generate such tokens when not insecure. Note that tokens expire, but can be renewed (by a previously specified user) and may allow for proxying. rwebHDFSFNc  s|jr dStjf| dj| r$dnd||d|_||_|p>i|_i|_|pNi|_|dk r||dk sj|dk rrt d||jd<|dk r||jd<|dk r||jd <|r|dk rt d |j dS) a Parameters ---------- host: str Name-node address port: int Port for webHDFS kerberos: bool Whether to authenticate with kerberos for this connection token: str or None If given, use this token on every call to authenticate. A user and user-proxy may be encoded in the token and should not be also given user: str or None If given, assert the user name to connect with proxy_to: str or None If given, the user has the authority to proxy, and this value is the user in who's name actions are taken kerb_kwargs: dict Any extra arguments for HTTPKerberosAuth, see ``_ data_proxy: dict, callable or None If given, map data-node addresses. This can be necessary if the HDFS cluster is behind a proxy, running on Docker or otherwise has a mismatch between the host-names given by the name-node and the address by which to refer to them from the client. If a dict, maps host names `host->data_proxy[host]`; if a callable, full URLs are passed, and function must conform to `url->data_proxy(url)`. use_https: bool Whether to connect to the Name-node using HTTPS instead of HTTP kwargs Nz%{protocol}://{host}:{port}/webhdfs/v1httpshttp)protocolhostportz_If passing a delegation token, must not set user or proxy_to, as these are encoded in the tokenZ delegationz user.nameZdoaszJIf using Kerberos auth, do not specify the user, this is handled by kinit.) _cachedsuper__init__formaturlkerb kerb_kwargsparsproxy ValueError_connect) selfrrZkerberostokenuserZproxy_torZ data_proxyZ use_httpskwargs) __class__H/usr/local/lib/python3.6/site-packages/fsspec/implementations/webhdfs.pyr+s,.      zWebHDFS.__init__cCs0tj|_|jr,ddlm}|f|j|j_dS)Nr)HTTPKerberosAuth)requestsSessionsessionrZrequests_kerberosr#rauth)rr#r!r!r"rvs  zWebHDFS._connectgetTc Ks|jt|p d}|j}|j|j|j|d<tjd|||jj |j||||d} | j dkry$| j } | d d } | d d } Wnt t fk rYn@X| dkrt | n,| dkrt| n| dkrt| nt| | j| S)Nopzsending %s with %s)methodrparamsdataallow_redirectsZRemoteExceptionmessage exceptionIllegalArgumentExceptionUnsupportedOperationExceptionSecurityExceptionAccessControlExceptionFileNotFoundException)r/r0r1r2r3)r6r7)r8r9)r:)rrcopyupdaterupperloggerdebugr&request status_codejsonrKeyErrorPermissionErrorFileNotFoundError RuntimeErrorraise_for_status) rr*r+pathr-redirectrrargsouterrmsgexpr!r!r"_call}s6       z WebHDFS._callrbc Ks$|p|j}t|||||j|||dS)a^ Parameters ---------- path: str File location mode: str 'rb', 'wb', etc. block_size: int Client buffer size for read-ahead or write buffer autocommit: bool If False, writes to temporary file that only gets put in final location upon commit replication: int Number of copies of file on the cluster, write mode only permissions: str or int posix permissions, write mode only kwargs Returns ------- WebHDFile instance )mode block_sizetempdir autocommit replication permissions) blocksize WebHDFilerS)rrHrQrRrTrUrVrr!r!r"_opens! z WebHDFS._opencCs |dj|d<|d|d<|S)Ntypelengthsize)lower)infor!r!r" _process_infos zWebHDFS._process_infocCs t|dS)NrH)r)clsrHr!r!r"_strip_protocolszWebHDFS._strip_protocolcCs:t|}|jdd|jddd|kr6|jd|d<|S)NrHrusernamer)rpop)ZurlpathrKr!r!r"_get_kwargs_from_urlss   zWebHDFS._get_kwargs_from_urlscCs,|jd|d}|jd}||d<|j|S)NZ GETFILESTATUS)rH FileStatusname)rOrBr_)rrHrKr^r!r!r"r^s z WebHDFS.infocCsz|jd|d}|jdd}x0|D](}|j||jdd|d|d<q$W|rdt|dd d Std d |DSdS) NZ LISTSTATUS)rHZ FileStatusesre/Z pathSuffixrfcSs|dS)Nrfr!)ir!r!r"szWebHDFS.ls..)keycss|]}|dVqdS)rfNr!).0r^r!r!r" szWebHDFS.ls..)rOrBr_rstripsorted)rrHZdetailrKinfosr^r!r!r"lss  z WebHDFS.lscCs|jd|d}|jdS)z8Total numbers of files, directories and bytes under pathZGETCONTENTSUMMARY)rHZContentSummary)rOrB)rrHrKr!r!r"content_summaryszWebHDFS.content_summarycCsb|jd|dd}d|jkrJ|j|jd}|jj|}|j|jdS|j|jdSdS)z/Checksum info of file, giving method and resultZGETFILECHECKSUMF)rHrILocationZ FileChecksumN)rOheaders _apply_proxyr&r(rGrB)rrHrKlocationout2r!r!r"ukeys   z WebHDFS.ukeycCs|jd}|jdS)zGet user's home directoryZGETHOMEDIRECTORYPath)rOrB)rrKr!r!r"home_directorys zWebHDFS.home_directorycCsB|r|jd|d}n |jd}|jd}|dkr:td|dS)zRetrieve token which can give the same authority to other uses Parameters ---------- renewer: str or None User who may use this token; if None, will be current user ZGETDELEGATIONTOKEN)renewerTokenNz1No token available for this user/security contextZ urlString)rOrBr)rrzrKtr!r!r"get_delegation_tokens  zWebHDFS.get_delegation_tokencCs|jdd|d}|jdS)z/Make token live longer. Returns new expiry timeZRENEWDELEGATIONTOKENput)r+rlong)rOrB)rrrKr!r!r"renew_delegation_tokenszWebHDFS.renew_delegation_tokencCs|jdd|ddS)z Stop the token from being usefulZCANCELDELEGATIONTOKENr~)r+rN)rO)rrr!r!r"cancel_delegation_tokenszWebHDFS.cancel_delegation_tokencCs|jdd||ddS)aSet the permission at path Parameters ---------- path: str location to set (file or directory) mod: str or int posix epresentation or permission, give as oct string, e.g, '777' or 0o777 Z SETPERMISSIONr~)r+rHZ permissionN)rO)rrHmodr!r!r"chmods z WebHDFS.chmodcCs>i}|dk r||d<|dk r$||d<|jdd|d|dS)zChange owning user and/or groupNownergroupSETOWNERr~)r+rH)r)rO)rrHrrrr!r!r"chown+s z WebHDFS.chowncCs|jd|d|ddS)a9 Set file replication factor Parameters ---------- path: str File location (not for directories) replication: int Number of copies of file on the cluster. Should be smaller than number of data nodes; normally 3 on most systems. ZSETREPLICATIONr~)rHr+rUN)rO)rrHrUr!r!r"set_replication4s zWebHDFS.set_replicationcKs|jdd|ddS)NZMKDIRSr~)r+rH)rO)rrHrr!r!r"mkdirBsz WebHDFS.mkdircCs(|dkr|j|rt||j|dS)NF)existsFileExistsErrorr)rrHexist_okr!r!r"makedirsEszWebHDFS.makedirscKs|jdd||ddS)NZRENAMEr~)r+rH destination)rO)rZpath1Zpath2rr!r!r"mvJsz WebHDFS.mvcKs|jdd||rdndddS)NDELETEdeletetruefalse)r+rH recursive)rO)rrHrrr!r!r"rmMs z WebHDFS.rmcKs|j|dS)N)r)rrHrr!r!r"rm_fileUszWebHDFS.rm_filecKs|j|}dj|j|dtjdg}y4|j|d}tj||WdQRX|j||Wn4tk rt t |j |WdQRXYnXWdQRXdS)Nrgz.tmp.wb) openjoin_parentsecretsZ token_hexshutil copyfileobjr BaseExceptionrrEr)rZlpathZrpathrZlstreamZ tmp_fnameZrstreamr!r!r"cp_fileXs   zWebHDFS.cp_filecCsL|jrt|jr|j|}n,|jrHx$|jjD]\}}|j||d}q.W|S)N)rcallableitemsreplace)rrukvr!r!r"rtfs  zWebHDFS._apply_proxy)rr )r FNNNNNF)r(NNT)rPNTNN)F)N)NN)F)F)%__name__ __module__ __qualname____doc__strtempfile gettempdirrSrrrrOrY staticmethodr_ classmethodrardr^rprqrwryr}rrrrrrrrrrrrt __classcell__r!r!)r r"r sN A # &         r csJeZdZdZfddZdddZddZd d Zd d Zd dZ Z S)rXz"A file living in HDFS over webHDFSc stj||f||j}|jdddkr6|jdd|jdddkrR|jdd|jdd|_|jd}|jdddkr|j|_tjj |t t j |_dS)NrVrUirSrTF) rrr;r(rcrVrHtargetosrruuiduuid4)rfsrHrrS)r r!r"rss   zWebHDFile.__init__FcCs,|jjj|j|jjddid}|jdS)zWrite one part of a multi-block file upload Parameters ========== final: bool This is the last block, so should complete file, if self.autocommit is True. z content-typezapplication/octet-stream)r-rsT)rr&postrubuffergetvaluerG)rfinalrKr!r!r" _upload_chunks  zWebHDFile._upload_chunkcCs|jj}d|jkrd\}}nd\}}d|d<|jj|||jfdd i|}|jj|jd }d |jkr|jjj |d d id}|j |j dd|_ dS)zCreate remote file/uploadaAPPENDPOSTCREATEPUTr overwriterIFrrwz content-typezapplication/octet-stream)rsN)rr)rr) rr;rQrrOrHrtrsr&r~rGrru)rrr*r+rKrurvr!r!r"_initiate_uploads    zWebHDFile._initiate_uploadcCst|d}t|j|}||ks(||jkr,dS|jjd|j|||dd}|jd|jkr|jd}|jjj |jj |}|j S|j SdS)NrZOPENF)rHoffsetr[rIrr) maxminr\rrOrHrGrsr&r(rtcontent)rstartendrKrurvr!r!r" _fetch_ranges    zWebHDFile._fetch_rangecCs|jj|j|jdS)N)rrrHr)rr!r!r"commitszWebHDFile.commitcCs|jj|jdS)N)rrrH)rr!r!r"discardszWebHDFile.discard)F) rrrrrrrrrrrr!r!)r r"rXps rX)loggingrrrrr contextlibr urllib.parserr$specrrutilsr getLoggerr>r rXr!r!r!r"s    ^