MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / _convert_value

Function _convert_value

src/config/settings.py:598–642  ·  view source on GitHub ↗

将数据库字符串值转换为正确的类型

(attr_name: str, value: str)

Source from the content-addressed store, hash-verified

596
597
598def _convert_value(attr_name: str, value: str) -> Any:
599 """将数据库字符串值转换为正确的类型"""
600 if attr_name in SECRET_FIELDS:
601 return SecretStr(value) if value else SecretStr("")
602
603 target_type = SETTING_TYPES.get(attr_name, str)
604
605 if target_type == bool:
606 if isinstance(value, bool):
607 return value
608 return str(value).lower() in ("true", "1", "yes", "on")
609 elif target_type == int:
610 if isinstance(value, int):
611 return value
612 return int(value) if value else 0
613 elif target_type == dict:
614 if isinstance(value, dict):
615 return value
616 if not value:
617 return {}
618 import json
619 import ast
620 try:
621 return json.loads(value)
622 except (json.JSONDecodeError, ValueError):
623 try:
624 return ast.literal_eval(value)
625 except Exception:
626 return {}
627 elif target_type == list:
628 if isinstance(value, list):
629 return value
630 if not value:
631 return []
632 import json
633 import ast
634 try:
635 return json.loads(value)
636 except (json.JSONDecodeError, ValueError):
637 try:
638 return ast.literal_eval(value)
639 except Exception:
640 return []
641 else:
642 return value
643
644
645def _normalize_database_url(url: str) -> str:

Callers 1

_load_settings_from_dbFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected