本文整理汇总了Python中pyrax.utils.get_checksum函数的典型用法代码示例。如果您正苦于以下问题:Python get_checksum函数的具体用法?Python get_checksum怎么用?Python get_checksum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_checksum函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: upload
def upload(fileobj, content_type, etag):
if isinstance(fileobj, basestring):
# This is an empty directory file
fsize = 0
else:
fsize = get_file_size(fileobj)
if fsize < self.max_file_size:
# We can just upload it as-is.
return self.connection.put_object(cont.name, obj_name,
contents=fileobj, content_type=content_type,
etag=etag)
# Files larger than self.max_file_size must be segmented
# and uploaded separately.
num_segments = int(math.ceil(float(fsize) / self.max_file_size))
digits = int(math.log10(num_segments)) + 1
# NOTE: This could be greatly improved with threading or other
# async design.
for segment in xrange(num_segments):
sequence = str(segment + 1).zfill(digits)
seg_name = "%s.%s" % (fname, sequence)
with utils.SelfDeletingTempfile() as tmpname:
with file(tmpname, "wb") as tmp:
tmp.write(fileobj.read(self.max_file_size))
with file(tmpname, "rb") as tmp:
# We have to calculate the etag for each segment
etag = utils.get_checksum(tmp)
self.connection.put_object(cont.name, seg_name,
contents=tmp, content_type=content_type,
etag=etag)
# Upload the manifest
hdr = {"X-Object-Meta-Manifest": "%s." % fname}
return self.connection.put_object(cont.name, fname,
contents=None, headers=hdr)
开发者ID:ejhammons,项目名称:pyrax,代码行数:33,代码来源:client.py
示例2: test_get_checksum_from_string
def test_get_checksum_from_string(self):
test = "some random text"
md = hashlib.md5()
md.update(test)
expected = md.hexdigest()
received = utils.get_checksum(test)
self.assertEqual(expected, received)
开发者ID:naterh,项目名称:pyrax,代码行数:7,代码来源:test_utils.py
示例3: test_get_checksum_from_string
def test_get_checksum_from_string(self):
test = utils.random_ascii().encode("ascii")
md = hashlib.md5()
md.update(test)
expected = md.hexdigest()
received = utils.get_checksum(test)
self.assertEqual(expected, received)
开发者ID:rackspace,项目名称:pyrax,代码行数:7,代码来源:test_utils.py
示例4: test_get_checksum_from_unicode_alt_encoding
def test_get_checksum_from_unicode_alt_encoding(self):
test = u"some ñøñåßçîî text"
md = hashlib.md5()
enc = "Windows-1252"
md.update(test.encode(enc))
expected = md.hexdigest()
received = utils.get_checksum(test, enc)
self.assertEqual(expected, received)
开发者ID:naterh,项目名称:pyrax,代码行数:8,代码来源:test_utils.py
示例5: test_get_checksum_from_binary
def test_get_checksum_from_binary(self):
test = fakes.get_png_content()
md = hashlib.md5()
enc = "utf8"
md.update(test)
expected = md.hexdigest()
received = utils.get_checksum(test)
self.assertEqual(expected, received)
开发者ID:CarlFK,项目名称:pyrax,代码行数:8,代码来源:test_utils.py
示例6: test_get_checksum_from_unicode
def test_get_checksum_from_unicode(self):
test = utils.random_unicode()
md = hashlib.md5()
enc = "utf8"
md.update(test.encode(enc))
expected = md.hexdigest()
received = utils.get_checksum(test)
self.assertEqual(expected, received)
开发者ID:CarlFK,项目名称:pyrax,代码行数:8,代码来源:test_utils.py
示例7: test_get_checksum_from_binary
def test_get_checksum_from_binary(self):
test = os.urandom(1024)
md = hashlib.md5()
enc = "utf8"
md.update(test)
expected = md.hexdigest()
received = utils.get_checksum(test)
self.assertEqual(expected, received)
开发者ID:rackspace,项目名称:pyrax,代码行数:8,代码来源:test_utils.py
示例8: test_get_checksum_from_binary
def test_get_checksum_from_binary(self):
# test = utils.random_name()
# test = open("tests/unit/python-logo.png", "rb").read()
test = fakes.png_file
md = hashlib.md5()
enc = "utf8"
md.update(test)
expected = md.hexdigest()
received = utils.get_checksum(test)
self.assertEqual(expected, received)
开发者ID:naterh,项目名称:pyrax,代码行数:10,代码来源:test_utils.py
示例9: test_get_checksum_from_file
def test_get_checksum_from_file(self):
test = "some random text"
md = hashlib.md5()
md.update(test)
expected = md.hexdigest()
with utils.SelfDeletingTempfile() as tmp:
with open(tmp, "w") as testfile:
testfile.write(test)
with open(tmp, "r") as testfile:
received = utils.get_checksum(testfile)
self.assertEqual(expected, received)
开发者ID:naterh,项目名称:pyrax,代码行数:11,代码来源:test_utils.py
示例10: test_store_object
def test_store_object(self):
client = self.client
client.connection.head_container = Mock()
client.connection.put_object = Mock()
gobj = client.get_object
client.get_object = Mock(return_value=self.fake_object)
content = u"something with ü†ƒ-8"
etag = utils.get_checksum(content)
obj = client.store_object(self.cont_name, self.obj_name, content,
content_type="test/test", etag=etag)
self.assertEqual(client.connection.put_object.call_count, 1)
client.get_object = gobj
开发者ID:dustinfarris,项目名称:pyrax,代码行数:12,代码来源:test_cf_client.py
示例11: add_entry
def add_entry(base, path):
node = FSNode(base, path)
if path in manifest and node.mtime <= manifest[path]["mtime"]:
return
print "noype"
file_hash = utils.get_checksum(os.path.join(base, path))
manifest[path] = ({
"md5": file_hash,
"atime": node.atime,
"ctime": node.ctime,
"mtime": node.mtime
})
开发者ID:cybera,项目名称:fusepy-moodledata,代码行数:12,代码来源:tool_build_modified_table.py
示例12: test_store_object
def test_store_object(self):
cont = self.container
cont.client.connection.head_container = Mock()
cont.client.connection.put_object = Mock()
gobj = cont.client.get_object
cont.client.get_object = Mock(return_value=self.fake_object)
content = "something"
etag = utils.get_checksum(content)
obj = cont.store_object(self.obj_name, content,
content_type="test/test", etag=etag,
content_encoding="gzip")
self.assertEqual(cont.client.connection.put_object.call_count, 1)
cont.client.get_object = gobj
开发者ID:naterh,项目名称:pyrax,代码行数:13,代码来源:test_cf_container.py
示例13: _sync_folder_to_container
def _sync_folder_to_container(self, folder_path, cont, prefix, delete,
include_hidden, ignore, ignore_timestamps):
"""
This is the internal method that is called recursively to handle
nested folder structures.
"""
fnames = os.listdir(folder_path)
ignore = utils.coerce_string_to_list(ignore)
if not include_hidden:
ignore.append(".*")
for fname in fnames:
if utils.match_pattern(fname, ignore):
continue
pth = os.path.join(folder_path, fname)
if os.path.isdir(pth):
subprefix = fname
if prefix:
subprefix = "%s/%s" % (prefix, subprefix)
self._sync_folder_to_container(pth, cont, prefix=subprefix,
delete=delete, include_hidden=include_hidden,
ignore=ignore, ignore_timestamps=ignore_timestamps)
continue
self._local_files.append(os.path.join(prefix, fname))
local_etag = utils.get_checksum(pth)
fullname = fname
if prefix:
fullname = "%s/%s" % (prefix, fname)
try:
obj = cont.get_object(fullname)
obj_etag = obj.etag
except exc.NoSuchObject:
obj = None
obj_etag = None
if local_etag != obj_etag:
if not ignore_timestamps:
if obj:
obj_time_str = obj.last_modified[:19]
else:
obj_time_str = EARLY_DATE_STR
local_mod = datetime.datetime.utcfromtimestamp(
os.stat(pth).st_mtime)
local_mod_str = local_mod.isoformat()
if obj_time_str >= local_mod_str:
# Remote object is newer
continue
cont.upload_file(pth, obj_name=fullname, etag=local_etag,
return_none=True)
if delete and not prefix:
self._delete_objects_not_in_list(cont)
开发者ID:ejhammons,项目名称:pyrax,代码行数:49,代码来源:client.py
示例14: test_store_object
def test_store_object(self):
client = self.client
client.connection.head_container = Mock()
client.connection.put_object = Mock()
gobj = client.get_object
client.get_object = Mock(return_value=self.fake_object)
content = u"something with ü†ƒ-8"
etag = utils.get_checksum(content)
obj = client.store_object(self.cont_name, self.obj_name, content,
content_type="test/test", etag=etag,
content_encoding="gzip")
self.assertEqual(client.connection.put_object.call_count, 1)
# Add extra_info
response = {}
obj = client.store_object(self.cont_name, self.obj_name, content,
content_type="test/test", etag=etag,
content_encoding="gzip", extra_info=response)
client.connection.put_object.assert_called_with(ANY, ANY,
contents=ANY, content_type=ANY, etag=ANY, headers=ANY,
response_dict=response)
client.get_object = gobj
开发者ID:datalogics,项目名称:pyrax,代码行数:22,代码来源:test_cf_client.py
注:本文中的pyrax.utils.get_checksum函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论