您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526
  1. import json
  2. from collections.abc import Iterable, Sequence
  3. from .segment_group import SegmentGroup
  4. from .segments import ArrayFileSegment, FileSegment, Segment
  5. def to_selector(node_id: str, name: str, paths: Iterable[str] = ()) -> Sequence[str]:
  6. selectors = [node_id, name]
  7. if paths:
  8. selectors.extend(paths)
  9. return selectors
  10. class SegmentJSONEncoder(json.JSONEncoder):
  11. def default(self, o):
  12. if isinstance(o, ArrayFileSegment):
  13. return [v.model_dump() for v in o.value]
  14. elif isinstance(o, FileSegment):
  15. return o.value.model_dump()
  16. elif isinstance(o, SegmentGroup):
  17. return [self.default(seg) for seg in o.value]
  18. elif isinstance(o, Segment):
  19. return o.value
  20. else:
  21. super().default(o)