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

Side by Side Diff: third_party/boto/s3/acl.py

Issue 12633019: Added boto/ to depot_tools/third_party (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Moved boto down by one Created 7 years, 9 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
« no previous file with comments | « third_party/boto/s3/__init__.py ('k') | third_party/boto/s3/bucket.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21
22 from boto.s3.user import User
23
24
25 CannedACLStrings = ['private', 'public-read',
26 'public-read-write', 'authenticated-read',
27 'bucket-owner-read', 'bucket-owner-full-control',
28 'log-delivery-write']
29
30
31 class Policy:
32
33 def __init__(self, parent=None):
34 self.parent = parent
35 self.acl = None
36
37 def __repr__(self):
38 grants = []
39 for g in self.acl.grants:
40 if g.id == self.owner.id:
41 grants.append("%s (owner) = %s" % (g.display_name, g.permission) )
42 else:
43 if g.type == 'CanonicalUser':
44 u = g.display_name
45 elif g.type == 'Group':
46 u = g.uri
47 else:
48 u = g.email_address
49 grants.append("%s = %s" % (u, g.permission))
50 return "<Policy: %s>" % ", ".join(grants)
51
52 def startElement(self, name, attrs, connection):
53 if name == 'Owner':
54 self.owner = User(self)
55 return self.owner
56 elif name == 'AccessControlList':
57 self.acl = ACL(self)
58 return self.acl
59 else:
60 return None
61
62 def endElement(self, name, value, connection):
63 if name == 'Owner':
64 pass
65 elif name == 'AccessControlList':
66 pass
67 else:
68 setattr(self, name, value)
69
70 def to_xml(self):
71 s = '<AccessControlPolicy>'
72 s += self.owner.to_xml()
73 s += self.acl.to_xml()
74 s += '</AccessControlPolicy>'
75 return s
76
77 class ACL:
78
79 def __init__(self, policy=None):
80 self.policy = policy
81 self.grants = []
82
83 def add_grant(self, grant):
84 self.grants.append(grant)
85
86 def add_email_grant(self, permission, email_address):
87 grant = Grant(permission=permission, type='AmazonCustomerByEmail',
88 email_address=email_address)
89 self.grants.append(grant)
90
91 def add_user_grant(self, permission, user_id, display_name=None):
92 grant = Grant(permission=permission, type='CanonicalUser', id=user_id, d isplay_name=display_name)
93 self.grants.append(grant)
94
95 def startElement(self, name, attrs, connection):
96 if name == 'Grant':
97 self.grants.append(Grant(self))
98 return self.grants[-1]
99 else:
100 return None
101
102 def endElement(self, name, value, connection):
103 if name == 'Grant':
104 pass
105 else:
106 setattr(self, name, value)
107
108 def to_xml(self):
109 s = '<AccessControlList>'
110 for grant in self.grants:
111 s += grant.to_xml()
112 s += '</AccessControlList>'
113 return s
114
115 class Grant:
116
117 NameSpace = 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
118
119 def __init__(self, permission=None, type=None, id=None,
120 display_name=None, uri=None, email_address=None):
121 self.permission = permission
122 self.id = id
123 self.display_name = display_name
124 self.uri = uri
125 self.email_address = email_address
126 self.type = type
127
128 def startElement(self, name, attrs, connection):
129 if name == 'Grantee':
130 self.type = attrs['xsi:type']
131 return None
132
133 def endElement(self, name, value, connection):
134 if name == 'ID':
135 self.id = value
136 elif name == 'DisplayName':
137 self.display_name = value
138 elif name == 'URI':
139 self.uri = value
140 elif name == 'EmailAddress':
141 self.email_address = value
142 elif name == 'Grantee':
143 pass
144 elif name == 'Permission':
145 self.permission = value
146 else:
147 setattr(self, name, value)
148
149 def to_xml(self):
150 s = '<Grant>'
151 s += '<Grantee %s xsi:type="%s">' % (self.NameSpace, self.type)
152 if self.type == 'CanonicalUser':
153 s += '<ID>%s</ID>' % self.id
154 s += '<DisplayName>%s</DisplayName>' % self.display_name
155 elif self.type == 'Group':
156 s += '<URI>%s</URI>' % self.uri
157 else:
158 s += '<EmailAddress>%s</EmailAddress>' % self.email_address
159 s += '</Grantee>'
160 s += '<Permission>%s</Permission>' % self.permission
161 s += '</Grant>'
162 return s
163
164
OLDNEW
« no previous file with comments | « third_party/boto/s3/__init__.py ('k') | third_party/boto/s3/bucket.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698