Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __prepare_file(file: dict, variables: dict):
resources = variables['RESOURCES_DIR']
[file_key] = [k for k in file.keys() if k != 'type']
filepath = file[file_key]
file_type = file.get('type', 'text/plain')
filename = file_utils.get_filename(filepath)
file = fill_template_str(file_utils.read_file(os.path.join(resources, filepath)), variables)
return file_key, (filename, file, file_type)
def __form_body(self, variables) -> tuple:
if self.method == 'get':
return False, None
body = self.body
if body is None and self.file is not None:
resources = variables['RESOURCES_DIR']
body = file_utils.read_file(fill_template_str(os.path.join(resources, self.file), variables))
if isinstance(body, dict) or isinstance(body, list): # dump body to json to be able fill templates in
body = json.dumps(body)
if body is None:
return False, None
isjson = 'tojson' in body
return isjson, fill_template(body, variables, isjson=isjson)
def action(self, includes: dict, variables: dict) -> tuple:
if self.source_file: # read from file
resources = variables['RESOURCES_DIR']
out = fill_template_str(read_file(os.path.join(resources, self.source_file)), variables)
else:
out = fill_template(self.source, variables)
if self.dst is None:
info(out)
else:
dst = fill_template(self.dst, variables)
with open(join(self.path, dst), 'w') as f:
f.write(str(out))
return variables, out
def __form_body(self, variables):
data = self.data
if data is None:
data = read_file(fill_template_str(self.file, variables))
return fill_template_str(data, variables)