Skip to content

Commit 9862e48

Browse files
committed
define simple repr and str
function on security_content_object so that they can be printed out without cycle/recursion issues
1 parent ced6164 commit 9862e48

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

contentctl/objects/abstract_security_content_objects/security_content_object_abstract.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import abc
1313
import uuid
1414
import datetime
15+
import pprint
1516
from pydantic import BaseModel, field_validator, Field, ValidationInfo, FilePath, HttpUrl, NonNegativeInt, ConfigDict, model_validator, model_serializer
1617
from typing import Tuple, Optional, List, Union
1718
import pathlib
@@ -181,6 +182,22 @@ def create_filename_to_content_dict(all_objects:list[SecurityContentObject_Abstr
181182
for object in all_objects:
182183
name_dict[str(pathlib.Path(object.file_path))] = object
183184
return name_dict
185+
186+
187+
def __repr__(self)->str:
188+
# Just use the model_dump functionality that
189+
# has already been written. This loses some of the
190+
# richness where objects reference themselves, but
191+
# is usable
192+
m = self.model_dump()
193+
return pprint.pformat(m, indent=3)
194+
195+
def __str__(self)->str:
196+
return(self.__repr__())
197+
198+
199+
200+
184201

185202

186203

0 commit comments

Comments
 (0)