| 211 | |
| 212 | |
| 213 | def simple_convert(obj): |
| 214 | if obj is None: |
| 215 | return None |
| 216 | elif isinstance(obj, (str, int, float, bool)): |
| 217 | return obj |
| 218 | elif isinstance(obj, dict): |
| 219 | return {k: simple_convert(v) for k, v in obj.items()} |
| 220 | elif isinstance(obj, (list, tuple, set)): |
| 221 | return [simple_convert(item) for item in obj] |
| 222 | |
| 223 | if isinstance(obj, str): |
| 224 | try: |
| 225 | return json.loads(obj) |
| 226 | except: |
| 227 | return obj |
| 228 | |
| 229 | if hasattr(obj, "__dict__"): |
| 230 | for method in ["to_dict", "to_json", "__getstate__", "as_dict"]: |
| 231 | if hasattr(obj, method): |
| 232 | result = getattr(obj, method)() |
| 233 | if isinstance(result, dict): |
| 234 | return simple_convert(result) |
| 235 | elif isinstance(result, str): |
| 236 | try: |
| 237 | return json.loads(result) |
| 238 | except: |
| 239 | return result |
| 240 | |
| 241 | try: |
| 242 | return {k: simple_convert(v) for k, v in vars(obj).items() if not k.startswith("_")} |
| 243 | except Exception: |
| 244 | return str(obj) |
| 245 | |
| 246 | return str(obj) |
| 247 | |
| 248 | |
| 249 | class UsageMessage: |