对dict类型数据与yaml串做转换
yaml字符串,如下文:
s = "
spring:
cloud:
nacos:
discovery:
server-addr: nacos.al:8848
dubbo:
registry:
address: nacos://nacos.al:8848
check: false
protocol:
name: dubbo
port: 10014 # dubbo provider才使用该端口,用以提供服务
al:
job:
executor:
logpath: /data/logs/ad-biz-job/xxl-job/jobhandler
port: 15001
auth:
resource:
anon-auth-url: /**
app:
group: line8@s03
business: ActivitiesOperation
system: AdvertisingSystem
owner: zhouxiong@akulaku.com
filter:
text:
FullChainSystemTypeHandler: '未满足全链路配置要求'
RedPackageTypeHandler: '该用户未满足红包配置的限制条件'
AdSpotPresentFreqFilter: '该广告所属广告位已经达到展示频率上线'
AreaFilter: '地区拦截器'
BanFilter: '屏蔽拦截器'
CountryFilter: '国家拦截器'
DeviceIdFilter: '设备号拦截器'
TimeRangeFilter: '时间范围拦截器'
VersionFilter: '版本号拦截器'
CategoryComponentFilter: '不符合商品类目'
CouponComponentFilter: '广告系统关联的优惠券不可用/用户无法领取'
CustomPropertyComponentFilter: '配置的属性值与客户端传入的不匹配'
KeywordComponentFilter: '关键词组件拦截器'
PresentFreqComponentFilter: '该广告已经达到展示频率上限'
PrizeComponentFilter: '广告系统关联的优惠券不可用/用户无法领取'
SPUComponentFilter: '不符合广告配置的商品类目'
UserVisibleFilter: '不符合广告配置的标签人群'
LowerPriorityTypeHandler: '优先级过低'
"
实现代码如下,返回为dict类型
import yaml
def ReadYMLStrToDict(content: str):
data = yaml.load(content,Loader=yaml.FullLoader)
return data
ReadYMLStrToDict(s)
返回报文如下:
{'spring': {'cloud': {'nacos': {'discovery': {'server-addr': 'nacos.al:8848'}}}}, 'dubbo': {'registry': {'address': 'nacos://nacos.al:8848', 'check': False}, 'protocol': {'name': 'dubbo', 'port': 10014}}, 'al': {'job': {'executor': {'logpath': '/data/logs/ad-biz-job/xxl-job/jobhandler', 'port': 15001}}, 'auth': {'resource': {'anon-auth-url': '/**'}}}, 'app': {'group': 'line8@s03', 'business': 'ActivitiesOperation', 'system': 'AdvertisingSystem', 'owner': 'zhouxiong@akulaku.com'}, 'filter': {'text': {'FullChainSystemTypeHandler': '未满足全链路配置要求', 'RedPackageTypeHandler': '该用户未满足红包配置的限制条件', 'AdSpotPresentFreqFilter': '该广告所属广告位已经达到展示频率上线', 'AreaFilter': '地区拦截器', 'BanFilter': '屏蔽拦截器', 'CountryFilter': '国家拦截器', 'DeviceIdFilter': '设备号拦截器', 'TimeRangeFilter': '时间范围拦截器', 'VersionFilter': '版本号拦截器', 'CategoryComponentFilter': '不符合商品类目', 'CouponComponentFilter': '广告系统关联的优惠券不可用/用户无法领取', 'CustomPropertyComponentFilter': '配置的属性值与客户端传入的不匹配', 'KeywordComponentFilter': '关键词组件拦截器', 'PresentFreqComponentFilter': '该广告已经达到展示频率上限', 'PrizeComponentFilter': '广告系统关联的优惠券不可用/用户无法领取', 'SPUComponentFilter': '不符合广告配置的商品类目', 'UserVisibleFilter': '不符合广告配置的标签人群', 'LowerPriorityTypeHandler': '优先级过低'}}}