Skip to content

Commit 36e8107

Browse files
author
Jakub Urban
committed
Add custom serializer and de-serializer for pickle module
1 parent 263e9c3 commit 36e8107

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

ansible/rebuild_module.digest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b15fe9a4d46c1914885e7c16533ac6b5 -
1+
edc44ab7e58d94cab8a8ad4384309c75 -

ansible/roles/openshift_client_python/library/openshift_client_python.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openshift/apiobject.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,3 +885,25 @@ def execute(self, cmd_to_exec=None, stdin=None, container_name=None, auto_raise=
885885
r.fail_if(
886886
"Error running {} exec on {} [rc={}]: {}".format(self.qname(), cmd_to_exec[0], r.status(), r.err()))
887887
return r
888+
889+
def __getstate__(self):
890+
"""
891+
Custom serializer for pickle module.
892+
The pickle module implements binary protocols for serializing and de-serializing a Python object structure.
893+
More info here: https://docs.python.org/3/library/pickle.html#object.__getstate__
894+
"""
895+
return {
896+
"name": self.model.metadata.name,
897+
"kind": self.model.kind,
898+
"context": self.context,
899+
}
900+
901+
def __setstate__(self, state):
902+
"""
903+
Custom de-serializing for pickle module.
904+
The pickle module implements binary protocols for serializing and de-serializing a Python object structure.
905+
More info here: https://docs.python.org/3/library/pickle.html#object.__setstate__
906+
"""
907+
with state["context"]:
908+
result = selector(f"{state['kind']}/{state['name']}").object_json()
909+
self.__init__(string_to_model=result)

0 commit comments

Comments
 (0)