Commit ecaa428c authored by Tim Peters's avatar Tim Peters

Reindent like other pure-doctest text files.

parent e15d3d32
...@@ -20,91 +20,91 @@ collection. ...@@ -20,91 +20,91 @@ collection.
Creating a multi-database starts with creating a named DB: Creating a multi-database starts with creating a named DB:
>>> from ZODB.tests.test_storage import MinimalMemoryStorage >>> from ZODB.tests.test_storage import MinimalMemoryStorage
>>> from ZODB import DB >>> from ZODB import DB
>>> db = DB(MinimalMemoryStorage(), database_name='root') >>> db = DB(MinimalMemoryStorage(), database_name='root')
The database name is accessible afterwards and in a newly created collection: The database name is accessible afterwards and in a newly created collection:
>>> db.database_name >>> db.database_name
'root' 'root'
>>> db.databases # doctest: +ELLIPSIS >>> db.databases # doctest: +ELLIPSIS
{'root': <ZODB.DB.DB object at ...>} {'root': <ZODB.DB.DB object at ...>}
Adding a new database works like this: Adding a new database works like this:
>>> db2 = DB(MinimalMemoryStorage(), >>> db2 = DB(MinimalMemoryStorage(),
... database_name='notroot', ... database_name='notroot',
... databases=db.databases) ... databases=db.databases)
The new db2 now shares the 'databases' dictionary with db and has two entries: The new db2 now shares the 'databases' dictionary with db and has two entries:
>>> db2.databases is db.databases >>> db2.databases is db.databases
True True
>>> len(db2.databases) >>> len(db2.databases)
2 2
Trying to insert a database with a name that is already in use will not work: Trying to insert a database with a name that is already in use will not work:
>>> db3 = DB(MinimalMemoryStorage(), >>> db3 = DB(MinimalMemoryStorage(),
... database_name='root', ... database_name='root',
... databases=db.databases) ... databases=db.databases)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: database_name 'root' already in databases ValueError: database_name 'root' already in databases
Because that failed, db.databases wasn't changed: Because that failed, db.databases wasn't changed:
>>> len(db.databases) # still 2 >>> len(db.databases) # still 2
2 2
You can (still) get a connection to a database this way: You can (still) get a connection to a database this way:
>>> cn = db.open() >>> cn = db.open()
>>> cn # doctest: +ELLIPSIS >>> cn # doctest: +ELLIPSIS
<Connection at ...> <Connection at ...>
This is the only connection in this collection right now: This is the only connection in this collection right now:
>>> cn.connections # doctest: +ELLIPSIS >>> cn.connections # doctest: +ELLIPSIS
{'root': <Connection at ...>} {'root': <Connection at ...>}
Getting a connection to a different database from an existing connection in the Getting a connection to a different database from an existing connection in the
same database collection (this enables 'connection binding' within a given same database collection (this enables 'connection binding' within a given
thread/transaction/context ...): thread/transaction/context ...):
>>> cn2 = cn.get_connection('notroot') >>> cn2 = cn.get_connection('notroot')
>>> cn2 # doctest: +ELLIPSIS >>> cn2 # doctest: +ELLIPSIS
<Connection at ...> <Connection at ...>
Now there are two connections in that collection: Now there are two connections in that collection:
>>> cn2.connections is cn.connections >>> cn2.connections is cn.connections
True True
>>> len(cn2.connections) >>> len(cn2.connections)
2 2
So long as this database group remains open, the same Connection objects So long as this database group remains open, the same Connection objects
are returned: are returned:
>>> cn.get_connection('root') is cn >>> cn.get_connection('root') is cn
True True
>>> cn.get_connection('notroot') is cn2 >>> cn.get_connection('notroot') is cn2
True True
>>> cn2.get_connection('root') is cn >>> cn2.get_connection('root') is cn
True True
>>> cn2.get_connection('notroot') is cn2 >>> cn2.get_connection('notroot') is cn2
True True
Of course trying to get a connection for a database not in the group raises Of course trying to get a connection for a database not in the group raises
an exception: an exception:
>>> cn.get_connection('no way') >>> cn.get_connection('no way')
Traceback (most recent call last): Traceback (most recent call last):
... ...
KeyError: 'no way' KeyError: 'no way'
Clean up: Clean up:
>>> for a_db in db.databases.values(): >>> for a_db in db.databases.values():
... a_db.close() ... a_db.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment