1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Abstract injector class for GS requests."""
8 class FileNotFoundError(Exception):
9 """Thrown by a subclass of CloudBucket when a file is not found."""
13 class BaseCloudBucket(object):
14 """An abstract base class for working with GS."""
16 def UploadFile(self
, path
, contents
, content_type
):
17 """Uploads a file to GS.
20 path: where in GS to upload the file.
21 contents: the contents of the file to be uploaded.
22 content_type: the MIME Content-Type of the file.
24 raise NotImplementedError
26 def DownloadFile(self
, path
):
27 """Downsloads a file from GS.
30 path: the location in GS to download the file from.
33 String contents of the file downloaded.
36 bucket_injector.NotFoundException: if the file is not found.
38 raise NotImplementedError
40 def UpdateFile(self
, path
, contents
):
41 """Uploads a file to GS.
44 path: location of the file in GS to update.
45 contents: the contents of the file to be updated.
47 raise NotImplementedError
49 def RemoveFile(self
, path
):
50 """Removes a file from GS.
53 path: the location in GS to download the file from.
55 raise NotImplementedError
57 def FileExists(self
, path
):
58 """Checks if a file exists in GS.
61 path: the location in GS of the file.
64 boolean representing whether the file exists in GS.
66 raise NotImplementedError
68 def GetImageURL(self
, path
):
69 """Gets a URL to an item in GS from its path.
72 path: the location in GS of a file.
75 an url to a file in GS.
78 bucket_injector.NotFoundException: if the file is not found.
80 raise NotImplementedError
82 def GetAllPaths(self
, prefix
):
83 """Gets paths to files in GS that start with a prefix.
86 prefix: the prefix to filter files in GS.
89 a generator of paths to files in GS.
91 raise NotImplementedError