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
afb56604
Commit
afb56604
authored
Aug 07, 2000
by
Shane Hathaway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
__replaceable__ property implementation.
parent
8e9322c0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
12 deletions
+36
-12
lib/python/OFS/ObjectManager.py
lib/python/OFS/ObjectManager.py
+36
-12
No files found.
lib/python/OFS/ObjectManager.py
View file @
afb56604
...
@@ -84,9 +84,9 @@
...
@@ -84,9 +84,9 @@
##############################################################################
##############################################################################
__doc__
=
"""Object Manager
__doc__
=
"""Object Manager
$Id: ObjectManager.py,v 1.10
2 2000/08/04 13:59:33 jim
Exp $"""
$Id: ObjectManager.py,v 1.10
3 2000/08/07 18:31:21 shane
Exp $"""
__version__
=
'$Revision: 1.10
2
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.10
3
$'
[
11
:
-
2
]
import
App.Management
,
Acquisition
,
Globals
,
CopySupport
,
Products
import
App.Management
,
Acquisition
,
Globals
,
CopySupport
,
Products
import
os
,
App
.
FactoryDispatcher
,
ts_regex
,
Products
import
os
,
App
.
FactoryDispatcher
,
ts_regex
,
Products
...
@@ -109,6 +109,11 @@ customImporters={
...
@@ -109,6 +109,11 @@ customImporters={
bad_id
=
ts_regex
.
compile
(
'[^a-zA-Z0-9-_~
\
,
\
. ]'
).
search
#TS
bad_id
=
ts_regex
.
compile
(
'[^a-zA-Z0-9-_~
\
,
\
. ]'
).
search
#TS
# Global constants: __replaceable__ states (see ObjectManager._checkId):
NOT_REPLACEABLE
=
0
REPLACEABLE
=
1
UNIQUE
=
-
1
class
BeforeDeleteException
(
Exception
):
pass
# raise to veto deletion
class
BeforeDeleteException
(
Exception
):
pass
# raise to veto deletion
_marker
=
[]
_marker
=
[]
...
@@ -206,25 +211,37 @@ class ObjectManager(
...
@@ -206,25 +211,37 @@ class ObjectManager(
def
_checkId
(
self
,
id
,
allow_dup
=
0
):
def
_checkId
(
self
,
id
,
allow_dup
=
0
):
# If allow_dup is false, an error will be raised if an object
# If allow_dup is false, an error will be raised if an object
# with the given id already exists. If allow_dup is true,
# with the given id already exists. If allow_dup is true,
# only check that the id string contains no illegal chars.
# only check that the id string contains no illegal chars;
# _checkId() will be called again later with allow_dup
# set to false before the object is added.
if
not
id
or
(
type
(
id
)
!=
type
(
''
)):
if
not
id
or
(
type
(
id
)
!=
type
(
''
)):
raise
'Bad Request'
,
'Empty or invalid
specified
'
raise
'Bad Request'
,
'Empty or invalid
id specified.
'
if
bad_id
(
id
)
!=
-
1
:
if
bad_id
(
id
)
!=
-
1
:
raise
'Bad Request'
,
(
raise
'Bad Request'
,
(
'The id
%s
contains characters illegal in URLs.'
%
id
)
'The id
"%s"
contains characters illegal in URLs.'
%
id
)
if
id
[
0
]
==
'_'
:
raise
'Bad Request'
,
(
if
id
[
0
]
==
'_'
:
raise
'Bad Request'
,
(
'The id
%s
is invalid - it begins with an underscore.'
%
id
)
'The id
"%s"
is invalid - it begins with an underscore.'
%
id
)
if
not
allow_dup
:
if
not
allow_dup
:
if
hasattr
(
self
,
'aq_base'
):
obj
=
getattr
(
self
,
id
,
None
)
self
=
self
.
aq_base
if
obj
is
not
None
:
if
hasattr
(
self
,
id
):
# An object by the given id exists either in this
raise
'Bad Request'
,
(
# ObjectManager or in the acquisition path.
'The id %s is invalid - it is already in use.'
%
id
)
print
obj
,
dir
(
obj
)
flag
=
getattr
(
obj
,
'__replaceable__'
,
NOT_REPLACEABLE
)
if
flag
==
UNIQUE
:
raise
'Bad Request'
,
\
(
'The id "%s" is reserved by another object.'
%
id
)
base
=
getattr
(
self
,
'aq_base'
,
self
)
if
hasattr
(
base
,
id
):
# The object is located in this ObjectManager.
if
flag
!=
REPLACEABLE
:
raise
'Bad Request'
,
(
'The id "%s" is invalid - '
\
'it is already in use.'
%
id
)
if
id
==
'REQUEST'
:
if
id
==
'REQUEST'
:
raise
'Bad Request'
,
'REQUEST is a reserved name.'
raise
'Bad Request'
,
'REQUEST is a reserved name.'
if
'/'
in
id
:
if
'/'
in
id
:
raise
'Bad Request'
,
(
raise
'Bad Request'
,
(
'The id
%s
contains characters illegal in URLs.'
%
id
'The id
"%s"
contains characters illegal in URLs.'
%
id
)
)
def
_setOb
(
self
,
id
,
object
):
setattr
(
self
,
id
,
object
)
def
_setOb
(
self
,
id
,
object
):
setattr
(
self
,
id
,
object
)
...
@@ -244,6 +261,13 @@ class ObjectManager(
...
@@ -244,6 +261,13 @@ class ObjectManager(
if
v
is
not
None
:
id
=
v
if
v
is
not
None
:
id
=
v
try
:
t
=
object
.
meta_type
try
:
t
=
object
.
meta_type
except
:
t
=
None
except
:
t
=
None
# If an object by the given id already exists, remove it.
for
object_info
in
self
.
_objects
:
if
object_info
[
'id'
]
==
id
:
self
.
_delObject
(
id
)
break
self
.
_objects
=
self
.
_objects
+
({
'id'
:
id
,
'meta_type'
:
t
},)
self
.
_objects
=
self
.
_objects
+
({
'id'
:
id
,
'meta_type'
:
t
},)
# Prepare the _p_jar attribute immediately. _getCopy() may need it.
# Prepare the _p_jar attribute immediately. _getCopy() may need it.
object
.
_p_jar
=
self
.
_p_jar
object
.
_p_jar
=
self
.
_p_jar
...
...
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