Bases: BaseModel
Pretty-print as YAML style outputs.
Source code in passengersim/config/pretty.py
| class PrettyModel(BaseModel):
"""Pretty-print as YAML style outputs."""
def __repr_with_indent__(self, indent=0):
x = []
i = " " * indent
for k, v in self:
try:
val = v.__repr_with_indent__(0)
except AttributeError:
if isinstance(v, dict):
val = repr_dict_with_indent(v, indent)
else:
val = repr(v)
if isinstance(v, list) and len(val) > 70:
val = "- " + "\n- ".join(repr(j) for j in v)
if "\n" in val:
val_lines = val.split("\n")
val = "\n " + "\n ".join(val_lines)
x.append(f"{i}{k}: {val}")
return "\n".join(x)
def __repr__(self):
return f"{self.__class__.__name__}:\n" + self.__repr_with_indent__(2)
|
__repr__
Source code in passengersim/config/pretty.py
| def __repr__(self):
return f"{self.__class__.__name__}:\n" + self.__repr_with_indent__(2)
|
__repr_with_indent__
__repr_with_indent__(indent=0)
Source code in passengersim/config/pretty.py
| def __repr_with_indent__(self, indent=0):
x = []
i = " " * indent
for k, v in self:
try:
val = v.__repr_with_indent__(0)
except AttributeError:
if isinstance(v, dict):
val = repr_dict_with_indent(v, indent)
else:
val = repr(v)
if isinstance(v, list) and len(val) > 70:
val = "- " + "\n- ".join(repr(j) for j in v)
if "\n" in val:
val_lines = val.split("\n")
val = "\n " + "\n ".join(val_lines)
x.append(f"{i}{k}: {val}")
return "\n".join(x)
|