Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
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
ZEO
Commits
fb7d8993
Commit
fb7d8993
authored
Apr 22, 2003
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python 2.1 compatibility.
parent
850e8917
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
22 deletions
+48
-22
src/ZEO/ClientStorage.py
src/ZEO/ClientStorage.py
+23
-5
src/ZEO/tests/ConnectionTests.py
src/ZEO/tests/ConnectionTests.py
+7
-2
src/ZODB/Connection.py
src/ZODB/Connection.py
+4
-1
src/ZODB/DB.py
src/ZODB/DB.py
+3
-3
src/ZODB/tests/testZODB.py
src/ZODB/tests/testZODB.py
+11
-11
No files found.
src/ZEO/ClientStorage.py
View file @
fb7d8993
...
@@ -214,7 +214,7 @@ class ClientStorage:
...
@@ -214,7 +214,7 @@ class ClientStorage:
# _is_read_only stores the constructor argument
# _is_read_only stores the constructor argument
self
.
_is_read_only
=
read_only
self
.
_is_read_only
=
read_only
# _conn_is_read_only stores the status of the current connection
# _conn_is_read_only stores the status of the current connection
self
.
_conn_is_read_only
=
False
self
.
_conn_is_read_only
=
0
self
.
_storage
=
storage
self
.
_storage
=
storage
self
.
_read_only_fallback
=
read_only_fallback
self
.
_read_only_fallback
=
read_only_fallback
# _server_addr is used by sortKey()
# _server_addr is used by sortKey()
...
@@ -367,7 +367,7 @@ class ClientStorage:
...
@@ -367,7 +367,7 @@ class ClientStorage:
"""
"""
log2
(
INFO
,
"Testing connection %r"
%
conn
)
log2
(
INFO
,
"Testing connection %r"
%
conn
)
# XXX Check the protocol version here?
# XXX Check the protocol version here?
self
.
_conn_is_read_only
=
False
self
.
_conn_is_read_only
=
0
stub
=
self
.
StorageServerStubClass
(
conn
)
stub
=
self
.
StorageServerStubClass
(
conn
)
try
:
try
:
stub
.
register
(
str
(
self
.
_storage
),
self
.
_is_read_only
)
stub
.
register
(
str
(
self
.
_storage
),
self
.
_is_read_only
)
...
@@ -377,7 +377,7 @@ class ClientStorage:
...
@@ -377,7 +377,7 @@ class ClientStorage:
raise
raise
log2
(
INFO
,
"Got ReadOnlyError; trying again with read_only=1"
)
log2
(
INFO
,
"Got ReadOnlyError; trying again with read_only=1"
)
stub
.
register
(
str
(
self
.
_storage
),
read_only
=
1
)
stub
.
register
(
str
(
self
.
_storage
),
read_only
=
1
)
self
.
_conn_is_read_only
=
True
self
.
_conn_is_read_only
=
1
return
0
return
0
def
notifyConnected
(
self
,
conn
):
def
notifyConnected
(
self
,
conn
):
...
@@ -559,7 +559,7 @@ class ClientStorage:
...
@@ -559,7 +559,7 @@ class ClientStorage:
def
isReadOnly
(
self
):
def
isReadOnly
(
self
):
"""Storage API: return whether we are in read-only mode."""
"""Storage API: return whether we are in read-only mode."""
if
self
.
_is_read_only
:
if
self
.
_is_read_only
:
return
True
return
1
else
:
else
:
# If the client is configured for a read-write connection
# If the client is configured for a read-write connection
# but has a read-only fallback connection, _conn_is_read_only
# but has a read-only fallback connection, _conn_is_read_only
...
@@ -961,12 +961,18 @@ class ClientStorage:
...
@@ -961,12 +961,18 @@ class ClientStorage:
end
=
endVerify
end
=
endVerify
Invalidate
=
invalidateTrans
Invalidate
=
invalidateTrans
try
:
StopIteration
except
NameError
:
class
StopIteration
(
Exception
):
pass
class
InvalidationLogIterator
:
class
InvalidationLogIterator
:
"""Helper class for reading invalidations in endVerify."""
"""Helper class for reading invalidations in endVerify."""
# XXX will require extra work to backport to Python 2.1
def
__init__
(
self
,
fileobj
):
def
__init__
(
self
,
fileobj
):
self
.
_unpickler
=
cPickle
.
Unpickler
(
fileobj
)
self
.
_unpickler
=
cPickle
.
Unpickler
(
fileobj
)
self
.
getitem_i
=
0
def
__iter__
(
self
):
def
__iter__
(
self
):
return
self
return
self
...
@@ -976,3 +982,15 @@ class InvalidationLogIterator:
...
@@ -976,3 +982,15 @@ class InvalidationLogIterator:
if
oid
is
None
:
if
oid
is
None
:
raise
StopIteration
raise
StopIteration
return
oid
,
version
return
oid
,
version
# The __getitem__() method is needed to support iteration
# in Python 2.1.
def
__getitem__
(
self
,
i
):
assert
i
==
self
.
getitem_i
try
:
obj
=
self
.
next
()
except
StopIteration
:
raise
IndexError
,
i
self
.
getitem_i
+=
1
return
obj
src/ZEO/tests/ConnectionTests.py
View file @
fb7d8993
...
@@ -438,6 +438,7 @@ class ConnectionTests(CommonSetupTearDown):
...
@@ -438,6 +438,7 @@ class ConnectionTests(CommonSetupTearDown):
self
.
_storage
=
self
.
openClientStorage
()
self
.
_storage
=
self
.
openClientStorage
()
self
.
_dostore
()
self
.
_dostore
()
# Test case for multiple storages participating in a single
# Test case for multiple storages participating in a single
# transaction. This is not really a connection test, but it needs
# transaction. This is not really a connection test, but it needs
# about the same infrastructure (several storage servers).
# about the same infrastructure (several storage servers).
...
@@ -491,8 +492,12 @@ class ConnectionTests(CommonSetupTearDown):
...
@@ -491,8 +492,12 @@ class ConnectionTests(CommonSetupTearDown):
get_transaction
().
commit
()
get_transaction
().
commit
()
# make sure the invalidation is received in the other client
# make sure the invalidation is received in the other client
for
i
in
range
(
10
):
c1
.
_storage
.
sync
()
c1
.
_storage
.
sync
()
self
.
assert_
(
r1
.
_p_oid
in
c1
.
_invalidated
)
if
c1
.
_invalidated
.
has_key
(
r1
.
_p_oid
):
break
time
.
sleep
(
0.1
)
self
.
assert_
(
c1
.
_invalidated
.
has_key
(
r1
.
_p_oid
))
# force the invalidations to be applied...
# force the invalidations to be applied...
c1
.
setLocalTransaction
()
c1
.
setLocalTransaction
()
...
...
src/ZODB/Connection.py
View file @
fb7d8993
...
@@ -13,7 +13,10 @@
...
@@ -13,7 +13,10 @@
##############################################################################
##############################################################################
"""Database connection support
"""Database connection support
$Id: Connection.py,v 1.88 2003/04/08 15:55:44 jeremy Exp $"""
$Id: Connection.py,v 1.89 2003/04/22 18:04:37 jeremy Exp $"""
from
__future__
import
nested_scopes
from
cPickleCache
import
PickleCache
from
cPickleCache
import
PickleCache
from
POSException
import
ConflictError
,
ReadConflictError
,
TransactionError
from
POSException
import
ConflictError
,
ReadConflictError
,
TransactionError
from
ExtensionClass
import
Base
from
ExtensionClass
import
Base
...
...
src/ZODB/DB.py
View file @
fb7d8993
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
##############################################################################
##############################################################################
"""Database objects
"""Database objects
$Id: DB.py,v 1.4
8 2003/04/08 15:55:44
jeremy Exp $"""
$Id: DB.py,v 1.4
9 2003/04/22 18:04:37
jeremy Exp $"""
__version__
=
'$Revision: 1.4
8
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.4
9
$'
[
11
:
-
2
]
import
cPickle
,
cStringIO
,
sys
,
POSException
,
UndoLogCompatible
import
cPickle
,
cStringIO
,
sys
,
POSException
,
UndoLogCompatible
from
Connection
import
Connection
from
Connection
import
Connection
...
@@ -301,7 +301,7 @@ class DB(UndoLogCompatible.UndoLogCompatible):
...
@@ -301,7 +301,7 @@ class DB(UndoLogCompatible.UndoLogCompatible):
version
=
connection
.
_version
version
=
connection
.
_version
# Update modified in version cache
# Update modified in version cache
# XXX must make this work with list or dict to backport to 2.6
# XXX must make this work with list or dict to backport to 2.6
for
oid
in
oids
:
for
oid
in
oids
.
keys
()
:
h
=
hash
(
oid
)
%
131
h
=
hash
(
oid
)
%
131
o
=
self
.
_miv_cache
.
get
(
h
,
None
)
o
=
self
.
_miv_cache
.
get
(
h
,
None
)
if
o
is
not
None
and
o
[
0
]
==
oid
:
del
self
.
_miv_cache
[
h
]
if
o
is
not
None
and
o
[
0
]
==
oid
:
del
self
.
_miv_cache
[
h
]
...
...
src/ZODB/tests/testZODB.py
View file @
fb7d8993
...
@@ -26,12 +26,12 @@ class P(Persistent):
...
@@ -26,12 +26,12 @@ class P(Persistent):
class
Independent
(
Persistent
):
class
Independent
(
Persistent
):
def
_p_independent
(
self
):
def
_p_independent
(
self
):
return
True
return
1
class
DecoyIndependent
(
Persistent
):
class
DecoyIndependent
(
Persistent
):
def
_p_independent
(
self
):
def
_p_independent
(
self
):
return
False
return
0
class
ZODBTests
(
unittest
.
TestCase
):
class
ZODBTests
(
unittest
.
TestCase
):
...
@@ -193,7 +193,7 @@ class ZODBTests(unittest.TestCase):
...
@@ -193,7 +193,7 @@ class ZODBTests(unittest.TestCase):
self
.
obj
=
P
()
self
.
obj
=
P
()
self
.
readConflict
()
self
.
readConflict
()
def
readConflict
(
self
,
shouldFail
=
True
):
def
readConflict
(
self
,
shouldFail
=
1
):
# Two transactions run concurrently. Each reads some object,
# Two transactions run concurrently. Each reads some object,
# then one commits and the other tries to read an object
# then one commits and the other tries to read an object
# modified by the first. This read should fail with a conflict
# modified by the first. This read should fail with a conflict
...
@@ -237,10 +237,10 @@ class ZODBTests(unittest.TestCase):
...
@@ -237,10 +237,10 @@ class ZODBTests(unittest.TestCase):
root
[
"real_data"
]
=
real_data
=
PersistentDict
()
root
[
"real_data"
]
=
real_data
=
PersistentDict
()
root
[
"index"
]
=
index
=
PersistentDict
()
root
[
"index"
]
=
index
=
PersistentDict
()
real_data
[
"a"
]
=
PersistentDict
({
"indexed_value"
:
False
})
real_data
[
"a"
]
=
PersistentDict
({
"indexed_value"
:
0
})
real_data
[
"b"
]
=
PersistentDict
({
"indexed_value"
:
True
})
real_data
[
"b"
]
=
PersistentDict
({
"indexed_value"
:
1
})
index
[
True
]
=
PersistentDict
({
"b"
:
1
})
index
[
1
]
=
PersistentDict
({
"b"
:
1
})
index
[
False
]
=
PersistentDict
({
"a"
:
1
})
index
[
0
]
=
PersistentDict
({
"a"
:
1
})
get_transaction
().
commit
()
get_transaction
().
commit
()
# load some objects from one connection
# load some objects from one connection
...
@@ -251,8 +251,8 @@ class ZODBTests(unittest.TestCase):
...
@@ -251,8 +251,8 @@ class ZODBTests(unittest.TestCase):
index2
=
r2
[
"index"
]
index2
=
r2
[
"index"
]
real_data
[
"b"
][
"indexed_value"
]
=
False
real_data
[
"b"
][
"indexed_value"
]
=
False
del
index
[
True
][
"b"
]
del
index
[
1
][
"b"
]
index
[
False
][
"b"
]
=
1
index
[
0
][
"b"
]
=
1
cn2
.
getTransaction
().
commit
()
cn2
.
getTransaction
().
commit
()
del
real_data2
[
"a"
]
del
real_data2
[
"a"
]
...
@@ -269,8 +269,8 @@ class ZODBTests(unittest.TestCase):
...
@@ -269,8 +269,8 @@ class ZODBTests(unittest.TestCase):
# index2 values not ready to commit
# index2 values not ready to commit
self
.
assert_
(
not
index2
.
_p_changed
)
self
.
assert_
(
not
index2
.
_p_changed
)
self
.
assert_
(
not
index2
[
False
].
_p_changed
)
self
.
assert_
(
not
index2
[
0
].
_p_changed
)
self
.
assert_
(
not
index2
[
True
].
_p_changed
)
self
.
assert_
(
not
index2
[
1
].
_p_changed
)
self
.
assertRaises
(
ConflictError
,
get_transaction
().
commit
)
self
.
assertRaises
(
ConflictError
,
get_transaction
().
commit
)
get_transaction
().
abort
()
get_transaction
().
abort
()
...
...
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