OLD | NEW |
| (Empty) |
1 # -*- coding: utf-8 -*- | |
2 # Copyright 2012 Google Inc. All Rights Reserved. | |
3 # | |
4 # Licensed under the Apache License, Version 2.0 (the "License"); | |
5 # you may not use this file except in compliance with the License. | |
6 # You may obtain a copy of the License at | |
7 # | |
8 # http://www.apache.org/licenses/LICENSE-2.0 | |
9 # | |
10 # Unless required by applicable law or agreed to in writing, software | |
11 # distributed under the License is distributed on an "AS IS" BASIS, | |
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 # See the License for the specific language governing permissions and | |
14 # limitations under the License. | |
15 """Class that holds state for instantiating StorageUri objects. | |
16 | |
17 The StorageUri func defined in this class uses that state | |
18 (bucket_storage_uri_class and debug) needed plus gsutil default flag values to | |
19 instantiate this frequently constructed object with just one param for most | |
20 cases. | |
21 """ | |
22 | |
23 from __future__ import absolute_import | |
24 | |
25 import boto | |
26 | |
27 | |
28 class StorageUriBuilder(object): | |
29 """Class for instantiating StorageUri objects.""" | |
30 | |
31 def __init__(self, debug, bucket_storage_uri_class): | |
32 """Initializes the builder. | |
33 | |
34 Args: | |
35 debug: Debug level to pass in to boto connection (range 0..3). | |
36 bucket_storage_uri_class: Class to instantiate for cloud StorageUris. | |
37 Settable for testing/mocking. | |
38 """ | |
39 self.bucket_storage_uri_class = bucket_storage_uri_class | |
40 self.debug = debug | |
41 | |
42 def StorageUri(self, uri_str): | |
43 """Instantiates StorageUri using class state and gsutil default flag values. | |
44 | |
45 Args: | |
46 uri_str: StorageUri naming bucket or object. | |
47 | |
48 Returns: | |
49 boto.StorageUri for given uri_str. | |
50 | |
51 Raises: | |
52 InvalidUriError: if uri_str not valid. | |
53 """ | |
54 return boto.storage_uri( | |
55 uri_str, 'file', debug=self.debug, validate=False, | |
56 bucket_storage_uri_class=self.bucket_storage_uri_class, | |
57 suppress_consec_slashes=False) | |
OLD | NEW |