/usr/lib/python2.7/dist-packages/notebook/static/services/config.js is in python-notebook 5.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | // Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/utils',
],
function(utils) {
"use strict";
var ConfigSection = function(section_name, options) {
this.section_name = section_name;
this.base_url = options.base_url;
this.data = {};
var that = this;
/* .loaded is a promise, fulfilled the first time the config is loaded
* from the server. Code can do:
* conf.loaded.then(function() { ... using conf.data ... });
*/
this._one_load_finished = false;
this.loaded = new Promise(function(resolve, reject) {
that._finish_firstload = resolve;
});
};
ConfigSection.prototype.api_url = function() {
return utils.url_path_join(this.base_url, 'api/config',
utils.encode_uri_components(this.section_name));
};
ConfigSection.prototype._load_done = function() {
if (!this._one_load_finished) {
this._one_load_finished = true;
this._finish_firstload();
}
};
ConfigSection.prototype.load = function() {
var that = this;
return utils.promising_ajax(this.api_url(), {
cache: false,
type: "GET",
dataType: "json",
}).then(function(data) {
that.data = data;
that._load_done();
return data;
});
};
/**
* Modify the config values stored. Update the local data immediately,
* send the change to the server, and use the updated data from the server
* when the reply comes.
*/
ConfigSection.prototype.update = function(newdata) {
$.extend(true, this.data, newdata); // true -> recursive update
var that = this;
return utils.promising_ajax(this.api_url(), {
processData: false,
type : "PATCH",
data: JSON.stringify(newdata),
dataType : "json",
contentType: 'application/json',
}).then(function(data) {
that.data = data;
that._load_done();
return data;
});
};
var ConfigWithDefaults = function(section, defaults, classname) {
this.section = section;
this.defaults = defaults;
this.classname = classname;
};
ConfigWithDefaults.prototype._class_data = function() {
if (this.classname) {
return this.section.data[this.classname] || {};
} else {
return this.section.data;
}
};
/**
* Wait for config to have loaded, then get a value or the default.
* Returns a promise.
*/
ConfigWithDefaults.prototype.get = function(key) {
var that = this;
return this.section.loaded.then(function() {
return that.get_sync(key);
});
};
/**
* Return a config value. If config is not yet loaded, return the default
* instead of waiting for it to load.
*/
ConfigWithDefaults.prototype.get_sync = function(key) {
var data = this._class_data();
if (key === undefined) {
// no key specified, return full config data
return $.extend(true, {}, this.defaults, data);
}
var value = data[key];
if (value !== undefined) {
if (typeof value == 'object') {
// merge with defaults if it's an object
return $.extend(true, {}, this.defaults[key], value);
} else {
return value;
}
}
return this.defaults[key];
};
/**
* Set a config value. Send the update to the server, and change our
* local copy of the data immediately.
* Returns a promise which is fulfilled when the server replies to the
* change.
*/
ConfigWithDefaults.prototype.set = function(key, value) {
var d = {};
d[key] = value;
if (this.classname) {
var d2 = {};
d2[this.classname] = d;
return this.section.update(d2);
} else {
return this.section.update(d);
}
};
return {ConfigSection: ConfigSection,
ConfigWithDefaults: ConfigWithDefaults,
};
});
|