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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
9bd4feda
Commit
9bd4feda
authored
May 22, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
fdcec437
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
75 deletions
+76
-75
wcfs/testprog/treedelta-genallstructs.py
wcfs/testprog/treedelta-genallstructs.py
+76
-75
No files found.
wcfs/testprog/treedelta-genallstructs.py
View file @
9bd4feda
...
...
@@ -60,81 +60,6 @@ from persistent.mapping import PersistentMapping
import
BTrees.LOBTree
# kvEncode encodes key->value maping into text.
# e.g. {1:'a', 2:'b'} -> '1:a,2:b'
def
kvEncode
(
kvDict
,
vencode
):
# -> kvText
retv
=
[]
for
k
in
sorted
(
kvDict
.
keys
()):
v
=
kvDict
[
k
]
retv
.
append
(
'%d:%s'
%
(
k
,
vencode
(
v
)))
return
','
.
join
(
retv
)
# kvDecode decodes key->value mapping from text.
# e.g. '1:a,2:b' -> {1:'a', 2:'b'}
def
kvDecode
(
kvText
,
vdecode
):
# -> kvDict
kv
=
{}
for
item
in
kvText
.
split
(
','
):
ktxt
,
vtxt
=
item
.
split
(
':'
)
k
=
int
(
ktxt
)
v
=
vdecode
(
vtxt
)
if
k
in
kv
:
raise
ValueError
(
"key %s present multiple times"
%
k
)
kv
[
k
]
=
v
return
kv
# diff computes difference in between mappings d1 and d2.
DEL
=
'ø'
def
diff
(
d1
,
d2
):
# -> [] of (k,v) to change; DEL means del[k]
delta
=
[]
keys
=
set
(
d1
.
keys
())
keys
.
update
(
d2
.
keys
())
for
k
in
sorted
(
keys
):
v1
=
d1
.
get
(
k
,
DEL
)
v2
=
d2
.
get
(
k
,
DEL
)
if
v1
is
not
v2
:
delta
.
append
((
k
,
v2
))
return
delta
# patch changes mapping d according to diff.
# diff = [] of (k,v) to change; DEL means del[k]
def
patch
(
d
,
diff
,
verify
):
for
(
k
,
v
)
in
diff
:
if
v
is
DEL
:
del
d
[
k
]
else
:
d
[
k
]
=
v
if
verify
is
None
:
return
keys
=
set
(
d
.
keys
())
keyok
=
set
(
verify
.
keys
())
if
keys
!=
keyok
:
panic
(
"patch: verify: different keys: %s"
%
keys
.
symmetric_difference
(
keyok
))
for
k
in
keys
:
if
d
[
k
]
is
not
verify
[
k
]:
panic
(
"patch: verify: [%d] different: got %r; want %r"
%
(
k
,
d
[
k
],
verify
[
k
]))
# commit commits current transaction with description.
def
commit
(
description
):
txn
=
transaction
.
get
()
txn
.
description
=
description
# XXX hack to retrieve committed transaction ID via ._p_serial of object changed in this transaction
assert
len
(
txn
.
_resources
)
==
1
zconn
=
txn
.
_resources
[
0
]
assert
isinstance
(
zconn
,
Connection
)
assert
len
(
zconn
.
_registered_objects
)
>
0
obj
=
zconn
.
_registered_objects
[
0
]
assert
obj
.
_p_state
==
CHANGED
txn
.
commit
()
return
obj
.
_p_serial
# treetxt returns text representation of a tree.
def
treetxt
(
ztree
):
# -> txt
return
xbtree
.
TopoEncode
(
xbtree
.
StructureOf
(
ztree
))
# FIXME include values
# XXX
#
# kv: k₁:v₁,k₂:v₂,...
...
...
@@ -255,6 +180,82 @@ def test_bitravel2Way():
test_bitravel2Way
()
# kvEncode encodes key->value maping into text.
# e.g. {1:'a', 2:'b'} -> '1:a,2:b'
def
kvEncode
(
kvDict
,
vencode
):
# -> kvText
retv
=
[]
for
k
in
sorted
(
kvDict
.
keys
()):
v
=
kvDict
[
k
]
retv
.
append
(
'%d:%s'
%
(
k
,
vencode
(
v
)))
return
','
.
join
(
retv
)
# kvDecode decodes key->value mapping from text.
# e.g. '1:a,2:b' -> {1:'a', 2:'b'}
def
kvDecode
(
kvText
,
vdecode
):
# -> kvDict
kv
=
{}
for
item
in
kvText
.
split
(
','
):
ktxt
,
vtxt
=
item
.
split
(
':'
)
k
=
int
(
ktxt
)
v
=
vdecode
(
vtxt
)
if
k
in
kv
:
raise
ValueError
(
"key %s present multiple times"
%
k
)
kv
[
k
]
=
v
return
kv
# diff computes difference in between mappings d1 and d2.
DEL
=
'ø'
def
diff
(
d1
,
d2
):
# -> [] of (k,v) to change; DEL means del[k]
delta
=
[]
keys
=
set
(
d1
.
keys
())
keys
.
update
(
d2
.
keys
())
for
k
in
sorted
(
keys
):
v1
=
d1
.
get
(
k
,
DEL
)
v2
=
d2
.
get
(
k
,
DEL
)
if
v1
is
not
v2
:
delta
.
append
((
k
,
v2
))
return
delta
# patch changes mapping d according to diff.
# diff = [] of (k,v) to change; DEL means del[k]
def
patch
(
d
,
diff
,
verify
):
for
(
k
,
v
)
in
diff
:
if
v
is
DEL
:
del
d
[
k
]
else
:
d
[
k
]
=
v
if
verify
is
None
:
return
keys
=
set
(
d
.
keys
())
keyok
=
set
(
verify
.
keys
())
if
keys
!=
keyok
:
panic
(
"patch: verify: different keys: %s"
%
keys
.
symmetric_difference
(
keyok
))
for
k
in
keys
:
if
d
[
k
]
is
not
verify
[
k
]:
panic
(
"patch: verify: [%d] different: got %r; want %r"
%
(
k
,
d
[
k
],
verify
[
k
]))
# commit commits current transaction with description.
def
commit
(
description
):
# -> tid
txn
=
transaction
.
get
()
txn
.
description
=
description
# XXX hack to retrieve committed transaction ID via ._p_serial of object changed in this transaction
assert
len
(
txn
.
_resources
)
==
1
zconn
=
txn
.
_resources
[
0
]
assert
isinstance
(
zconn
,
Connection
)
assert
len
(
zconn
.
_registered_objects
)
>
0
obj
=
zconn
.
_registered_objects
[
0
]
assert
obj
.
_p_state
==
CHANGED
txn
.
commit
()
return
obj
.
_p_serial
# treetxt returns text representation of a tree.
def
treetxt
(
ztree
):
# -> txt
return
xbtree
.
TopoEncode
(
xbtree
.
StructureOf
(
ztree
))
# FIXME include values
@
func
def
main
():
if
len
(
sys
.
argv
)
!=
5
:
...
...
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