Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
8121aef8
Commit
8121aef8
authored
Jun 05, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some PEP8 cleanup
parent
85c9193b
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
198 additions
and
138 deletions
+198
-138
src/AccessControl/Permission.py
src/AccessControl/Permission.py
+74
-48
src/AccessControl/Role.py
src/AccessControl/Role.py
+124
-90
No files found.
src/AccessControl/Permission.py
View file @
8121aef8
...
@@ -20,110 +20,135 @@ import string
...
@@ -20,110 +20,135 @@ import string
from
Acquisition
import
aq_base
from
Acquisition
import
aq_base
name_trans
=
filter
(
lambda
c
,
an
=
string
.
letters
+
string
.
digits
+
'_'
:
c
not
in
an
,
name_trans
=
filter
(
lambda
c
,
an
=
string
.
letters
+
string
.
digits
+
'_'
:
c
not
in
an
,
map
(
chr
,
range
(
256
)))
map
(
chr
,
range
(
256
)))
name_trans
=
string
.
maketrans
(
''
.
join
(
name_trans
),
'_'
*
len
(
name_trans
))
name_trans
=
string
.
maketrans
(
''
.
join
(
name_trans
),
'_'
*
len
(
name_trans
))
def
pname
(
name
,
translate
=
string
.
translate
,
name_trans
=
name_trans
):
def
pname
(
name
,
translate
=
string
.
translate
,
name_trans
=
name_trans
):
return
'_'
+
translate
(
name
,
name_trans
)
+
"_Permission"
return
'_'
+
translate
(
name
,
name_trans
)
+
"_Permission"
_marker
=
[]
_marker
=
[]
class
Permission
:
class
Permission
:
# A Permission maps a named logical permission to a set
# A Permission maps a named logical permission to a set
# of attribute names. Attribute names which appear in a
# of attribute names. Attribute names which appear in a
# permission may not appear in any other permission defined
# permission may not appear in any other permission defined
# by the object.
# by the object.
def
__init__
(
self
,
name
,
data
,
obj
,
default
=
None
):
def
__init__
(
self
,
name
,
data
,
obj
,
default
=
None
):
self
.
name
=
name
self
.
name
=
name
self
.
_p
=
'_'
+
string
.
translate
(
name
,
name_trans
)
+
"_Permission"
self
.
_p
=
'_'
+
string
.
translate
(
name
,
name_trans
)
+
"_Permission"
self
.
data
=
data
self
.
data
=
data
self
.
obj
=
aq_base
(
obj
)
self
.
obj
=
aq_base
(
obj
)
self
.
default
=
default
self
.
default
=
default
def
getRoles
(
self
,
default
=
_marker
):
def
getRoles
(
self
,
default
=
_marker
):
# Return the list of role names which have been given
# Return the list of role names which have been given
# this permission for the object in question. To do
# this permission for the object in question. To do
# this, we try to get __roles__ from all of the object
# this, we try to get __roles__ from all of the object
# attributes that this permission represents.
# attributes that this permission represents.
obj
=
self
.
obj
obj
=
self
.
obj
name
=
self
.
_p
name
=
self
.
_p
if
hasattr
(
obj
,
name
):
return
getattr
(
obj
,
name
)
if
hasattr
(
obj
,
name
):
roles
=
default
return
getattr
(
obj
,
name
)
roles
=
default
for
name
in
self
.
data
:
for
name
in
self
.
data
:
if
name
:
if
name
:
if
hasattr
(
obj
,
name
):
if
hasattr
(
obj
,
name
):
attr
=
getattr
(
obj
,
name
)
attr
=
getattr
(
obj
,
name
)
if
hasattr
(
attr
,
'im_self'
):
if
hasattr
(
attr
,
'im_self'
):
attr
=
attr
.
im_self
attr
=
attr
.
im_self
if
hasattr
(
attr
,
'__dict__'
):
if
hasattr
(
attr
,
'__dict__'
):
attr
=
attr
.
__dict__
attr
=
attr
.
__dict__
name
=
name
+
'__roles__'
name
=
name
+
'__roles__'
if
attr
.
has_key
(
name
)
:
if
name
in
attr
:
roles
=
attr
[
name
]
roles
=
attr
[
name
]
break
break
elif
hasattr
(
obj
,
'__dict__'
):
elif
hasattr
(
obj
,
'__dict__'
):
attr
=
obj
.
__dict__
attr
=
obj
.
__dict__
if
attr
.
has_key
(
'__roles__'
)
:
if
'__roles__'
in
attr
:
roles
=
attr
[
'__roles__'
]
roles
=
attr
[
'__roles__'
]
break
break
if
roles
:
if
roles
:
try
:
try
:
if
'Shared'
not
in
roles
:
return
tuple
(
roles
)
if
'Shared'
not
in
roles
:
roles
=
list
(
roles
)
return
tuple
(
roles
)
roles
=
list
(
roles
)
roles
.
remove
(
'Shared'
)
roles
.
remove
(
'Shared'
)
return
roles
return
roles
except
:
return
[]
except
:
return
[]
if
roles
is
None
:
return
[
'Manager'
,
'Anonymous'
]
if
roles
is
None
:
if
roles
is
_marker
:
return
[
'Manager'
]
return
[
'Manager'
,
'Anonymous'
]
if
roles
is
_marker
:
return
[
'Manager'
]
return
roles
return
roles
def
setRoles
(
self
,
roles
):
def
setRoles
(
self
,
roles
):
obj
=
self
.
obj
obj
=
self
.
obj
if
isinstance
(
roles
,
list
)
and
not
roles
:
if
isinstance
(
roles
,
list
)
and
not
roles
:
if
hasattr
(
obj
,
self
.
_p
):
delattr
(
obj
,
self
.
_p
)
if
hasattr
(
obj
,
self
.
_p
):
delattr
(
obj
,
self
.
_p
)
else
:
else
:
setattr
(
obj
,
self
.
_p
,
roles
)
setattr
(
obj
,
self
.
_p
,
roles
)
for
name
in
self
.
data
:
for
name
in
self
.
data
:
if
name
==
''
:
attr
=
obj
if
name
==
''
:
else
:
attr
=
getattr
(
obj
,
name
)
attr
=
obj
try
:
del
attr
.
__roles__
else
:
except
:
pass
attr
=
getattr
(
obj
,
name
)
try
:
delattr
(
obj
,
name
+
'__roles__'
)
try
:
except
:
pass
del
attr
.
__roles__
except
:
pass
try
:
delattr
(
obj
,
name
+
'__roles__'
)
except
:
pass
def
setRole
(
self
,
role
,
present
):
def
setRole
(
self
,
role
,
present
):
roles
=
self
.
getRoles
()
roles
=
self
.
getRoles
()
if
role
in
roles
:
if
role
in
roles
:
if
present
:
return
if
present
:
if
isinstance
(
roles
,
list
):
roles
.
remove
(
role
)
return
if
isinstance
(
roles
,
list
):
roles
.
remove
(
role
)
else
:
else
:
roles
=
list
(
roles
)
roles
=
list
(
roles
)
roles
.
remove
(
role
)
roles
.
remove
(
role
)
roles
=
tuple
(
roles
)
roles
=
tuple
(
roles
)
elif
not
present
:
return
elif
not
present
:
return
else
:
else
:
if
isinstance
(
roles
,
list
):
roles
.
append
(
role
)
if
isinstance
(
roles
,
list
):
else
:
roles
=
roles
+
(
role
,)
roles
.
append
(
role
)
else
:
roles
=
roles
+
(
role
,
)
self
.
setRoles
(
roles
)
self
.
setRoles
(
roles
)
def
__len__
(
self
):
return
1
def
__len__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
1
def
__str__
(
self
):
return
self
.
name
_registeredPermissions
=
{}
_registeredPermissions
=
{}
_registerdPermission
=
_registeredPermissions
.
has_key
_registerdPermission
=
_registeredPermissions
.
has_key
def
registerPermissions
(
permissions
,
defaultDefault
=
(
'Manager'
,)):
def
registerPermissions
(
permissions
,
defaultDefault
=
(
'Manager'
,
)):
"""Register an __ac_permissions__ sequence.
"""Register an __ac_permissions__ sequence.
"""
"""
import
Products
import
Products
for
setting
in
permissions
:
for
setting
in
permissions
:
if
_registerdPermission
(
setting
[
0
]):
continue
if
_registerdPermission
(
setting
[
0
]):
continue
if
len
(
setting
)
==
2
:
if
len
(
setting
)
==
2
:
perm
,
methods
=
setting
perm
,
methods
=
setting
default
=
defaultDefault
default
=
defaultDefault
...
@@ -132,12 +157,13 @@ def registerPermissions(permissions, defaultDefault=('Manager',)):
...
@@ -132,12 +157,13 @@ def registerPermissions(permissions, defaultDefault=('Manager',)):
_registeredPermissions
[
perm
]
=
1
_registeredPermissions
[
perm
]
=
1
Products_permissions
=
getattr
(
Products
,
'__ac_permissions__'
,
())
Products_permissions
=
getattr
(
Products
,
'__ac_permissions__'
,
())
Products
.
__ac_permissions__
=
(
Products
.
__ac_permissions__
=
(
Products_permissions
+
((
perm
,
(),
default
),))
Products_permissions
+
((
perm
,
(),
default
),
))
mangled
=
pname
(
perm
)
# get mangled permission name
mangled
=
pname
(
perm
)
# get mangled permission name
if
not
hasattr
(
ApplicationDefaultPermissions
,
mangled
):
if
not
hasattr
(
ApplicationDefaultPermissions
,
mangled
):
setattr
(
ApplicationDefaultPermissions
,
setattr
(
ApplicationDefaultPermissions
,
mangled
,
default
)
mangled
,
default
)
class
ApplicationDefaultPermissions
:
class
ApplicationDefaultPermissions
:
_View_Permission
=
(
'Manager'
,
'Anonymous'
)
_View_Permission
=
(
'Manager'
,
'Anonymous'
)
_Access_contents_information_Permission
=
(
'Manager'
,
'Anonymous'
)
_Access_contents_information_Permission
=
(
'Manager'
,
'Anonymous'
)
src/AccessControl/Role.py
View file @
8121aef8
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment