MCPcopy Create free account
hub / github.com/StackStorm/st2 / load

Method load

st2common/st2common/content/loader.py:233–264  ·  view source on GitHub ↗

Loads content from file_path if file_path's extension is one of allowed ones (See ALLOWED_EXTS). Throws UnsupportedMetaException on disallowed filetypes. Throws ValueError on malformed meta. :param file_path: Absolute path to the file to load content from.

(self, file_path, expected_type=None)

Source from the content-addressed store, hash-verified

231 """
232
233 def load(self, file_path, expected_type=None):
234 """
235 Loads content from file_path if file_path's extension
236 is one of allowed ones (See ALLOWED_EXTS).
237
238 Throws UnsupportedMetaException on disallowed filetypes.
239 Throws ValueError on malformed meta.
240
241 :param file_path: Absolute path to the file to load content from.
242 :type file_path: ``str``
243
244 :param expected_type: Expected type for the loaded and parsed content (optional).
245 :type expected_type: ``object``
246
247 :rtype: ``dict``
248 """
249 file_name, file_ext = os.path.splitext(file_path)
250
251 if file_ext not in ALLOWED_EXTS:
252 raise Exception(
253 "Unsupported meta type %s, file %s. Allowed: %s"
254 % (file_ext, file_path, ALLOWED_EXTS)
255 )
256
257 result = self._load(PARSER_FUNCS[file_ext], file_path)
258
259 if expected_type and not isinstance(result, expected_type):
260 actual_type = type(result).__name__
261 error = 'Expected "%s", got "%s"' % (expected_type.__name__, actual_type)
262 raise ValueError(error)
263
264 return result
265
266 def _load(self, parser_func, file_path):
267 with open(file_path, "r", encoding="utf-8") as fd:

Callers 15

mainFunction · 0.95
get_pack_metadataFunction · 0.95
json_2_yaml_convertFunction · 0.80
loaderMethod · 0.80
save_fixtures_to_dbMethod · 0.80
load_fixturesMethod · 0.80
load_modelsMethod · 0.80
pre_runMethod · 0.80

Calls 1

_loadMethod · 0.95

Tested by 3

test_yaml_safe_loadMethod · 0.64