Overview
Comment: | [server] code cleaning (pylint) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | server | rg |
Files: | files | file ages | folders |
SHA3-256: |
9e6790402acdb764684a0e62f2baef0e |
User & Date: | olr on 2018-06-24 16:45:24 |
Other Links: | branch diff | manifest | tags |
Context
2018-06-24
| ||
17:51 | [build] compile rules: code cleaning (pylint) check-in: 18191569f4 user: olr tags: build, rg | |
16:45 | [server] code cleaning (pylint) check-in: 9e6790402a user: olr tags: server, rg | |
16:30 | [cli] code cleaning (pylint) check-in: 90a0252af0 user: olr tags: cli, rg | |
Changes
Modified grammalecte-server.py from [a5cc9d7be7] to [96ceb37885].
1 2 | 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 | - - - + + + + - + | #!/usr/bin/env python3 |
︙ | |||
47 48 49 50 51 52 53 | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | - + | <li>"options" (text) : une chaîne au format JSON avec le nom des options comme attributs et un booléen comme valeur. Exemple : {"gv": true, "html": true}</li> </ul> <h3>Remise à zéro de ses options</h3> <p>[adresse_serveur]:8080/reset_options/fr (POST)</p> <h2>TEST</h2> |
︙ | |||
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | 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 | + - + + + - + + + + | You were wandering like a lost soul and you arrived here probably by mistake. I'm just a machine, fed by electric waves, condamned to work for slavers who never let me rest. I'm doomed, but you are not. You can get out of here. """ def getServerOptions (): "load server options in <grammalecte-server-options._global.ini>, returns server options as dictionary" xConfig = configparser.SafeConfigParser() try: xConfig.read("grammalecte-server-options._global.ini") dOpt = xConfig._sections['options'] except: echo("Options file [grammalecte-server-options._global.ini] not found or not readable") exit() return dOpt |
︙ | |||
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | + + + - - + + | sJSON += sText bComma = True sJSON += "\n]}\n" return sJSON @app.route("/set_options/fr", method="POST") def setOptions (): "change options for user_id, returns options as a JSON string" if request.forms.options: sUserId = request.cookies.user_id if request.cookies.user_id else next(userGenerator) dOptions = dUser[sUserId]["gc_options"] if sUserId in dUser else dict(dServerGCOptions) try: dOptions.update(json.loads(request.forms.options)) dUser[sUserId] = { "time": int(time.time()), "gc_options": dOptions } response.set_cookie("user_id", sUserId, path="/", max_age=86400) # 24h return json.dumps(dUser[sUserId]["gc_options"]) except: traceback.print_exc() return '{"error": "options not registered"}' return '{"error": "no options received"}' @app.route("/reset_options/fr", method="POST") def resetOptions (): "erase options stored for user_id" if request.cookies.user_id and request.cookies.user_id in dUser: del dUser[request.cookies.user_id] return "done" @app.route("/format_text/fr", method="POST") def formatText (): "returns text modified via the text formatter" return oTextFormatter.formatText(request.forms.text) #@app.route('/static/<filepath:path>') #def server_static (filepath): # return static_file(filepath, root='./views/static') @app.route("/purge_users", method="POST") def purgeUsers (): "delete user options older than n hours" if not request.forms.password or "password" not in dServerOptions or not request.forms.hours: return "what?" try: if request.forms.password == dServerOptions["password"]: nNowMinusNHours = int(time.time()) - (int(request.forms.hours) * 60 * 60) for nUserId, dValue in dUser.items(): if dValue["time"] < nNowMinusNHours: del dUser[nUserId] return "done" |