Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
python3-s3fuse-plugin / usr / lib / python3.6 / site-packages / s3fuse / __pycache__ / vaults3.cpython-36.opt-1.pyc
Size: Mime:
3

Ù2Ù_‘lã@shdZddlZddlZddlZddlZddlZddlZddlmZdZ	dZ
dZdd„ZGd	d
„d
e
ƒZdS)z Trilio S3 Backend implimentation

    This module contains the back end implimentation of all of all S3 specific
    support.
éN)ÚClientErrorÚs3ièz$80bc80ff-0c51-4534-86a2-ec5e719643c2cCs&|jdd}|tjdddƒjƒ}|S)zè Utility function used to convert a datetime to an OS timestamp.

    Args:
        modified_time (datetime): Datatime object to convert to a Unix Epoc timestamp.

    Returns:
        The value of modified_time as a timestamp.
    N)Ztzinfoi²é)ÚreplaceÚdatetimeZ
total_seconds)Z
modified_timeZ
naive_timeZ
delta_seconds©rú/usr/lib/python3.6/vaults3.pyÚ_make_timestamps	r	c@sžeZdZdZdd„Zdd„Zdd„Zdd	„Zd
d„Zd'd
d„Z	dd„Z
dd„Zd(dd„Zdd„Z
d)dd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„ZdS)*Ú	S3Backendz´ S3 Backend implimentation.

    A Wrapper for the AWS S3 boto3 and botocore API. This class encapsulates all S3
    operations and exposes them as a backend storage instance.
    c
CsÒd}|ddkr.tjj|dt|dƒd}ntjjt|dƒd}|ddkrŽtjd|d	d
|d|d|d
|d	d||dd|_n6tjd|d	d
|d|d|d
|d	d|d|_|d|_dS)NZs3_signatureÚdefaultZs3_read_timeout)Zsignature_versionÚread_timeout)rZs3_ssl_certÚrZ
os_optionsÚregion_nameZs3_sslÚuserÚkeyZobject_storage_url)rÚuse_sslÚaws_access_key_idÚaws_secret_access_keyÚendpoint_urlÚconfigZverify)rrrrrrZbucket)ÚbotocoreZclientZConfigÚintÚboto3Ú_S3Backend__clientÚ_S3Backend__bucket_name)ÚselfÚoptionsZ
config_objectrrrÚ__init__2s*




zS3Backend.__init__cCs–yzxtt|ƒdkrvg}|dt…}x0|D](}|jdƒr@|dd…}|jd|iƒq&W|jj|jd|id|td…}qWWntk
r‚YnXdS)zß Utility method that takes a list of objects and puts it in the correct format
            for the S3 delete_objects() API.

        Args:
            object_list (list): A list of objects with the correct S3 path.
        rNú/rÚKeyZObjects)ÚBucketZDelete)ÚlenÚMAX_S3_PAGE_SIZEÚ
startswithÚappendrZdelete_objectsrr)rÚobject_listZobject_delete_listZ	list_partÚobjrrrZ__delete_object_list]s


zS3Backend.__delete_object_listcCs˜y|g}|jjdƒ}|j|j|d}xL|D]D}d|kr(|jdt|dƒƒdkr(x|dD]}|j|dƒqVWq(W|j|ƒWntk
r’‚YnXdS)z‘ Utility method used to perform a rmdir operation on an object hierarchy

        Args:
            object_tree (str): Object/Tree path.
        Úlist_objects)r ÚPrefixÚContentsÚKeyCountrrN)	rÚ
get_paginatorÚpaginaterÚgetr!r$Ú_S3Backend__delete_object_listr)rÚobject_treer%Úlist_paginatorÚ
page_iteratorÚobjectsr&rrrZ__delete_object_treevs
 zS3Backend.__delete_object_treecCs|j|ƒdS)zó Delete a list of objects.

        Args:
            object_list (list): List of objects. Each with a full object path
                                in correct format.
            options (dic): Dictionary of configuration options.
        N)r.)rr%rrrrÚdelete_object_list‹szS3Backend.delete_object_listcCszy^|s
dSdj|ƒ}|jdƒr*|dd…}d|krF|jj|j|dn|jj|j|ddWntk
rt‚YnXdS)a Delete an object from the S3 object store.

        The object and any segments stored in the segment directory will be
        removed.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.
        Nrrz	-segments)r rz	.manifest)Újoinr#rÚ
delete_objectrr)rÚargsrÚobject_namerrrr5•s





zS3Backend.delete_objectrcCs¤td|ƒ}y~xxtd|ƒD]j}y|jj|j|ddStk
r€}z2|jdddkrn|d|krntjdƒw‚WYdd}~XqXqWWntk
rž‚YnXdS)a Utility method used to wait for a S3 object to become available.

        This routine will keep performing a head_object() request every second
        for "retries" number of times. This was added to work around any potential
        eventual consistancey issues when uploading to AWS.

        Args:
            object_name (str): Name of the object.
            retries (int): Optional parameter that defaults to 1.

        Returns:
            Returns when the object is available or ClientError not found exception.
        rr)r rNÚResponseMetadataÚHTTPStatusCodei”)	ÚmaxÚrangerÚhead_objectrrÚresponseÚtimeÚsleep)rr7ÚretriesÚretryÚerrorrrrZ__wait_for_object³s


zS3Backend.__wait_for_objectcCsÄ|jdƒd}y*|jj|j|d}tj|dj|dƒƒStk
r¾}zj|jdddkr`‚nNy6|j	|d	ƒ|jj|j|d}tj|dj|dƒƒStk
r¬‚YnXWYd
d
}~XnXd
S)zÓ Download and return the object manifest as a json array.

            Args:
                object_name (str): Name of the object.

            Returns:
                Object manifest as a dictionary.
        rz	.manifest)r rÚBodyÚ
ContentLengthr8r9iӎ
N)
ÚstriprZ
get_objectrÚjsonÚloadsÚreadrr=Ú_S3Backend__wait_for_object)rr7Ú
manifest_nameZresprBrrrÚget_object_manifestÒs	
zS3Backend.get_object_manifestcCsRy"dj|ƒ}|jj|j||jƒWn*tk
r8‚Yntk
rL‚YnXdS)a? Download a file from the S3 object store.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.

        Returns:
            On success, the contents of the object are downloaded to file identidfied
            by options.out_file.
        rN)r4rZ
download_filerZout_filerÚ	Exception)rr6rr7rrrÚdownload_objectìs
zS3Backend.download_objectNTcCsDtƒ}dj|ƒ}|ddk	rB|d|d}|jdƒrB|dd…}yât}|dk	r^|tkr^|}|jjdƒ}|s†|j|jdd|id}	n|j|j|d|id}	x€|	D]v}
d	|
koÈ|
jd
t	|
d	ƒƒdkrÂ|d}xì|
d	D]à}|dk	oôt	|ƒ|krt
|ƒStjj
|djdƒƒ\}
}|d
kr\tjj
|
ƒ\}}t	|ƒdkrÞ|dkrÞ||krÞ|j|ƒqÞtjj
|ƒ\}}||
kr~|
|ksÞ|dksÞ|d|kr–qÞ|dks¨|
|krÞ|j|j
ddƒdƒqÞWd|
kr¤xP|
dD]D}|dk	røt	|ƒ|krøt
|ƒS|djtƒsÔ|j|dƒqÔWq¤Wt
|ƒStk
r>‚YnXdS)a° Return a list of objects based on the provided prefix.

        Used to generate a directory listing based on a prefix path
        constructed from the object parts in args[] and the options.prefix.

        Args:
            args (list): List of prefix keyParts
            options (dic): Dictionary of configuration options
            max_items (int): Maximum number of objects in a list query. Default is
                unlimited but when testing for an empty directory a smaller
                number can be used to limit the query and size of the list that
                is returned.
            strict_path_filter (bool): Defaults to True in order to only return
                objects with the exact same prefix. Individual segment listings
                set this to False in order to get a match on the segment offset.

        Returns:
            On success a list of unique items to be used as a directory listing.
        rÚprefixNrr'ZPageSize)r Z	DelimiterÚPaginationConfig)r r(rPr)r*rrzx.hiddenr
Fz	.manifestZCommonPrefixesr(éÿÿÿÿ)Úsetr4Úendswithr"rr+r,rr-r!ÚlistÚosÚpathÚsplitÚrstripÚaddr#Ú_SEGMENT_PREFIXr)rr6rZ	max_itemsÚstrict_path_filterZ
object_setrOZ	page_sizer0r1r2Zsplit_tokenÚitemrVr7Z	root_pathZsub_dirÚ_Z
object_prefixrrrr'sZ

"

zS3Backend.list_objectscCsfyJg}tjj|jƒ\}}|j||dd}x|D]}|j|d|ƒq.W|Stk
r`‚YnXdS)a& Returns a list of object segments based on a prefix.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.

        Returns:
            A list of segments in the object store that match the supplied prefix.
        F)r[rN)rUrVrWrOr'r$r)rr6rZsegment_listZ
segments_pathr]r%r\rrrÚ
list_segmentses

zS3Backend.list_segmentsc/Cs„td|ƒ}yZxRtd|ƒD]B}y|jj|j|d}|Stk
r^}z|jdddkrLy|jj|j|dd}|Stk
rJ}z°|jdddkr8d|kry|jj|j|d	d}|Stk
r}z6|jdddkr
|d|kr
tjdƒw‚WYd
d
}~XnX|d|kr8tjdƒw‚WYd
d
}~XnX‚WYd
d
}~XqXqWWntk
r~‚YnXd
S)a= Utility method that gets an object head from the repository with retry support.

        The default is to try once. Admittedly, this is ugly because the
        provided object name might be a terminal object or a "directory" so
        we need to try both cases for each retry attempt. When retry > 1, there is
        a 1 second delay between attempts.

        Args:
            object_name (str): Name of the object.
            retries (int): Optional parameter, default is 1 attempt.

        Returns:
            Object head dictionary or Boto3 exception.
        rr)r rr8r9i”rz	-segmentsz	.manifestN)	r:r;rr<rrr=r>r?)rr7r@rAZobj_headersrBrrrZ__get_object_headers{sB






zS3Backend.__get_object_headerscCs2dddddœ}i|d<i|dd<dj|ƒ}yè|sHttjjƒƒ|d<|S|j|ƒ}t|d	ƒ|d<||d<|jd
dƒdks†|d
dkrŽd|d<x0|ddjƒD]\}}d|kr ||d|<q Wt|ddjddƒƒdkrö|ddjddƒ|d<n|d
|d<|d|d<|SWntk
r,‚YnXdS)a) Get "operating system like" stat data for the given object.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.

        Returns:
            A stat structure containing object information required by caller.
        rr
F)Ú	timestampÚsizeÚetagÚ	directoryZheadersÚMetadatarr_ZLastModifiedÚContentTypez
text/plainzapplication/x-directoryrDTrbz
x-object-metazx-object-meta-segment-countzx-object-meta-total-sizer`zx-account-bytes-usedN)	r4r	rZnowÚ_S3Backend__get_object_headersr-Úitemsrr)rr6rZ	stat_datar7Z
obj_headerrÚvaluerrrÚstat_object­s2


zS3Backend.stat_objectcCsdj|ƒ}|j||ƒdS)zÎ Create an object that represents a directory in the object store.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.
        rN)r4Ú_S3Backend__create_folder)rr6rZ
new_folderrrrÚmkdir_objectÙs
zS3Backend.mkdir_objectcCsDdj|ƒd}|jdƒr$|dd…}|j|ƒ|jj|j|ddS)zÎ Remove an object that represents a directory in the object store.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.
        rrN)r r)r4r#Ú_S3Backend__delete_object_treerr5r)rr6rr/rrrÚrmdir_objectäs


zS3Backend.rmdir_objectc
Cs|y`x*|D]"}|jdƒ|d<|jddƒ|d<qWtj|ƒ}|jdƒd}|jj|j|||dd	Wntk
rv‚YnXd
S)a? Upload a new object manifest to the object store.

        Args:
            object_name (str): Name of the object. A ".manifest" will be added.
            put_headers (dic): Dictionary of meta data to be added to the object.
            manifest_data (dic): The manifest data which becomes the body of file.
        rVÚnamerarÚhashrz	.manifestz
text/plain)r rrcrCrdN)ÚpoprGÚdumpsrFrÚ
put_objectrr)rr7Zput_headersZ
manifest_dataZsegment_dataZmanifestrKrrrÚupload_object_manifestõs


z S3Backend.upload_object_manifestc)CsXy|jj|j|dWn:tk
rR}z|jdddkrB|jdƒ}d}xð|D]è}|dkrdP||d}y|jj|j|dWqVtk
r<}z˜|jdddkr*|ddkrÔ|jj|j|d	d
dnVy|jj|j|dd
dWn:tk
r(}z|jdddkr‚WYdd}~XnXwVWYdd}~XqVXqVWWYdd}~XnXdS)a< Utility method used to create a object directory structure.

        The entire path is split and each directory level is created as an object
        if it does not exist.

        Args:
            folder_name (str): The entire folder name.
            options (dic): Dictionary of configuration options.
        )r rr8r9i”rr
Zsupport_empty_dirTzx.hiddenz
Do Not Remove)r rrCzTrilioVault directory objectzapplication/x-directory)r rrCrdi™N)rr<rrr=rWrq)rZfolder_namerrBÚ
path_partsÚnew_pathÚpartrrrZ__create_folder
s4




zS3Backend.__create_foldercCs¨|dd…}y€|jdkr<|jtjj|dd|dƒ|ƒ|jdk	rŠt|ddƒ0}|jj||j	|dd|ddd	id
WdQRXWnt
k
r¢‚YnXdS)zµ Upload an object to the S3 object store.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.
        rNFrrr7Úrbrdzapplication/octet-stream)r rZ	ExtraArgs)Z
path_validrirUrVÚdirnamer7ÚopenrZupload_fileobjrr)rr6rÚfilesÚdatarrrÚ
upload_object=s

zS3Backend.upload_object)r)NT)r)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rr.rkr3r5rJrLrNr'r^rerhrjrlrrrir{rrrrr
,s$+


c
2,0r
)rrr>rGrUrrZbotocore.exceptionsrZBASENAMEr"rZr	Úobjectr
rrrrÚ<module>s