12fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# Copyright (C) 2010 Google Inc. All rights reserved. 22fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# 32fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# Redistribution and use in source and binary forms, with or without 42fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# modification, are permitted provided that the following conditions 52fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# are met: 62fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# 72fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# 1. Redistributions of source code must retain the above copyright 82fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# notice, this list of conditions and the following disclaimer. 92fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# 2. Redistributions in binary form must reproduce the above copyright 102fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# notice, this list of conditions and the following disclaimer in the 112fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# documentation and/or other materials provided with the distribution. 122fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# 132fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 142fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 152fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 162fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 172fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 182fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 192fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 202fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 212fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 222fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 232fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 242fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockfrom webkitpy.common.system.fileset import FileSetFileHandle 252fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockfrom webkitpy.common.system.filesystem_mock import MockFileSystem 262fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 272fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 282fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockclass MockZip(object): 292fc2651226baac27029e38c9d6ef883fa32084dbSteve Block """A mock zip file that can have new files inserted into it.""" 302fc2651226baac27029e38c9d6ef883fa32084dbSteve Block def __init__(self, filesystem=None): 312fc2651226baac27029e38c9d6ef883fa32084dbSteve Block self._filesystem = filesystem or MockFileSystem() 322fc2651226baac27029e38c9d6ef883fa32084dbSteve Block self._files = {} 332fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 342fc2651226baac27029e38c9d6ef883fa32084dbSteve Block def __str__(self): 352fc2651226baac27029e38c9d6ef883fa32084dbSteve Block return "MockZip" 362fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 372fc2651226baac27029e38c9d6ef883fa32084dbSteve Block def insert(self, filename, content): 382fc2651226baac27029e38c9d6ef883fa32084dbSteve Block self._files[filename] = content 392fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 402fc2651226baac27029e38c9d6ef883fa32084dbSteve Block def namelist(self): 412fc2651226baac27029e38c9d6ef883fa32084dbSteve Block return self._files.keys() 422fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 432fc2651226baac27029e38c9d6ef883fa32084dbSteve Block def open(self, filename): 442fc2651226baac27029e38c9d6ef883fa32084dbSteve Block return FileSetFileHandle(self, filename) 452fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 462fc2651226baac27029e38c9d6ef883fa32084dbSteve Block def read(self, filename): 472fc2651226baac27029e38c9d6ef883fa32084dbSteve Block return self._files[filename] 482fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 492fc2651226baac27029e38c9d6ef883fa32084dbSteve Block def extract(self, filename, path): 502fc2651226baac27029e38c9d6ef883fa32084dbSteve Block full_path = self._filesystem.join(path, filename) 512fc2651226baac27029e38c9d6ef883fa32084dbSteve Block contents = self.open(filename).contents() 522fc2651226baac27029e38c9d6ef883fa32084dbSteve Block self._filesystem.write_text_file(full_path, contents) 532fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 542fc2651226baac27029e38c9d6ef883fa32084dbSteve Block def delete(self, filename): 552fc2651226baac27029e38c9d6ef883fa32084dbSteve Block self._files[filename] = None 56