/usr/lib/python2.7/dist-packages/sagenb/notebook/conf.py is in python-sagenb 1.0.1+ds1-2.
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | # -*- coding: utf-8 -*
"""nodoctest
Configuration
"""
from __future__ import absolute_import
#############################################################################
# Copyright (C) 2007 William Stein <wstein@gmail.com>
# Distributed under the terms of the GNU General Public License (GPL)
# The full text of the GPL is available at:
# http://www.gnu.org/licenses/
#############################################################################
from flask_babel import gettext, lazy_gettext
POS = 'pos'
DESC = 'desc'
GROUP = 'group'
TYPE = 'type'
CHOICES = 'choices'
T_BOOL = 0
T_INTEGER = 1
T_CHOICE = 2
T_REAL = 3
T_COLOR = 4
T_STRING = 5
T_LIST = 6
T_INFO = 7
POS_DEFAULT = 100
class Configuration(object):
def __init__(self):
self.confs = {}
def __repr__(self):
return 'Configuration: %s'%self.confs
def __eq__(self, other):
return self.__class__ is other.__class__ and self.confs == other.confs
def __ne__(self, other):
return not self.__eq__(other)
def basic(self):
return self.confs
def defaults(self):
raise NotImplementedError
def defaults_descriptions(self):
raise NotImplementedError
def __getitem__(self, key):
try:
return self.confs[key]
except KeyError:
if key in self.defaults():
A = self.defaults()[key]
self.confs[key] = A
return A
else:
raise KeyError("No key '%s' and no default for this key"%key)
def __setitem__(self, key, value):
self.confs[key] = value
def html_conf_form(self, action):
D = self.defaults()
C = self.confs
K = list(set(self.confs.keys() + D.keys()))
K.sort()
options = ''
for key in K:
options += '<tr><td>%s</td><td><input type="text" name="%s" value="%s"></td></tr>\n'%(key, key, self[key])
s = """
<form method="post" action="%s" enctype="multipart/form-data">
<input type="submit" value="Submit">
<table border=0 cellpadding=5 cellspacing=2>
%s
</table>
</form>
"""%(action, options)
return s
def update_from_form(self, form):
D = self.defaults()
DS = self.defaults_descriptions()
C = self.confs
keys = list(set(C.keys() + D.keys()))
updated = {}
for key in keys:
try:
typ = DS[key][TYPE]
except KeyError:
# We skip this setting. Perhaps defaults_descriptions
# is not in sync with defaults, someone has tampered
# with the request arguments, etc.
continue
val = form.get(key, '')
if typ == T_BOOL:
if val:
val = True
else:
val = False
elif typ == T_INTEGER:
try:
val = int(val)
except ValueError:
val = self[key]
elif typ == T_REAL:
try:
val = float(val)
except ValueError:
val = self[key]
elif typ == T_LIST:
val = val.strip()
if val == '' or val == 'None':
val = None
else:
val = val.split(',')
if typ != T_INFO and self[key] != val:
self[key] = val
updated[key] = ('updated', gettext('Updated'))
return updated
def html_table(self, updated = {}):
from .server_conf import G_LDAP
# check if LDAP can be used
try:
from ldap import __version__ as ldap_version
except ImportError:
ldap_version = None
# For now, we assume there's a description for each setting.
D = self.defaults()
DS = self.defaults_descriptions()
C = self.confs
K = set(C.keys() + D.keys())
G = {}
# Make groups
for key in K:
try:
gp = DS[key][GROUP]
# don't display LDAP settings if the check above failed
if gp == G_LDAP and ldap_version is None:
continue
DS[key][DESC]
DS[key][TYPE]
except KeyError:
# We skip this setting. It's obsolete and/or
# defaults_descriptions is not up to date. See
# *_conf.py for details.
continue
try:
G[gp].append(key)
except KeyError:
G[gp] = [key]
s = u''
color_picker = 0
special_init = u''
for group in G:
s += u'<div class="section">\n <h2>%s</h2>\n <table>\n' % lazy_gettext(group)
opts = G[group]
def sort_key(x):
return (DS[x].get(POS, POS_DEFAULT), x)
opts.sort(key=sort_key)
for o in opts:
s += u' <tr>\n <td>%s</td>\n <td>\n' % lazy_gettext(DS[o][DESC])
input_type = 'text'
input_value = self[o]
extra = ''
if DS[o][TYPE] == T_BOOL:
input_type = 'checkbox'
if input_value:
extra = 'checked="checked"'
if DS[o][TYPE] == T_LIST:
if input_value is not None:
input_value = ','.join(input_value)
if DS[o][TYPE] == T_CHOICE:
s += u' <select name="%s" id="%s">\n' % (o, o)
for c in DS[o][CHOICES]:
selected = ''
if c == input_value:
selected = u' selected="selected"'
s += u' <option value="%s"%s>%s</option>\n' % (c, selected, lazy_gettext(c))
s += u' </select>\n'
elif DS[o][TYPE] == T_INFO:
s += u' <span>%s</span>'%input_value
else:
s += u' <input type="%s" name="%s" id="%s" value="%s" %s>\n' % (input_type, o, o, input_value, extra)
if DS[o][TYPE] == T_COLOR:
s += u' <div id="picker_%s"></div>\n' % color_picker
color_picker += 1
s += u' </td>\n <td class="%s">%s</td>\n </tr>\n' % updated.get(o, ('', ''))
s += u' </table>\n</div>\n'
s += u'<script type="text/javascript">\n$(document).ready(function() {\n' + special_init + '});\n</script>'
lines = s.split(u'\n')
lines = map(lambda x: u' ' + x, lines)
return u'\n'.join(lines)
|