Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
link89 committed Nov 2, 2023
1 parent 795dc71 commit e51135d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions ai2_kit/tool/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
from copy import deepcopy
import sys

def _apply_lss(data: dict):
"""
For each value in data, if it is a multiple line string, convert it to LSS.
"""
for k, v in data.items():
if isinstance(v, str) and '\n' in v:
data[k] = LSS(v)
elif isinstance(v, dict):
_apply_lss(v)
elif isinstance(v, list):
for item in v:
if isinstance(item, dict):
_apply_lss(item)

class Yaml:
def __init__(self) -> None:
Expand Down Expand Up @@ -55,3 +42,18 @@ def dump(self, in_place = False, pretty=True):
yaml.dump(data, fp)
else: # to stdout
yaml.dump(data, sys.stdout)


def _apply_lss(data: dict):
"""
For each value in data, if it is a multiple line string, convert it to LSS.
"""
for k, v in data.items():
if isinstance(v, str) and '\n' in v:
data[k] = LSS(v)
elif isinstance(v, dict):
_apply_lss(v)
elif isinstance(v, list):
for item in v:
if isinstance(item, dict):
_apply_lss(item)

0 comments on commit e51135d

Please sign in to comment.