def test_evenly_divisible(self): self.tmp.write('01234567') chunks = utils.f_chunk(self.tmp, 2) assert len(chunks) == 4 for r in range(4): assert utils.f_sizeof(chunks[r]) == 2 assert chunks[r].read() == '{}{}'.format(r * 2, r * 2 + 1) chunks[r].close() assert chunks[r].closed
def test_evenly_divisible(self): self.tmp.write('01234567') chunks = utils.f_chunk(self.tmp, 2) assert len(chunks) == 4 for r in range(4): assert utils.f_sizeof(chunks[r]) == 2 assert chunks[r].read() == '{}{}'.format(r*2, r*2+1) chunks[r].close() assert chunks[r].closed
def upload(self, f): """Upload file like object to s3 with this key's configuration.""" try: log.info("upload: {} <- {}".format(self.pretty_path, f.name)) except AttributeError: log.info("upload: {}".format(self.pretty_path)) if utils.f_sizeof(f) <= constants.MULTIPART_CUTOFF: self._basic_upload(f) else: self._multipart_upload(f) self.sync_acl()
def _is_unmodified(self, s3_key): local_path = self._get_local_path_from_key(s3_key.name) with open(local_path, 'rb') as f: if utils.f_sizeof(f) != s3_key.size: return False if not '-' in s3_key.md5: local_md5 = hexlify(utils.f_md5(f)) else: chunks = utils.f_chunk(f, constants.MULTIPART_PART_SIZE) m = hashlib.md5() for chunk in chunks: m.update(utils.f_md5(chunk)) local_md5 = "{}-{}".format(hexlify(m.digest()), len(chunks)) return local_md5 == s3_key.md5
def test_f_sizeof(): s = StringIO('hello') s.seek(2, 0) assert utils.f_sizeof(s) == 5 assert s.tell() == 2
def upload_from_file(self, f): if utils.f_sizeof(f) <= constants.MULTIPART_CUTOFF: self._basic_upload(f) else: self._multipart_upload(f)