Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / tools / telemetry / third_party / gsutilz / gslib / storage_uri_builder.py
blob9d9b9df6e23b79ab5bd06f37ab1e2aabf4050edc
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
20 cases.
21 """
23 from __future__ import absolute_import
25 import boto
28 class StorageUriBuilder(object):
29 """Class for instantiating StorageUri objects."""
31 def __init__(self, debug, bucket_storage_uri_class):
32 """Initializes the builder.
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
42 def StorageUri(self, uri_str):
43 """Instantiates StorageUri using class state and gsutil default flag values.
45 Args:
46 uri_str: StorageUri naming bucket or object.
48 Returns:
49 boto.StorageUri for given uri_str.
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)