Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ipaaca
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
ipaaca
Commits
3f7a84f1
Commit
3f7a84f1
authored
11 years ago
by
Hendrik Buschmeier
Browse files
Options
Downloads
Patches
Plain Diff
ipaaca-py: first attempt of context-manager based batch payload updates.
parent
325d40e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ipaacalib/python/src/ipaaca/__init__.py
+29
-6
29 additions, 6 deletions
ipaacalib/python/src/ipaaca/__init__.py
with
29 additions
and
6 deletions
ipaacalib/python/src/ipaaca/__init__.py
+
29
−
6
View file @
3f7a84f1
...
@@ -144,10 +144,14 @@ class Payload(dict):
...
@@ -144,10 +144,14 @@ class Payload(dict):
# NOTE omit_init_update_message is necessary to prevent checking for
# NOTE omit_init_update_message is necessary to prevent checking for
# exceptions and sending updates in the case where we just receive
# exceptions and sending updates in the case where we just receive
# a whole new payload from the remote side and overwrite it locally.
# a whole new payload from the remote side and overwrite it locally.
if
(
not
omit_init_update_message
)
and
(
self
.
iu
.
buffer
is
not
None
):
self
.
iu
.
_modify_payload
(
is_delta
=
False
,
new_items
=
pl
,
keys_to_remove
=
[],
writer_name
=
writer_name
)
for
k
,
v
in
pl
.
items
():
for
k
,
v
in
pl
.
items
():
dict
.
__setitem__
(
self
,
k
,
v
)
dict
.
__setitem__
(
self
,
k
,
v
)
if
(
not
omit_init_update_message
)
and
(
self
.
iu
.
buffer
is
not
None
):
self
.
iu
.
_modify_payload
(
is_delta
=
False
,
new_items
=
pl
,
keys_to_remove
=
[],
writer_name
=
writer_name
)
self
.
_update_on_every_change
=
True
self
.
_collected_modifications
=
{}
self
.
_collected_removals
=
[]
def
merge
(
self
,
payload
,
writer_name
=
None
):
def
merge
(
self
,
payload
,
writer_name
=
None
):
for
k
,
v
in
payload
:
for
k
,
v
in
payload
:
...
@@ -163,16 +167,35 @@ class Payload(dict):
...
@@ -163,16 +167,35 @@ class Payload(dict):
k
=
unicode
(
k
,
'
utf8
'
)
k
=
unicode
(
k
,
'
utf8
'
)
if
type
(
v
)
==
str
:
if
type
(
v
)
==
str
:
v
=
unicode
(
v
,
'
utf8
'
)
v
=
unicode
(
v
,
'
utf8
'
)
self
.
iu
.
_modify_payload
(
is_delta
=
True
,
new_items
=
{
k
:
v
},
keys_to_remove
=
[],
writer_name
=
writer_name
)
if
self
.
_update_on_every_change
:
result
=
dict
.
__setitem__
(
self
,
k
,
v
)
self
.
iu
.
_modify_payload
(
is_delta
=
True
,
new_items
=
{
k
:
v
},
keys_to_remove
=
[],
writer_name
=
writer_name
)
else
:
# Collect additions/modifications
self
.
_collected_modifications
[
k
]
=
v
return
dict
.
__setitem__
(
self
,
k
,
v
)
def
__delitem__
(
self
,
k
,
writer_name
=
None
):
def
__delitem__
(
self
,
k
,
writer_name
=
None
):
if
type
(
k
)
==
str
:
if
type
(
k
)
==
str
:
k
=
unicode
(
k
,
'
utf8
'
)
k
=
unicode
(
k
,
'
utf8
'
)
self
.
iu
.
_modify_payload
(
is_delta
=
True
,
new_items
=
{},
keys_to_remove
=
[
k
],
writer_name
=
writer_name
)
if
self
.
_update_on_every_change
:
result
=
dict
.
__delitem__
(
self
,
k
)
self
.
iu
.
_modify_payload
(
is_delta
=
True
,
new_items
=
{},
keys_to_remove
=
[
k
],
writer_name
=
writer_name
)
else
:
# Collect additions/modifications
self
.
_collected_removals
.
append
(
k
)
return
dict
.
__delitem__
(
self
,
k
)
# Context-manager based batch updates, not yet thread-safe (on remote updates)
#def __enter__(self):
# self._update_on_every_change = False
#
#def __exit__(self, type, value, traceback):
# self.iu._modify_payload(is_delta=True, new_items=self._collected_modifications, keys_to_remove=self._collected_removals, writer_name=None)
# self._collected_modifications = {}
# self._collected_removals = []
# self._update_on_every_change = True
def
_remotely_enforced_setitem
(
self
,
k
,
v
):
def
_remotely_enforced_setitem
(
self
,
k
,
v
):
"""
Sets an item when requested remotely.
"""
"""
Sets an item when requested remotely.
"""
return
dict
.
__setitem__
(
self
,
k
,
v
)
return
dict
.
__setitem__
(
self
,
k
,
v
)
def
_remotely_enforced_delitem
(
self
,
k
):
def
_remotely_enforced_delitem
(
self
,
k
):
"""
Deletes an item when requested remotely.
"""
"""
Deletes an item when requested remotely.
"""
return
dict
.
__delitem__
(
self
,
k
)
return
dict
.
__delitem__
(
self
,
k
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment