diff --git a/src/py-opentimelineio/opentimelineio/core/_core_utils.py b/src/py-opentimelineio/opentimelineio/core/_core_utils.py index d58791a67b..548a33fac9 100644 --- a/src/py-opentimelineio/opentimelineio/core/_core_utils.py +++ b/src/py-opentimelineio/opentimelineio/core/_core_utils.py @@ -4,6 +4,7 @@ import types import collections.abc import copy +import json from .. import ( _otio, @@ -14,6 +15,11 @@ AnyVector, PyAny ) +from .. _opentime import ( + RationalTime, + TimeRange, + TimeTransform +) SUPPORTED_VALUE_TYPES = ( @@ -388,3 +394,57 @@ def __deepcopy__(self, *args, **kwargs): @add_method(SerializableObject) def __copy__(self, *args, **kwargs): raise ValueError("SerializableObjects may not be shallow copied.") + + +@add_method(AnyDictionary) +def to_dict(self): + """ + Convert to a built-in dict. It will recursively convert all values + to their corresponding python built-in types. + """ + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) + + +@add_method(AnyVector) +def to_list(self): + """ + Convert to a built-in list. It will recursively convert all values + to their corresponding python built-in types. + """ + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) + + +@add_method(SerializableObject) +def to_dict(self): + """ + Convert to a built-in dict. It will recursively convert all values + to their corresponding python built-in types. + """ + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) + + +@add_method(RationalTime) +def to_dict(self): + """ + Convert to a built-in dict. It will recursively convert all values + to their corresponding python built-in types. + """ + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) + + +@add_method(TimeRange) +def to_dict(self): + """ + Convert to a built-in dict. It will recursively convert all values + to their corresponding python built-in types. + """ + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) + + +@add_method(TimeTransform) +def to_dict(self): + """ + Convert to a built-in dict. It will recursively convert all values + to their corresponding python built-in types. + """ + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0))