Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodb
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joshua
zodb
Commits
11a251d3
Commit
11a251d3
authored
Apr 30, 2009
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The databasesFrom... methods now support multiple databases.
Added an option to disallow cross-database references.
parent
02b5e591
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
40 deletions
+123
-40
src/ZODB/config.py
src/ZODB/config.py
+20
-5
src/ZODB/config.xml
src/ZODB/config.xml
+2
-1
src/ZODB/tests/testConfig.py
src/ZODB/tests/testConfig.py
+101
-34
No files found.
src/ZODB/config.py
View file @
11a251d3
...
...
@@ -49,8 +49,15 @@ def databaseFromURL(url):
config
,
handler
=
ZConfig
.
loadConfig
(
getDbSchema
(),
url
)
return
databaseFromConfig
(
config
.
database
)
def
databaseFromConfig
(
section
):
return
section
.
open
()
def
databaseFromConfig
(
database_factories
):
databases
=
{}
first
=
None
for
factory
in
database_factories
:
db
=
factory
.
open
(
databases
)
if
first
is
None
:
first
=
db
return
first
def
storageFromString
(
s
):
return
storageFromFile
(
StringIO
(
s
))
...
...
@@ -93,8 +100,16 @@ class ZODBDatabase(BaseConfig):
section
=
self
.
config
storage
=
section
.
storage
.
open
()
options
=
{}
if
section
.
pool_timeout
is
not
None
:
options
[
'pool_timeout'
]
=
section
.
pool_timeout
def
_option
(
name
,
oname
=
None
):
v
=
getattr
(
section
,
name
)
if
v
is
not
None
:
if
oname
is
None
:
oname
=
name
options
[
oname
]
=
v
_option
(
'pool_timeout'
)
_option
(
'allow_implicit_cross_references'
,
'xrefs'
)
try
:
return
ZODB
.
DB
(
...
...
@@ -106,7 +121,7 @@ class ZODBDatabase(BaseConfig):
historical_cache_size
=
section
.
historical_cache_size
,
historical_cache_size_bytes
=
section
.
historical_cache_size_bytes
,
historical_timeout
=
section
.
historical_timeout
,
database_name
=
section
.
database_name
,
database_name
=
section
.
database_name
or
self
.
name
or
''
,
databases
=
databases
,
**
options
)
except
:
...
...
src/ZODB/config.xml
View file @
11a251d3
...
...
@@ -2,6 +2,7 @@
<import
package=
"ZODB"
/>
<section
type=
"ZODB.database"
name=
"*"
attribute=
"database"
/>
<multisection
type=
"ZODB.database"
name=
"*"
attribute=
"database"
required=
"yes"
/>
</schema>
src/ZODB/tests/testConfig.py
View file @
11a251d3
...
...
@@ -12,23 +12,26 @@
#
##############################################################################
import
os
import
t
ransaction
import
doctest
import
t
empfile
import
unittest
import
ZEO.ClientStorage
import
transaction
import
ZODB.config
import
ZODB.POSException
import
ZODB.tests.util
from
zope.testing
import
doctest
from
ZODB.POSException
import
ReadOnlyError
class
ConfigTestBase
(
ZODB
.
tests
.
util
.
TestCase
):
class
ConfigTestBase
(
unittest
.
TestCase
):
def
_opendb
(
self
,
s
):
return
ZODB
.
config
.
databaseFromString
(
s
)
def
tearDown
(
self
):
if
getattr
(
self
,
"storage"
,
None
)
is
not
None
:
self
.
storage
.
cleanup
()
def
_test
(
self
,
s
):
db
=
self
.
_opendb
(
s
)
self
.
storage
=
db
.
storage
self
.
storage
=
db
.
_
storage
# Do something with the database to make sure it works
cn
=
db
.
open
()
rt
=
cn
.
root
()
...
...
@@ -56,26 +59,28 @@ class ZODBConfigTest(ConfigTestBase):
"""
)
def
test_file_config1
(
self
):
path
=
tempfile
.
mktemp
()
self
.
_test
(
"""
<zodb>
<filestorage>
path
Data.f
s
path
%
s
</filestorage>
</zodb>
"""
)
"""
%
path
)
def
test_file_config2
(
self
):
path
=
tempfile
.
mktemp
()
cfg
=
"""
<zodb>
<filestorage>
path
Data.f
s
path
%
s
create false
read-only true
</filestorage>
</zodb>
"""
self
.
assertRaises
(
ZODB
.
POSException
.
ReadOnlyError
,
self
.
_test
,
cfg
)
"""
%
path
self
.
assertRaises
(
ReadOnlyError
,
self
.
_test
,
cfg
)
def
test_demo_config
(
self
):
cfg
=
"""
...
...
@@ -110,54 +115,116 @@ class ZEOConfigTest(ConfigTestBase):
</zodb>
"""
config
,
handle
=
ZConfig
.
loadConfigFile
(
getDbSchema
(),
StringIO
(
cfg
))
self
.
assertEqual
(
config
.
database
.
config
.
storage
.
config
.
blob_dir
,
self
.
assertEqual
(
config
.
database
[
0
]
.
config
.
storage
.
config
.
blob_dir
,
None
)
self
.
assertRaises
(
ClientDisconnected
,
self
.
_test
,
cfg
)
cfg
=
"""
<zodb>
<zeoclient>
blob-dir
blobs
blob-dir
/tmp
server localhost:56897
wait false
</zeoclient>
</zodb>
"""
config
,
handle
=
ZConfig
.
loadConfigFile
(
getDbSchema
(),
StringIO
(
cfg
))
self
.
assertEqual
(
os
.
path
.
abspath
(
config
.
database
.
config
.
storage
.
config
.
blob_dir
),
os
.
path
.
abspath
(
'blobs'
))
self
.
assertEqual
(
config
.
database
[
0
].
config
.
storage
.
config
.
blob_dir
,
'/tmp'
)
self
.
assertRaises
(
ClientDisconnected
,
self
.
_test
,
cfg
)
def
db_connection_pool_timeout
():
def
database_xrefs_config
():
r"""
>>> db = ZODB.config.databaseFromString(
... "<zodb>\n<mappingstorage>\n</mappingstorage>\n</zodb>\n")
>>> db.xrefs
True
>>> db = ZODB.config.databaseFromString(
... "<zodb>\nallow-implicit-cross-references true\n"
... "<mappingstorage>\n</mappingstorage>\n</zodb>\n")
>>> db.xrefs
True
>>> db = ZODB.config.databaseFromString(
... "<zodb>\nallow-implicit-cross-references false\n"
... "<mappingstorage>\n</mappingstorage>\n</zodb>\n")
>>> db.xrefs
False
"""
Test that the database pool timeout option works:
>>> db = ZODB.config.databaseFromString('''
... <zodb>
... <mappingstorage/>
... </zodb>
... ''')
>>> db.pool._timeout == 1<<31
True
def
multi_atabases
():
r"""If there are multiple codb sections -> multidatabase
>>> db = ZODB.config.databaseFromString('''
... <zodb>
... pool-timeout 600
... <mappingstorage/>
... </zodb>
... <zodb>
... <mappingstorage>
... </mappingstorage>
... </zodb>
... <zodb Foo>
... <mappingstorage>
... </mappingstorage>
... </zodb>
... <zodb>
... database-name Bar
... <mappingstorage>
... </mappingstorage>
... </zodb>
... ''')
>>> db.pool._timeout == 600
>>> sorted(db.databases)
['', 'Bar', 'foo']
>>> db.database_name
''
>>> db.databases[db.database_name] is db
True
>>> db.databases['foo'] is not db
True
>>> db.databases['Bar'] is not db
True
>>> db.databases['Bar'] is not db.databases['foo']
True
"""
Can't have repeats:
>>> ZODB.config.databaseFromString('''
... <zodb 1>
... <mappingstorage>
... </mappingstorage>
... </zodb>
... <zodb 1>
... <mappingstorage>
... </mappingstorage>
... </zodb>
... <zodb 1>
... <mappingstorage>
... </mappingstorage>
... </zodb>
... ''') # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ConfigurationSyntaxError:
section names must not be re-used within the same container:'1' (line 9)
>>> ZODB.config.databaseFromString('''
... <zodb>
... <mappingstorage>
... </mappingstorage>
... </zodb>
... <zodb>
... <mappingstorage>
... </mappingstorage>
... </zodb>
... ''') # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ValueError: database_name '' already in databases
"""
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
doctest
.
DocTestSuite
())
suite
.
addTest
(
unittest
.
makeSuite
(
ZODBConfigTest
))
suite
.
addTest
(
unittest
.
makeSuite
(
ZEOConfigTest
))
suite
.
addTest
(
doctest
.
DocTestSuite
())
return
suite
...
...
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