o Qa~@sddlmZmZddlZddlZddlZddlmZmZm Z ddl m Z ej dkZ GdddeZGd d d eZGd d d eZGd ddeZGdddeZedkredZedeeedeedejedeedeeedZedeeedeedejedeeedZedeeedeedejedeeedZedeeedeedejedeeedZedeeedeedejedeedSdS))absolute_importprint_functionN) unicodise deunicodisecheck_bucket_name_dns_support)Config)rc@sDeZdZdZdZddZddZddZdd Zd d Z d d Z dS)S3UriNc Cs|js1g|_tjtj}|D]"}t||t|urqt|||r0|||kr0|j||q|jD]}zt |}| ||WSt yNYq4wt d|)Nz%s: not a recognized URI) _subclassessysmodules__name____dict__type issubclassappendobject__new____init__ ValueError)selfstringdict somethingsubclassinstancer*/usr/lib/python3/dist-packages/S3/S3Uri.pyrs$       z S3Uri.__new__cCstr|St|SN)PY3urirrrrr__str__,s z S3Uri.__str__cCs|Sr)r!r"rrr __unicode__2zS3Uri.__unicode__cCstd|jj|fS)Nz<%s: %s>)repr __class__rr$r"rrr__repr__5zS3Uri.__repr__cCstd)Nz6This S3 URI does not have Anonymous URL representation)rr"rrr public_url8r%zS3Uri.public_urlcCs|ddS)N/)r$splitr"rrrbasename;zS3Uri.basename) r __module__ __qualname__rr rr#r$r(r*r.rrrrr s r c@seZdZdZedejejBZddZ ddZ ddZ d d Z d d Z d dZddZddZddZedddZeddZdS)S3UriS3s3z^s3:///*([^/]*)/?(.*)cCs<|j|}|std||}|d|_|d|_dS)Nz%s: not a S3 URIrr)_rematchrgroups_bucket_objectrrr5r6rrrrAs   zS3UriS3.__init__cC|jSr)r7r"rrrbucketIzS3UriS3.bucketcCr:r)r8r"rrrrLr<zS3UriS3.objectcC t|jSr)boolr7r"rrr has_bucketO zS3UriS3.has_bucketcCr=r)r>r8r"rrr has_objectRr@zS3UriS3.has_objectcCsdd|j|jgS)Nr+zs3:/)joinr7r8r"rrrr!Uz S3UriS3.uricCsttj|jSr)rr host_bucketr7r"rrris_dns_compatibleXr/zS3UriS3.is_dns_compatiblecCsNd}tjr d}|rd||jtj|jfSd|tj|j|jfS)Nhttphttpsz %s://%s.%s/%sz %s://%s/%s/%s)rpublic_url_use_httpsrEr7 host_baser8)rpublic_url_protocolrrrr*[s  zS3UriS3.public_urlcCs|r d|jSdS)Nz%s.s3.amazonaws.coms3.amazonaws.com)rEr7r"rrr host_nameds zS3UriS3.host_namecCs d||fS)Nz s3://%s/%srr;rrrr compose_urijs zS3UriS3.compose_uricCstd|tjtjB}|dd\}}|}|dkr2|ddkr)|}d}n|dd\}}n|drA|dt d }nt d|t d ||d S) Nz(https?://)?([^/]+)/?(.*)rrKr+rrMz.s3.amazonaws.comzUnable to parse URL: %szs3://%(bucket)s/%(object)srN) rer5 IGNORECASEUNICODEr6lowercountr-endswithlenrr )http_urlmhostnamerr;rrrhttpurl_to_s3urins   zS3UriS3.httpurl_to_s3uriN)rM)rr0r1rrPcompilerQrRr4rr;rr?rAr!rEr*rL staticmethodrOrZrrrrr2>s   r2c@DeZdZdZedejejBZddZ ddZ ddZ d d Z d S) S3UriS3FSs3fsz^s3fs:///*([^/]*)/?(.*)cCsB|j|}|std||}|d|_|dd|_dS)Nz%s: not a S3fs URIrrr+)r4r5rr6_fsnamer-_pathr9rrrrs   zS3UriS3FS.__init__cCr:r)r`r"rrrfsnamer<zS3UriS3FS.fsnamecCs d|jS)Nr+rBrar"rrrpaths zS3UriS3FS.pathcCsdd|j|gS)Nr+zs3fs:/)rBr`rdr"rrrr!sz S3UriS3FS.uriN) rr0r1rrPr[rQrRr4rrbrdr!rrrrr^ r^c@sNeZdZdZedejZddZddZ ddZ d d Z d d Z d dZ dS) S3UriFilefilez^(\w+://)?(.*)cCsb|j|}|}|ddvrtd||ddur'|dtj|_dS|dd|_dS)Nr)Nzfile://z%s: not a file:// URIrr+)r4r5r6rr-osseprar9rrrrs    zS3UriFile.__init__cCstj|jSr)rhrirBrar"rrrrdszS3UriFile.pathcCsddg|jS)Nr+zfile:/rcr"rrrr!r/z S3UriFile.uricCstjt|Sr)rhrdisdirrr"rrrrjrCzS3UriFile.isdircCttjt|Sr)rrhrddirnamerr"rrrrlr)zS3UriFile.dirnamecCrkr)rrhrdr.rr"rrrr.r)zS3UriFile.basenameN)rr0r1rrPr[rRr4rrdr!rjrlr.rrrrrfs  rfc@r]) S3UriCloudFrontcfz^cf://([^/]*)/*(.*)cCsL|j|}|std||}|d|_|ddkr!|dp"d|_dS)Nz%s: not a CloudFront URIrrr+)r4r5rr6_dist_id _request_idr9rrrrs   zS3UriCloudFront.__init__cCr:r)ror"rrrdist_idr<zS3UriCloudFront.dist_idcCr:r)rpr"rrr request_idr<zS3UriCloudFront.request_idcCs(d|}|r|d|7}|S)Nzcf://r+)rqrr)rr!rrrr!s zS3UriCloudFront.uriN) rr0r1rrPr[rQrRr4rrqrrr!rrrrrmrerm__main__zs3://bucket/objectz type() =z uri =z uri.type=z bucket =z object =z s3://bucketz*s3fs://filesystem1/path/to/remote/file.txtz path =z/path/to/local/file.txtzcf://1234567890ABCD/z dist_id =) __future__rrrhrPr UtilsrrrrMr version_infor rr r2r^rfrmrr!printrr;rdrqrrrrsZ  )G