2828And you are able to ``grant`` and ``revoke`` the following roles:
2929
3030- **Reading**:
31- :func:`ACL.Entity. grant_read` and :func:`ACL.Entity .revoke_read`
31+ :func:`_ACLEntity. grant_read` and :func:`_ACLEntity .revoke_read`
3232- **Writing**:
33- :func:`ACL.Entity. grant_write` and :func:`ACL.Entity .revoke_write`
33+ :func:`_ACLEntity. grant_write` and :func:`_ACLEntity .revoke_write`
3434- **Owning**:
35- :func:`ACL.Entity. grant_owner` and :func:`ACL.Entity .revoke_owner`
35+ :func:`_ACLEntity. grant_owner` and :func:`_ACLEntity .revoke_owner`
3636
3737You can use any of these like any other factory method
38- (these happen to be :class:`ACL.Entity ` factories)::
38+ (these happen to be :class:`_ACLEntity ` factories)::
3939
4040 >>> acl.user('[email protected] ').grant_read() 4141 >>> acl.all_authenticated().grant_write()
7272"""
7373
7474
75- class ACL (object ):
76- """Container class representing a list of access controls."""
75+ class _ACLEntity (object ):
76+ """Class representing a set of roles for an entity.
77+
78+ This is a helper class that you likely won't ever construct
79+ outside of using the factor methods on the :class:`ACL` object.
80+ """
7781
7882 READER_ROLE = 'READER'
7983 WRITER_ROLE = 'WRITER'
8084 OWNER_ROLE = 'OWNER'
8185
82- class Entity ( object ):
83- """Class representing a set of roles for an entity .
86+ def __init__ ( self , entity_type , identifier = None ):
87+ """Entity constructor .
8488
85- This is a helper class that you likely won't ever construct
86- outside of using the factor methods on the :class:`ACL` object.
87- """
88-
89- def __init__ (self , entity_type , identifier = None ):
90- """Entity constructor.
89+ :type entity_type: string
90+ :param entity_type: The type of entity (ie, 'group' or 'user').
9191
92- :type entity_type: string
93- :param entity_type: The type of entity (ie, 'group' or 'user').
92+ :type identifier: string
93+ :param identifier: The ID or e-mail of the entity. For the special
94+ entity types (like 'allUsers') this is optional.
95+ """
96+ self .identifier = identifier
97+ self .roles = set ([])
98+ self .type = entity_type
9499
95- :type identifier: string
96- :param identifier: The ID or e-mail of the entity. For the special
97- entity types (like 'allUsers') this is optional.
98- """
100+ def __str__ (self ):
101+ if not self .identifier :
102+ return str (self .type )
103+ else :
104+ return '{self.type}-{self.identifier}' .format (self = self )
99105
100- self . identifier = identifier
101- self . roles = set ([])
102- self . type = entity_type
106+ def __repr__ ( self ):
107+ return '<ACL Entity: { self} ({roles})>' . format (
108+ self = self , roles = ', ' . join ( self . roles ))
103109
104- def __str__ (self ):
105- if not self .identifier :
106- return str (self .type )
107- else :
108- return '{self.type}-{self.identifier}' .format (self = self )
110+ def get_roles (self ):
111+ """Get the list of roles permitted by this entity.
109112
110- def __repr__ ( self ):
111- return '<ACL Entity: {self} ({roles})>' . format (
112- self = self , roles = ', ' . join ( self . roles ))
113+ :rtype: list of strings
114+ :returns: The list of roles associated with this entity.
115+ """
113116
114- def get_roles (self ):
115- """Get the list of roles permitted by this entity.
117+ return self .roles
116118
117- :rtype: list of strings
118- :returns: The list of roles associated with this entity.
119- """
119+ def grant (self , role ):
120+ """Add a role to the entity.
120121
121- return self .roles
122+ :type role: string
123+ :param role: The role to add to the entity.
122124
123- def grant (self , role ):
124- """Add a role to the entity.
125+ :rtype: :class:`_ACLEntity`
126+ :returns: The entity class.
127+ """
125128
126- :type role: string
127- :param role: The role to add to the entity.
129+ self . roles . add ( role )
130+ return self
128131
129- :rtype: :class:`ACL.Entity`
130- :returns: The entity class.
131- """
132+ def revoke (self , role ):
133+ """Remove a role from the entity.
132134
133- self . roles . add ( role )
134- return self
135+ :type role: string
136+ :param role: The role to remove from the entity.
135137
136- def revoke (self , role ):
137- """Remove a role from the entity.
138+ :rtype: :class:`_ACLEntity`
139+ :returns: The entity class.
140+ """
138141
139- :type role: string
140- :param role: The role to remove from the entity.
142+ if role in self .roles :
143+ self .roles .remove (role )
144+ return self
141145
142- :rtype: :class:`ACL.Entity`
143- :returns: The entity class.
144- """
146+ def grant_read (self ):
147+ """Grant read access to the current entity."""
145148
146- if role in self .roles :
147- self .roles .remove (role )
148- return self
149+ return self .grant (_ACLEntity .READER_ROLE )
149150
150- def grant_read (self ):
151- """Grant read access to the current entity."""
151+ def grant_write (self ):
152+ """Grant write access to the current entity."""
152153
153- return self .grant (ACL . READER_ROLE )
154+ return self .grant (_ACLEntity . WRITER_ROLE )
154155
155- def grant_write (self ):
156- """Grant write access to the current entity."""
156+ def grant_owner (self ):
157+ """Grant owner access to the current entity."""
157158
158- return self .grant (ACL . WRITER_ROLE )
159+ return self .grant (_ACLEntity . OWNER_ROLE )
159160
160- def grant_owner (self ):
161- """Grant owner access to the current entity."""
161+ def revoke_read (self ):
162+ """Revoke read access from the current entity."""
162163
163- return self .grant ( ACL . OWNER_ROLE )
164+ return self .revoke ( _ACLEntity . READER_ROLE )
164165
165- def revoke_read (self ):
166- """Revoke read access from the current entity."""
166+ def revoke_write (self ):
167+ """Revoke write access from the current entity."""
167168
168- return self .revoke (ACL . READER_ROLE )
169+ return self .revoke (_ACLEntity . WRITER_ROLE )
169170
170- def revoke_write (self ):
171- """Revoke write access from the current entity."""
171+ def revoke_owner (self ):
172+ """Revoke owner access from the current entity."""
172173
173- return self .revoke (ACL . WRITER_ROLE )
174+ return self .revoke (_ACLEntity . OWNER_ROLE )
174175
175- def revoke_owner (self ):
176- """Revoke owner access from the current entity."""
177176
178- return self .revoke (ACL .OWNER_ROLE )
177+ class ACL (object ):
178+ """Container class representing a list of access controls."""
179179
180180 def __init__ (self ):
181181 self .entities = {}
@@ -187,7 +187,7 @@ def __iter__(self):
187187 yield {'entity' : str (entity ), 'role' : role }
188188
189189 def entity_from_dict (self , entity_dict ):
190- """Build an ACL.Entity object from a dictionary of data.
190+ """Build an _ACLEntity object from a dictionary of data.
191191
192192 An entity is a mutable object
193193 that represents a list of roles
@@ -199,7 +199,7 @@ def entity_from_dict(self, entity_dict):
199199 :type entity_dict: dict
200200 :param entity_dict: Dictionary full of data from an ACL lookup.
201201
202- :rtype: :class:`ACL.Entity `
202+ :rtype: :class:`_ACLEntity `
203203 :returns: An Entity constructed from the dictionary.
204204 """
205205
@@ -217,15 +217,15 @@ def entity_from_dict(self, entity_dict):
217217 entity = self .entity (entity_type = entity_type ,
218218 identifier = identifier )
219219
220- if not isinstance (entity , ACL . Entity ):
220+ if not isinstance (entity , _ACLEntity ):
221221 raise ValueError ('Invalid dictionary: %s' % entity_dict )
222222
223223 return entity .grant (role )
224224
225225 def has_entity (self , entity ):
226226 """Returns whether or not this ACL has any entries for an entity.
227227
228- :type entity: :class:`ACL.Entity `
228+ :type entity: :class:`_ACLEntity `
229229 :param entity: The entity to check for existence in this ACL.
230230
231231 :rtype: bool
@@ -237,14 +237,14 @@ def has_entity(self, entity):
237237 def get_entity (self , entity , default = None ):
238238 """Gets an entity object from the ACL.
239239
240- :type entity: :class:`ACL.Entity ` or string
240+ :type entity: :class:`_ACLEntity ` or string
241241 :param entity: The entity to get lookup in the ACL.
242242
243243 :type default: anything
244244 :param default: This value will be returned if the entity
245245 doesn't exist.
246246
247- :rtype: :class:`ACL.Entity `
247+ :rtype: :class:`_ACLEntity `
248248 :returns: The corresponding entity or the value provided
249249 to ``default``.
250250 """
@@ -254,7 +254,7 @@ def get_entity(self, entity, default=None):
254254 def add_entity (self , entity ):
255255 """Add an entity to the ACL.
256256
257- :type entity: :class:`ACL.Entity `
257+ :type entity: :class:`_ACLEntity `
258258 :param entity: The entity to add to this ACL.
259259 """
260260
@@ -276,11 +276,11 @@ def entity(self, entity_type, identifier=None):
276276 :param identifier: The ID of the entity (if applicable).
277277 This can be either an ID or an e-mail address.
278278
279- :rtype: :class:`ACL.Entity `
280- :returns: A new Entity or a refernece to an existing identical entity.
279+ :rtype: :class:`_ACLEntity `
280+ :returns: A new Entity or a reference to an existing identical entity.
281281 """
282282
283- entity = ACL . Entity (entity_type = entity_type , identifier = identifier )
283+ entity = _ACLEntity (entity_type = entity_type , identifier = identifier )
284284 if self .has_entity (entity ):
285285 entity = self .get_entity (entity )
286286 else :
@@ -293,7 +293,7 @@ def user(self, identifier):
293293 :type identifier: string
294294 :param identifier: An id or e-mail for this particular user.
295295
296- :rtype: :class:`ACL.Entity `
296+ :rtype: :class:`_ACLEntity `
297297 :returns: An Entity corresponding to this user.
298298 """
299299
@@ -305,7 +305,7 @@ def group(self, identifier):
305305 :type identifier: string
306306 :param identifier: An id or e-mail for this particular group.
307307
308- :rtype: :class:`ACL.Entity `
308+ :rtype: :class:`_ACLEntity `
309309 :returns: An Entity corresponding to this group.
310310 """
311311
@@ -317,7 +317,7 @@ def domain(self, domain):
317317 :type domain: string
318318 :param domain: The domain for this entity.
319319
320- :rtype: :class:`ACL.Entity `
320+ :rtype: :class:`_ACLEntity `
321321 :returns: An entity corresponding to this domain.
322322 """
323323
@@ -326,7 +326,7 @@ def domain(self, domain):
326326 def all (self ):
327327 """Factory method for an Entity representing all users.
328328
329- :rtype: :class:`ACL.Entity `
329+ :rtype: :class:`_ACLEntity `
330330 :returns: An entity representing all users.
331331 """
332332
@@ -335,7 +335,7 @@ def all(self):
335335 def all_authenticated (self ):
336336 """Factory method for an Entity representing all authenticated users.
337337
338- :rtype: :class:`ACL.Entity `
338+ :rtype: :class:`_ACLEntity `
339339 :returns: An entity representing all authenticated users.
340340 """
341341
@@ -344,7 +344,7 @@ def all_authenticated(self):
344344 def get_entities (self ):
345345 """Get a list of all Entity objects.
346346
347- :rtype: list of :class:`ACL.Entity ` objects
347+ :rtype: list of :class:`_ACLEntity ` objects
348348 :returns: A list of all Entity objects.
349349 """
350350
0 commit comments