1 # -*- coding: utf-8 -*-
2 # Copyright 2012 Google Inc. All Rights Reserved.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
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
23 from __future__
import absolute_import
28 class StorageUriBuilder(object):
29 """Class for instantiating StorageUri objects."""
31 def __init__(self
, debug
, bucket_storage_uri_class
):
32 """Initializes the builder.
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.
39 self
.bucket_storage_uri_class
= bucket_storage_uri_class
42 def StorageUri(self
, uri_str
):
43 """Instantiates StorageUri using class state and gsutil default flag values.
46 uri_str: StorageUri naming bucket or object.
49 boto.StorageUri for given uri_str.
52 InvalidUriError: if uri_str not valid.
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)