labpack/storage/aws/s3.py
def save(self, record_key, record_data, overwrite=True, secret_key=''):
        
        ''' 
            a method to create a file in the collection folder on S3

        :param record_key: string with name to assign to record (see NOTES below)
        :param record_data: byte data for record body
        :param overwrite: [optional] boolean to overwrite records with same name
        :param secret_key: [optional] string with key to encrypt data
        :return: string with name of record

        NOTE:   record_key may only contain alphanumeric, /, _, . or -
                characters and may not begin with the . or / character.

        NOTE:   using one or more / characters splits the key into
                separate segments. these segments will appear as a
                sub directories inside the record collection and each
                segment is used as a separate index for that record
                when using the list method
                eg. lab/unittests/1473719695.2165067.json is indexed:
                [ 'lab', 'unittests', '1473719695.2165067', '.json' ]
        '''

        title = '%s.save' % self.__class__.__name__
    
    # validate inputs
        input_fields = {
            'record_key': record_key,
            'secret_key': secret_key
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
    
    # validate byte data
        if not isinstance(record_data, bytes):
            raise ValueError('%s(record_data=b"...") must be byte data.' % title)
    
    # encrypt data
        if secret_key:
            from labpack.encryption import cryptolab
            record_data, secret_key = cryptolab.encrypt(record_data, secret_key)
            
    # define keyword arguments
        from time import time
        create_kwargs = {
            'bucket_name': self.bucket_name,
            'record_key': record_key,
            'record_data': record_data,
            'overwrite': overwrite,
            'record_metadata': { 'last_modified': str(time()) }
        }
    
    # add encryption metadata
        if secret_key:
            create_kwargs['record_metadata']['encryption'] = 'lab512'
    
    # add record mimetype and encoding
        import mimetypes
        guess_mimetype, guess_encoding = mimetypes.guess_type(record_key)
        if not guess_mimetype:
            if record_key.find('.yaml') or record_key.find('.yml'):
                guess_mimetype = 'application/x-yaml'
            if record_key.find('.drep'):
                guess_mimetype = 'application/x-drep'
        if guess_mimetype:
            create_kwargs['record_mimetype'] = guess_mimetype
        if guess_encoding:
            create_kwargs['record_encoding'] = guess_encoding
            
    # create record
        self.s3.create_record(**create_kwargs)

        return record_key
 
            a method to create a file in the collection folder on S3

        :param record_key: string with name to assign to record (see NOTES below)
        :param record_data: byte data for record body
        :param overwrite: [optional] boolean to overwrite records with same name
        :param secret_key: [optional] string with key to encrypt data
        :return: string with name of record

        NOTE:   record_key may only contain alphanumeric, /, _, . or -
                characters and may not begin with the . or / character.

        NOTE:   using one or more / characters splits the key into
                separate segments. these segments will appear as a
                sub directories inside the record collection and each
                segment is used as a separate index for that record
                when using the list method
                eg. lab/unittests/1473719695.2165067.json is indexed:
                [ 'lab', 'unittests', '1473719695.2165067', '.json' ]
        
a method to create a file in the collection folder on S3
a method to create a file in the collection folder on S3
def save(self, record_key, record_data, overwrite=True, secret_key=''):
        title = '%s.save' % self.__class__.__name__
        input_fields = {
            'record_key': record_key,
            'secret_key': secret_key
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
        if not isinstance(record_data, bytes):
            raise ValueError('%s(record_data=b"...") must be byte data.' % title)
        if secret_key:
            from labpack.encryption import cryptolab
            record_data, secret_key = cryptolab.encrypt(record_data, secret_key)
        from time import time
        create_kwargs = {
            'bucket_name': self.bucket_name,
            'record_key': record_key,
            'record_data': record_data,
            'overwrite': overwrite,
            'record_metadata': { 'last_modified': str(time()) }
        }
        if secret_key:
            create_kwargs['record_metadata']['encryption'] = 'lab512'
        import mimetypes
        guess_mimetype, guess_encoding = mimetypes.guess_type(record_key)
        if not guess_mimetype:
            if record_key.find('.yaml') or record_key.find('.yml'):
                guess_mimetype = 'application/x-yaml'
            if record_key.find('.drep'):
                guess_mimetype = 'application/x-drep'
        if guess_mimetype:
            create_kwargs['record_mimetype'] = guess_mimetype
        if guess_encoding:
            create_kwargs['record_encoding'] = guess_encoding
        self.s3.create_record(**create_kwargs)
        return record_key
def save ( self , record_key , record_data , overwrite = True , secret_key = '' ) : title = '%s.save' % self . __class__ . __name__ input_fields = { 'record_key' : record_key , 'secret_key' : secret_key } for key , value in input_fields . items ( ) : if value : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) if not isinstance ( record_data , bytes ) : raise ValueError ( '%s(record_data=b"...") must be byte data.' % title ) if secret_key : from labpack . encryption import cryptolab record_data , secret_key = cryptolab . encrypt ( record_data , secret_key ) from time import time create_kwargs = { 'bucket_name' : self . bucket_name , 'record_key' : record_key , 'record_data' : record_data , 'overwrite' : overwrite , 'record_metadata' : { 'last_modified' : str ( time ( ) ) } } if secret_key : create_kwargs [ 'record_metadata' ] [ 'encryption' ] = 'lab512' import mimetypes guess_mimetype , guess_encoding = mimetypes . guess_type ( record_key ) if not guess_mimetype : if record_key . find ( '.yaml' ) or record_key . find ( '.yml' ) : guess_mimetype = 'application/x-yaml' if record_key . find ( '.drep' ) : guess_mimetype = 'application/x-drep' if guess_mimetype : create_kwargs [ 'record_mimetype' ] = guess_mimetype if guess_encoding : create_kwargs [ 'record_encoding' ] = guess_encoding self . s3 . create_record ( ** create_kwargs ) return record_key
a method to create a file in the collection folder on S3
a method to create a file in the collection folder on S3
''' 
            a method to create a file in the collection folder on S3

        :param record_key: string with name to assign to record (see NOTES below)
        :param record_data: byte data for record body
        :param overwrite: [optional] boolean to overwrite records with same name
        :param secret_key: [optional] string with key to encrypt data
        :return: string with name of record

        NOTE:   record_key may only contain alphanumeric, /, _, . or -
                characters and may not begin with the . or / character.

        NOTE:   using one or more / characters splits the key into
                separate segments. these segments will appear as a
                sub directories inside the record collection and each
                segment is used as a separate index for that record
                when using the list method
                eg. lab/unittests/1473719695.2165067.json is indexed:
                [ 'lab', 'unittests', '1473719695.2165067', '.json' ]
        ''' # validate inputs # validate byte data # encrypt data # define keyword arguments # add encryption metadata # add record mimetype and encoding # create record
string with name of record
NOTE:   record_key may only contain alphanumeric, /, _, . or
characters and may not begin with the . or / character.

using one or more / characters splits the key into
separate segments. these segments will appear as a
sub directories inside the record collection and each
segment is used as a separate index for that record
when using the list method
eg.
string with name of record NOTE : record_key may only contain alphanumeric / _ . or characters and may not begin with the . or / character . using one or more / characters splits the key into separate segments . these segments will appear as a sub directories inside the record collection and each segment is used as a separate index for that record when using the list method eg .
self
record_key
string with name to assign to record
string with name to assign to record
record_data
byte data for record body
byte data for record body
overwrite
[optional] boolean to overwrite records with same name
[ optional ] boolean to overwrite records with same name
secret_key
[optional] string with key to encrypt data
[ optional ] string with key to encrypt data