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
b8c4aeaa
Commit
b8c4aeaa
authored
Jul 13, 2011
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop using id() methods and define proper getId methods
parent
c8b7bcbe
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
19 deletions
+9
-19
src/OFS/Application.py
src/OFS/Application.py
+1
-1
src/OFS/Image.py
src/OFS/Image.py
+0
-3
src/OFS/SimpleItem.py
src/OFS/SimpleItem.py
+5
-12
src/OFS/tests/testApplication.py
src/OFS/tests/testApplication.py
+3
-3
No files found.
src/OFS/Application.py
View file @
b8c4aeaa
...
@@ -82,7 +82,7 @@ class Application(ApplicationDefaultPermissions,
...
@@ -82,7 +82,7 @@ class Application(ApplicationDefaultPermissions,
self
.
__allow_groups__
=
uf
self
.
__allow_groups__
=
uf
self
.
_setObject
(
'acl_users'
,
uf
)
self
.
_setObject
(
'acl_users'
,
uf
)
def
i
d
(
self
):
def
getI
d
(
self
):
try
:
try
:
return
self
.
REQUEST
[
'SCRIPT_NAME'
][
1
:]
return
self
.
REQUEST
[
'SCRIPT_NAME'
][
1
:]
except
(
KeyError
,
TypeError
):
except
(
KeyError
,
TypeError
):
...
...
src/OFS/Image.py
View file @
b8c4aeaa
...
@@ -141,9 +141,6 @@ class File(Persistent, Implicit, PropertyManager,
...
@@ -141,9 +141,6 @@ class File(Persistent, Implicit, PropertyManager,
content_type
=
self
.
_get_content_type
(
file
,
data
,
id
,
content_type
)
content_type
=
self
.
_get_content_type
(
file
,
data
,
id
,
content_type
)
self
.
update_data
(
data
,
content_type
,
size
)
self
.
update_data
(
data
,
content_type
,
size
)
def
id
(
self
):
return
self
.
__name__
def
_if_modified_since_request_handler
(
self
,
REQUEST
,
RESPONSE
):
def
_if_modified_since_request_handler
(
self
,
REQUEST
,
RESPONSE
):
# HTTP If-Modified-Since header handling: return True if
# HTTP If-Modified-Since header handling: return True if
# we can handle this request by returning a 304 response
# we can handle this request by returning a 304 response
...
...
src/OFS/SimpleItem.py
View file @
b8c4aeaa
...
@@ -91,7 +91,7 @@ class Item(Base,
...
@@ -91,7 +91,7 @@ class Item(Base,
manage_afterClone
.
__five_method__
=
True
manage_afterClone
.
__five_method__
=
True
# Direct use of the 'id' attribute is deprecated - use getId()
# Direct use of the 'id' attribute is deprecated - use getId()
id
=
''
id
=
''
security
.
declarePublic
(
'getId'
)
security
.
declarePublic
(
'getId'
)
def
getId
(
self
):
def
getId
(
self
):
...
@@ -100,17 +100,13 @@ class Item(Base,
...
@@ -100,17 +100,13 @@ class Item(Base,
This method should be used in preference to accessing an id attribute
This method should be used in preference to accessing an id attribute
of an object directly. The getId method is public.
of an object directly. The getId method is public.
"""
"""
name
=
getattr
(
self
,
'id'
,
None
)
name
=
self
.
id
if
callable
(
name
):
return
name
()
if
name
is
not
None
:
if
name
is
not
None
:
return
name
return
name
if
hasattr
(
self
,
'__name__'
):
return
self
.
__name__
return
self
.
__name__
raise
AttributeError
,
'This object has no id'
# Alias id to __name__, which will make tracebacks a good bit nicer:
# Alias id to __name__, which will make tracebacks a good bit nicer:
__name__
=
ComputedAttribute
(
lambda
self
:
self
.
getId
()
)
__name__
=
ComputedAttribute
(
lambda
self
:
self
.
id
)
# Meta type used for selecting all objects of a given type.
# Meta type used for selecting all objects of a given type.
meta_type
=
'simple item'
meta_type
=
'simple item'
...
@@ -377,7 +373,6 @@ InitializeClass(Item)
...
@@ -377,7 +373,6 @@ InitializeClass(Item)
class
Item_w__name__
(
Item
):
class
Item_w__name__
(
Item
):
"""Mixin class to support common name/id functions"""
"""Mixin class to support common name/id functions"""
implements
(
IItemWithName
)
implements
(
IItemWithName
)
...
@@ -411,12 +406,10 @@ class Item_w__name__(Item):
...
@@ -411,12 +406,10 @@ class Item_w__name__(Item):
getPhysicalRoot() and getPhysicalPath() are designed to operate
getPhysicalRoot() and getPhysicalPath() are designed to operate
together.
together.
"""
"""
path
=
(
self
.
__name__
,)
path
=
(
self
.
__name__
,
)
p
=
aq_parent
(
aq_inner
(
self
))
p
=
aq_parent
(
aq_inner
(
self
))
if
p
is
not
None
:
if
p
is
not
None
:
path
=
p
.
getPhysicalPath
()
+
path
path
=
p
.
getPhysicalPath
()
+
path
return
path
return
path
...
...
src/OFS/tests/testApplication.py
View file @
b8c4aeaa
...
@@ -29,17 +29,17 @@ class ApplicationTests(unittest.TestCase):
...
@@ -29,17 +29,17 @@ class ApplicationTests(unittest.TestCase):
def
test_id_no_request
(
self
):
def
test_id_no_request
(
self
):
app
=
self
.
_makeOne
()
app
=
self
.
_makeOne
()
self
.
assertEqual
(
app
.
i
d
(),
'Zope'
)
self
.
assertEqual
(
app
.
getI
d
(),
'Zope'
)
def
test_id_w_request_no_SCRIPT_NAME
(
self
):
def
test_id_w_request_no_SCRIPT_NAME
(
self
):
app
=
self
.
_makeOne
()
app
=
self
.
_makeOne
()
app
.
REQUEST
=
{}
app
.
REQUEST
=
{}
self
.
assertEqual
(
app
.
i
d
(),
'Zope'
)
self
.
assertEqual
(
app
.
getI
d
(),
'Zope'
)
def
test_id_w_request_w_SCRIPT_NAME
(
self
):
def
test_id_w_request_w_SCRIPT_NAME
(
self
):
app
=
self
.
_makeOne
()
app
=
self
.
_makeOne
()
app
.
REQUEST
=
{
'SCRIPT_NAME'
:
'/Dummy'
}
app
.
REQUEST
=
{
'SCRIPT_NAME'
:
'/Dummy'
}
self
.
assertEqual
(
app
.
i
d
(),
'Dummy'
)
self
.
assertEqual
(
app
.
getI
d
(),
'Dummy'
)
def
test_title_and_id_plus_title_or_id
(
self
):
def
test_title_and_id_plus_title_or_id
(
self
):
app
=
self
.
_makeOne
()
app
=
self
.
_makeOne
()
...
...
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