本文整理汇总了Python中munch.Munch.fromDict方法的典型用法代码示例。如果您正苦于以下问题:Python Munch.fromDict方法的具体用法?Python Munch.fromDict怎么用?Python Munch.fromDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类munch.Munch
的用法示例。
在下文中一共展示了Munch.fromDict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_data_from
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import fromDict [as 别名]
def load_data_from(file_name, mode=None, external_params_name=None):
"""We assume that 'external_params' is a a valid json if passed
"""
external_params = BuiltIn().\
get_variable_value('${{{name}}}'.format(name=external_params_name))
if not os.path.exists(file_name):
file_name = os.path.join(os.path.dirname(__file__), 'data', file_name)
with open(file_name) as file_obj:
if file_name.endswith('.json'):
file_data = Munch.fromDict(load(file_obj))
elif file_name.endswith('.yaml'):
file_data = Munch.fromYAML(file_obj)
if mode == 'brokers':
default = file_data.pop('Default')
brokers = {}
for k, v in file_data.iteritems():
brokers[k] = merge_dicts(default, v)
file_data = brokers
try:
ext_params_munch \
= Munch.fromDict(loads(external_params)) \
if external_params else Munch()
except ValueError:
raise ValueError(
'Value {param} of command line parameter {name} is invalid'.
format(name=external_params_name, param=str(external_params))
)
return merge_dicts(file_data, ext_params_munch)
示例2: _check_session
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import fromDict [as 别名]
def _check_session(self):
if not 'FLASK_FAS_OPENID_USER' in flask.session \
or flask.session['FLASK_FAS_OPENID_USER'] is None:
flask.g.fas_user = None
else:
user = flask.session['FLASK_FAS_OPENID_USER']
# Add approved_memberships to provide backwards compatibility
# New applications should only use g.fas_user.groups
user['approved_memberships'] = []
for group in user['groups']:
membership = dict()
membership['name'] = group
user['approved_memberships'].append(Munch.fromDict(membership))
flask.g.fas_user = Munch.fromDict(user)
flask.g.fas_user.groups = frozenset(flask.g.fas_user.groups)
flask.g.fas_session_id = 0
示例3: load_initial_data_from
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import fromDict [as 别名]
def load_initial_data_from(file_name):
if not os.path.exists(file_name):
file_name = os.path.join(os.path.dirname(__file__), 'data/{}'.format(file_name))
with open(file_name) as file_obj:
if file_name.endswith(".json"):
return Munch.fromDict(load(file_obj))
elif file_name.endswith(".yaml"):
return fromYAML(file_obj)
示例4: load_data_from_file
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import fromDict [as 别名]
def load_data_from_file(file_name):
if not os.path.exists(file_name):
file_name = os.path.join(os.path.dirname(__file__), file_name)
with open(file_name) as file_obj:
if file_name.endswith(".json"):
return Munch.fromDict(load(file_obj))
elif file_name.endswith(".yaml"):
return Munch.fromYAML(file_obj)
示例5: load_data_from
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import fromDict [as 别名]
def load_data_from(file_name, mode=None):
if not os.path.exists(file_name):
file_name = os.path.join(os.path.dirname(__file__), 'data', file_name)
with open(file_name) as file_obj:
if file_name.endswith(".json"):
file_data = Munch.fromDict(load(file_obj))
elif file_name.endswith(".yaml"):
file_data = fromYAML(file_obj)
if mode == "brokers":
default = file_data.pop('Default')
brokers = {}
for k, v in file_data.iteritems():
brokers[k] = merge_dicts(default, v)
return brokers
else:
return file_data
示例6: test_fromDict
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import fromDict [as 别名]
def test_fromDict():
b = Munch.fromDict({'urmom': {'sez': {'what': 'what'}}})
assert b.urmom.sez.what == 'what'