Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_setting_from_file():
try:
file = open(EnvironmentSettings.config_path, 'r')
content = file.read()
beakerx_settings = json.loads(content)
if beakerx_settings['beakerx'].get('version') is None:
content = EnvironmentSettings._convert_to_version_2(beakerx_settings)
except IOError:
content = default_config
EnvironmentSettings.save_setting_to_file(default_config)
except ValueError as ex:
print ('Error while parsing beakerx.json: ', ex)
content = default_config
else:
file.close()
return content
def save_setting_to_file(content):
makedirs(paths.jupyter_config_dir(), exist_ok=True)
with fdopen(osopen(EnvironmentSettings.config_path, O_RDWR | O_CREAT, 0o600), 'w+') as file:
file_content = file.read()
new_settings = json.loads(content)
if file_content:
saved_settings = json.loads(file_content)
file.seek(0)
file.truncate()
for setting_name in new_settings['beakerx']:
saved_settings['beakerx'][setting_name] = new_settings['beakerx'][setting_name]
else:
saved_settings = new_settings
file.write(json.dumps(saved_settings, indent=4, sort_keys=True))
def __init__(self, **kw):
super(BeakerXKernelSpec, self).__init__(**kw)
if self.argv[0] == 'java':
args = EnvironmentSettings.read_beakerx_env_settings()
self.argv[1:1] = args
def post(self):
data = tornado.escape.json_decode(self.request.body)
EnvironmentSettings.save_setting_to_file(json.dumps(data))
self.finish(json.dumps(SettingsHandler._read_property()))
def read_setting_from_file():
try:
file = open(EnvironmentSettings.config_path, 'r')
content = file.read()
beakerx_settings = json.loads(content)
if beakerx_settings['beakerx'].get('version') is None:
content = EnvironmentSettings._convert_to_version_2(beakerx_settings)
except IOError:
content = default_config
EnvironmentSettings.save_setting_to_file(default_config)
except ValueError as ex:
print ('Error while parsing beakerx.json: ', ex)
content = default_config
else:
file.close()
return content