Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
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
Joshua
wendelin.core
Commits
ad0f05aa
Commit
ad0f05aa
authored
Apr 01, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bigfile/zodb: Factor-out patch for ZODB.Connection.onOpenCallback into -> lib/zodb
parent
42e313d1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
33 deletions
+31
-33
bigfile/file_zodb.py
bigfile/file_zodb.py
+0
-32
lib/zodb.py
lib/zodb.py
+31
-1
No files found.
bigfile/file_zodb.py
View file @
ad0f05aa
...
...
@@ -140,7 +140,6 @@ from persistent import Persistent, GHOST
from
BTrees.LOBTree
import
LOBTree
from
BTrees.IOBTree
import
IOBTree
from
zope.interface
import
implementer
from
ZODB.Connection
import
Connection
from
weakref
import
WeakSet
import
os
...
...
@@ -573,37 +572,6 @@ class ZBigFile(LivePersistent):
# patch for ZODB.Connection to support callback on .open()
# NOTE on-open callbacks are setup once and fire many times on every open
# on-close callbacks are setup once and fire only once on next close
Connection
.
_onOpenCallbacks
=
None
def
Connection_onOpenCallback
(
self
,
f
):
if
self
.
_onOpenCallbacks
is
None
:
# NOTE WeakSet does not work for bound methods - they are always created
# anew for each obj.method access, and thus will go away almost immediately
self
.
_onOpenCallbacks
=
WeakSet
()
self
.
_onOpenCallbacks
.
add
(
f
)
assert
not
hasattr
(
Connection
,
'onOpenCallback'
)
Connection
.
onOpenCallback
=
Connection_onOpenCallback
orig_Connection_open
=
Connection
.
open
def
Connection_open
(
self
,
transaction_manager
=
None
,
delegate
=
True
):
orig_Connection_open
(
self
,
transaction_manager
,
delegate
)
# FIXME method name hardcoded. Better not do it and allow f to be general
# callable, but that does not work with bound method - see above.
# ( Something like WeakMethod from py3 could help )
if
self
.
_onOpenCallbacks
:
for
f
in
self
.
_onOpenCallbacks
:
f
.
on_connection_open
()
Connection
.
open
=
Connection_open
# ------------
# BigFileH wrapper that also acts as DataManager proxying changes back to ZODB
# objects at two-phase-commit (TPC) level.
#
...
...
lib/zodb.py
View file @
ad0f05aa
# Wendelin.bigfile | common ZODB-related helpers
# Copyright (C) 2014-20
19
Nexedi SA and Contributors.
# Copyright (C) 2014-20
20
Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
...
...
@@ -19,9 +19,11 @@
# See https://www.nexedi.com/licensing for rationale and options.
"""Package wendelin.lib.zodb provides ZODB-related utilities."""
import
ZODB
from
ZODB.FileStorage
import
FileStorage
from
ZODB
import
DB
from
persistent
import
Persistent
from
weakref
import
WeakSet
import
gc
...
...
@@ -131,3 +133,31 @@ def _deactivate_bucket(bucket):
obj
.
_p_deactivate
()
bucket
.
_p_deactivate
()
# patch for ZODB.Connection to support callback on .open()
# NOTE on-open callbacks are setup once and fire many times on every open
# on-close callbacks are setup once and fire only once on next close
ZODB
.
Connection
.
Connection
.
_onOpenCallbacks
=
None
def
Connection_onOpenCallback
(
self
,
f
):
if
self
.
_onOpenCallbacks
is
None
:
# NOTE WeakSet does not work for bound methods - they are always created
# anew for each obj.method access, and thus will go away almost immediately
self
.
_onOpenCallbacks
=
WeakSet
()
self
.
_onOpenCallbacks
.
add
(
f
)
assert
not
hasattr
(
ZODB
.
Connection
.
Connection
,
'onOpenCallback'
)
ZODB
.
Connection
.
Connection
.
onOpenCallback
=
Connection_onOpenCallback
_orig_Connection_open
=
ZODB
.
Connection
.
Connection
.
open
def
Connection_open
(
self
,
transaction_manager
=
None
,
delegate
=
True
):
_orig_Connection_open
(
self
,
transaction_manager
,
delegate
)
# FIXME method name hardcoded. Better not do it and allow f to be general
# callable, but that does not work with bound method - see above.
# ( Something like WeakMethod from py3 could help )
if
self
.
_onOpenCallbacks
:
for
f
in
self
.
_onOpenCallbacks
:
f
.
on_connection_open
()
ZODB
.
Connection
.
Connection
.
open
=
Connection_open
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