diff options
Diffstat (limited to 'Tools/Scripts/webkitpy/common/system')
-rwxr-xr-x | Tools/Scripts/webkitpy/common/system/autoinstall.py | 4 | ||||
-rw-r--r-- | Tools/Scripts/webkitpy/common/system/filesystem.py | 3 | ||||
-rw-r--r-- | Tools/Scripts/webkitpy/common/system/filesystem_mock.py | 30 |
3 files changed, 35 insertions, 2 deletions
diff --git a/Tools/Scripts/webkitpy/common/system/autoinstall.py b/Tools/Scripts/webkitpy/common/system/autoinstall.py index 9adab29..4ffcccc 100755 --- a/Tools/Scripts/webkitpy/common/system/autoinstall.py +++ b/Tools/Scripts/webkitpy/common/system/autoinstall.py @@ -61,7 +61,7 @@ class AutoInstaller(object): installer.install(url="http://pypi.python.org/packages/source/p/pep8/pep8-0.5.0.tar.gz#md5=512a818af9979290cd619cce8e9c2e2b", url_subpath="pep8-0.5.0/pep8.py") - installer.install(url="http://pypi.python.org/packages/source/m/mechanize/mechanize-0.1.11.zip", + installer.install(url="http://pypi.python.org/packages/source/m/mechanize/mechanize-0.2.4.zip", url_subpath="mechanize") """ @@ -512,6 +512,6 @@ if __name__=="__main__": url_subpath="pep8-0.5.0/pep8.py") installer.install(should_refresh=False, target_name="mechanize", - url="http://pypi.python.org/packages/source/m/mechanize/mechanize-0.1.11.zip", + url="http://pypi.python.org/packages/source/m/mechanize/mechanize-0.2.4.zip", url_subpath="mechanize") diff --git a/Tools/Scripts/webkitpy/common/system/filesystem.py b/Tools/Scripts/webkitpy/common/system/filesystem.py index b876807..1988546 100644 --- a/Tools/Scripts/webkitpy/common/system/filesystem.py +++ b/Tools/Scripts/webkitpy/common/system/filesystem.py @@ -195,6 +195,9 @@ class FileSystem(object): mode = 'a' return codecs.open(path, mode, 'utf8') + def open_binary_file_for_reading(self, path): + return codecs.open(path, 'rb') + def read_binary_file(self, path): """Return the contents of the file at the given path as a byte string.""" with file(path, 'rb') as f: diff --git a/Tools/Scripts/webkitpy/common/system/filesystem_mock.py b/Tools/Scripts/webkitpy/common/system/filesystem_mock.py index aa79a8c..a6d158a 100644 --- a/Tools/Scripts/webkitpy/common/system/filesystem_mock.py +++ b/Tools/Scripts/webkitpy/common/system/filesystem_mock.py @@ -228,6 +228,11 @@ class MockFileSystem(object): def read_text_file(self, path): return self.read_binary_file(path).decode('utf-8') + def open_binary_file_for_reading(self, path): + if self.files[path] is None: + self._raise_not_found(path) + return ReadableFileObject(self, path, self.files[path]) + def read_binary_file(self, path): # Intentionally raises KeyError if we don't recognize the path. if self.files[path] is None: @@ -285,3 +290,28 @@ class WritableFileObject(object): def write(self, str): self.fs.files[self.path] += str self.fs.written_files[self.path] = self.fs.files[self.path] + + +class ReadableFileObject(object): + def __init__(self, fs, path, data=""): + self.fs = fs + self.path = path + self.closed = False + self.data = data + self.offset = 0 + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + + def close(self): + self.closed = True + + def read(self, bytes=None): + if not bytes: + return self.data[self.offset:] + start = self.offset + self.offset += bytes + return self.data[start:self.offset] |