本文整理汇总了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
}})
示例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()