Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodburi
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
zodburi
Commits
f889b874
Commit
f889b874
authored
Aug 18, 2011
by
Chris Rossi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix backwards compatability with zconfig--may specify a database or a storage.
parent
21c2c799
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
7 deletions
+62
-7
zodburi/resolvers.py
zodburi/resolvers.py
+20
-4
zodburi/tests/test_resolvers.py
zodburi/tests/test_resolvers.py
+42
-3
No files found.
zodburi/resolvers.py
View file @
f889b874
...
...
@@ -3,6 +3,7 @@ import cgi
from
cStringIO
import
StringIO
import
urlparse
from
ZODB.config
import
ZODBDatabase
from
ZEO.ClientStorage
import
ClientStorage
from
ZODB.FileStorage.FileStorage
import
FileStorage
from
ZODB.DemoStorage
import
DemoStorage
...
...
@@ -158,6 +159,7 @@ class ZConfigURIResolver(object):
<schema>
<import package="ZODB"/>
<multisection type="ZODB.storage" attribute="storages" />
<multisection type="ZODB.database" attribute="databases" />
</schema>
"""
...
...
@@ -169,16 +171,30 @@ class ZConfigURIResolver(object):
schema_xml
=
self
.
schema_xml_template
schema
=
ZConfig
.
loadSchemaFile
(
StringIO
(
schema_xml
))
config
,
handler
=
ZConfig
.
loadConfig
(
schema
,
path
)
for
factory
in
config
.
storages
:
for
config_item
in
config
.
databases
+
config
.
storages
:
if
not
frag
:
# use the first defined in the file
break
elif
frag
==
factory
.
name
:
elif
frag
==
config_item
.
name
:
# match found
break
else
:
raise
KeyError
(
"No storage named %s found"
%
frag
)
return
factory
.
open
,
dict
(
cgi
.
parse_qsl
(
query
))
raise
KeyError
(
"No storage or database named %s found"
%
frag
)
if
isinstance
(
config_item
,
ZODBDatabase
):
config
=
config_item
.
config
factory
=
config
.
storage
dbkw
=
{
'connection_cache_size'
:
config
.
cache_size
,
'connection_pool_size'
:
config
.
pool_size
,
}
if
config
.
database_name
:
dbkw
[
'database_name'
]
=
config
.
database_name
else
:
factory
=
config_item
dbkw
=
dict
(
cgi
.
parse_qsl
(
query
))
return
factory
.
open
,
dbkw
client_storage_resolver
=
ClientStorageURIResolver
()
...
...
zodburi/tests/test_resolvers.py
View file @
f889b874
...
...
@@ -265,7 +265,7 @@ class TestZConfigURIResolver(unittest.TestCase):
def
tearDown
(
self
):
self
.
tmp
.
close
()
def
test_named_
databas
e
(
self
):
def
test_named_
storag
e
(
self
):
self
.
tmp
.
write
(
"""
<demostorage foo>
</demostorage>
...
...
@@ -280,7 +280,7 @@ class TestZConfigURIResolver(unittest.TestCase):
from
ZODB.MappingStorage
import
MappingStorage
self
.
assertTrue
(
isinstance
(
storage
,
MappingStorage
),
storage
)
def
test_anonymous_
databas
e
(
self
):
def
test_anonymous_
storag
e
(
self
):
self
.
tmp
.
write
(
"""
<mappingstorage>
</mappingstorage>
...
...
@@ -294,6 +294,7 @@ class TestZConfigURIResolver(unittest.TestCase):
storage
=
factory
()
from
ZODB.MappingStorage
import
MappingStorage
self
.
assertTrue
(
isinstance
(
storage
,
MappingStorage
))
self
.
assertEqual
(
dbkw
,
{})
def
test_query_string_args
(
self
):
self
.
tmp
.
write
(
"""
...
...
@@ -308,7 +309,7 @@ class TestZConfigURIResolver(unittest.TestCase):
factory
,
dbkw
=
resolver
(
'zconfig://%s?foo=bar'
%
self
.
tmp
.
name
)
self
.
assertEqual
(
dbkw
,
{
'foo'
:
'bar'
})
def
test_
databas
e_not_found
(
self
):
def
test_
storag
e_not_found
(
self
):
self
.
tmp
.
write
(
"""
<mappingstorage x>
</mappingstorage>
...
...
@@ -317,6 +318,44 @@ class TestZConfigURIResolver(unittest.TestCase):
resolver
=
self
.
_makeOne
()
self
.
assertRaises
(
KeyError
,
resolver
,
'zconfig://%s#y'
%
self
.
tmp
.
name
)
def
test_anonymous_database
(
self
):
self
.
tmp
.
write
(
"""
<zodb>
<mappingstorage>
</mappingstorage>
</zodb>
"""
)
self
.
tmp
.
flush
()
resolver
=
self
.
_makeOne
()
factory
,
dbkw
=
resolver
(
'zconfig://%s'
%
self
.
tmp
.
name
)
storage
=
factory
()
from
ZODB.MappingStorage
import
MappingStorage
self
.
assertTrue
(
isinstance
(
storage
,
MappingStorage
))
self
.
assertEqual
(
dbkw
,
{
'connection_cache_size'
:
5000
,
'connection_pool_size'
:
7
})
def
test_named_database
(
self
):
self
.
tmp
.
write
(
"""
<zodb x>
<mappingstorage>
</mappingstorage>
database-name foo
cache-size 20000
pool-size 5
</zodb>
"""
)
self
.
tmp
.
flush
()
resolver
=
self
.
_makeOne
()
factory
,
dbkw
=
resolver
(
'zconfig://%s#x'
%
self
.
tmp
.
name
)
storage
=
factory
()
from
ZODB.MappingStorage
import
MappingStorage
self
.
assertTrue
(
isinstance
(
storage
,
MappingStorage
))
self
.
assertEqual
(
dbkw
,
{
'connection_cache_size'
:
20000
,
'connection_pool_size'
:
5
,
'database_name'
:
'foo'
})
class
TestMappingStorageURIResolver
(
Base
,
unittest
.
TestCase
):
def
_getTargetClass
(
self
):
...
...
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