From d346415f79943a263254d139cd8d990b5eab8db9 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 16 May 2012 16:34:18 -0700 Subject: [PATCH] realistic.py: update seek() implementation seek() requires whence param. Missing it broke readwrite test with boto 2.4.0. Signed-off-by: Yehuda Sadeh --- s3tests/realistic.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/s3tests/realistic.py b/s3tests/realistic.py index 1829048..97de394 100644 --- a/s3tests/realistic.py +++ b/s3tests/realistic.py @@ -6,6 +6,7 @@ import time import math import tempfile import shutil +import os NANOSECOND = int(1e9) @@ -27,10 +28,17 @@ class RandomContentFile(object): def _mark_chunk(self): self.chunks.append([self.offset, int(round((time.time() - self.last_seek) * NANOSECOND))]) - def seek(self, offset): - assert offset == 0 + def seek(self, offset, whence=os.SEEK_SET): + if whence == os.SEEK_SET: + self.offset = offset + elif whence == os.SEEK_END: + self.offset = self.size + offset; + elif whence == os.SEEK_CUR: + self.offset += offset + + assert self.offset == 0 + self.random.seed(self.seed) - self.offset = offset self.buffer = '' self.hash = hashlib.md5() @@ -95,10 +103,10 @@ class PrecomputedContentFile(object): self.last_chunks = self.chunks = None self.seek(0) - def seek(self, offset): - self._file.seek(offset) + def seek(self, offset, whence=os.SEEK_SET): + self._file.seek(offset, whence) - if offset == 0: + if self.tell() == 0: # only reset the chunks when seeking to the beginning self.last_chunks = self.chunks self.last_seek = time.time()