mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
python/samba/ndr: add ndr_deepcopy() helper
This uses ndr_pack/unpack in order to create a deep copy of the given object. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
parent
9ea06aaf9f
commit
4627997dda
@ -56,6 +56,25 @@ def ndr_print(object):
|
||||
return ndr_print()
|
||||
|
||||
|
||||
def ndr_deepcopy(object):
|
||||
"""Create a deep copy of a NDR object, using pack/unpack
|
||||
|
||||
:param object: Object to copy
|
||||
:return: The object copy
|
||||
"""
|
||||
ndr_pack = getattr(object, "__ndr_pack__", None)
|
||||
if ndr_pack is None:
|
||||
raise TypeError("%r is not a NDR object" % object)
|
||||
data = ndr_pack()
|
||||
cls = type(object)
|
||||
copy = cls()
|
||||
ndr_unpack = getattr(copy, "__ndr_unpack__", None)
|
||||
if ndr_unpack is None:
|
||||
raise TypeError("%r is not a NDR object" % copy)
|
||||
ndr_unpack(data, allow_remaining=False)
|
||||
return copy
|
||||
|
||||
|
||||
def ndr_pack_in(object, bigendian=False, ndr64=False):
|
||||
"""Pack the input of an NDR function object.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user