当前位置: 首页>>代码示例>>Python>>正文


Python Binary.__len__方法代码示例

本文整理汇总了Python中bson.binary.Binary.__len__方法的典型用法代码示例。如果您正苦于以下问题:Python Binary.__len__方法的具体用法?Python Binary.__len__怎么用?Python Binary.__len__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bson.binary.Binary的用法示例。


在下文中一共展示了Binary.__len__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from bson.binary import Binary [as 别名]
# 或者: from bson.binary.Binary import __len__ [as 别名]
 def post(self, *args):
     # Add entry into bucket and flag as multipart upload
     if self.bucket_name and self.object_name:
         bucket_name = self.bucket_name
         object_name = self.object_name
     else:
         bucket_name,object_name = args
     
     if bucket_name not in self._get_bucket_names():
         self._error(code=404,s3code='NSB')
         return
     
     original_name = urllib.unquote(object_name)
     bucket_object = Binary(self.request.body)
     object_size = bucket_object.__len__()
     object_md5 = self._object_md5(bucket_object)
     
     if self.uploadId:
         # We have a multipart upload, so iterate over the parts to generate the md5 hash and calculate size
         # This is the last call made after the mutlipart upload with the uploadId
         mupmd5 = hashlib.md5()
         mupsize = 0
         for mup in self.application.S3[bucket_name].find({'object_name':object_name}):
             mupmd5.update(mup['object'])
             mupsize += mup['size']
             
         self.application.S3[bucket_name].insert_one({'object_name':object_name,'object':bucket_object,'multipart':True,'md5':mupmd5.hexdigest(),'size':mupsize,'added':datetime.datetime.utcnow(),'updated':datetime.datetime.utcnow(),})
     
     self.render_xml({"InitiateMultipartUploadResult": {
         "Bucket": bucket_name,
         "Prefix": self.prefix,
         "Key":object_name,
         "UploadId":object_name
     }})
开发者ID:chembl,项目名称:the-S3-amongos,代码行数:36,代码来源:the-S3-amongos.py

示例2: put

# 需要导入模块: from bson.binary import Binary [as 别名]
# 或者: from bson.binary.Binary import __len__ [as 别名]
    def put(self, *args):
        
        if self.bucket_name and self.object_name:
            bucket_name = self.bucket_name
            object_name = self.object_name
        else:
            bucket_name,object_name = args
            
        original_name = urllib.unquote(object_name)

        if bucket_name not in self._get_bucket_names():
            self._error(code=404,s3code='NSB')
            return
        
        # Insert object and then calculate computed md5 of stored object, size, then update and return
        
        # If the object already exists, delete contents and add updated timestamp and update
        existance = self.application.S3[bucket_name].find({"object_name":original_name})       
        
        if existance.count() > 0 and self.partNumber == None:
            existance_id = existance.next()['_id']
            update_object = Binary(self.request.body)
            object_size = update_object.__len__()
            object_md5 = self._object_md5(update_object)
            self.application.S3[bucket_name].update({"_id":existance_id},{'$set': {'object':update_object,'md5':object_md5,'updated':datetime.datetime.utcnow(),'size':object_size}})
            self.set_header('etag', '"%s"' % object_md5)
            self.finish()
            return
        
        if self.partNumber:
            tobeinserted = {'object_name':original_name,'object':Binary(self.request.body),'partNumber':self.partNumber}
        else:
            tobeinserted = {'object_name':original_name,'object':Binary(self.request.body)}
            
        inserted_object_id = self.application.S3[bucket_name].insert_one(tobeinserted).inserted_id
        inserted_object = self._get_bucket_object(bucket_name=bucket_name,_id=inserted_object_id)
        
        object_size = inserted_object['object'].__len__()
        object_md5 = self._object_md5(inserted_object['object'])
        self.application.S3[bucket_name].update({'_id':inserted_object_id},{'$set': {'md5':object_md5,'updated':datetime.datetime.utcnow(),'added':datetime.datetime.utcnow(),'size':object_size}})
        self.set_header('etag', '"%s"' % object_md5)
        
        
        self.finish()
开发者ID:chembl,项目名称:the-S3-amongos,代码行数:46,代码来源:the-S3-amongos.py


注:本文中的bson.binary.Binary.__len__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。