Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: third_party/gsutil/20110627/gslib/project_id.py

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2011 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import boto
16 from gslib.exception import ProjectIdException
17 from gslib.wildcard_iterator import WILDCARD_BUCKET_ITERATOR
18
19 GOOG_PROJ_ID_HDR = 'x-goog-project-id'
20
21
22 class ProjectIdHandler(object):
23 """Google Project ID header handling."""
24
25 def __init__(self):
26 """Instantiates Project ID handler. Call after boto config file loaded."""
27 config = boto.config
28 self.project_id = config.get_value('GSUtil', 'default_project_id', None)
29
30 def SetProjectId(self, project_id):
31 """Overrides project ID value from config file default.
32
33 Args:
34 project_id: project_id to use
35 """
36 self.project_id = project_id
37
38 def FillInProjectHeaderIfNeeded(self, command, uri, headers):
39 """Fills project ID header into headers if defined and applicable.
40
41 Args:
42 command: The command being run.
43 uri: The URI against which this command is being run.
44 headers: dictionary containing optional HTTP headers to pass to boto.
45 Must not be None.
46 """
47
48 # We only include the project ID header if it's a GS URI and a project_id
49 # was specified and
50 # (it's an 'mb' command or
51 # (an 'ls' command that doesn't specify a bucket or a wildcard bucket itera tor)).
52 if (uri.scheme.lower() == 'gs' and self.project_id and
53 (command == 'mb' or
54 (command == 'ls' and not uri.bucket_name) or
55 (command == WILDCARD_BUCKET_ITERATOR))):
56 if headers is None:
57 raise ProjectIdException(
58 'FillInProjectHeaderIfNeeded called with headers=None')
59 headers[GOOG_PROJ_ID_HDR] = self.project_id
60 elif headers.has_key(GOOG_PROJ_ID_HDR):
61 del headers[GOOG_PROJ_ID_HDR]
OLDNEW
« no previous file with comments | « third_party/gsutil/20110627/gslib/exception.py ('k') | third_party/gsutil/20110627/gslib/test_command.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698