##// END OF EJS Templates
Fix #4777 and #7887...
Fix #4777 and #7887 The function in charge of actually converting cursor offset to CodeMirror line number and character number was actually crashing when the cursor was at the last character (loop until undefined, then access length of variable, which is undefined). This was hiding a bug in which when you would completer to a single completion pressing tab after as-you-type filtering, the completion would be completed twice. The logic that was supposed to detect whether or not all completions had a common prefix was actually faulty as the common prefix used to be a string but was then changed to an object. Hence the logic to check whether or not there was actually a common prefix was always true, even for empty string, leading to the deletion of the line (replace by '') in some cases.

File last commit:

r19083:3afade56
r20538:ae7f6d6a
Show More
handlers.py
44 lines | 1.2 KiB | text/x-python | PythonLexer
Thomas Kluyver
Fix docstring, validate JSON on PUT
r18704 """Tornado handlers for frontend config storage."""
Thomas Kluyver
Add REST API for retrieving, storing and updating config
r18703
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import json
import os
import io
Thomas Kluyver
Put frontend config files in profile_foo/nbconfig/ subdir
r18812 import errno
Thomas Kluyver
Add REST API for retrieving, storing and updating config
r18703 from tornado import web
Thomas Kluyver
Fix writing JSON on Python 2
r18706 from IPython.utils.py3compat import PY3
Thomas Kluyver
Add REST API for retrieving, storing and updating config
r18703 from ...base.handlers import IPythonHandler, json_errors
class ConfigHandler(IPythonHandler):
SUPPORTED_METHODS = ('GET', 'PUT', 'PATCH')
@web.authenticated
@json_errors
def get(self, section_name):
self.set_header("Content-Type", 'application/json')
Thomas Kluyver
First stab at ConfigManager class
r19083 self.finish(json.dumps(self.config_manager.get(section_name)))
Thomas Kluyver
Add REST API for retrieving, storing and updating config
r18703
@web.authenticated
@json_errors
def put(self, section_name):
Thomas Kluyver
First stab at ConfigManager class
r19083 data = self.get_json_body() # Will raise 400 if content is not valid JSON
self.config_manager.set(section_name, data)
Thomas Kluyver
Add REST API for retrieving, storing and updating config
r18703 self.set_status(204)
@web.authenticated
@json_errors
def patch(self, section_name):
Thomas Kluyver
First stab at ConfigManager class
r19083 new_data = self.get_json_body()
section = self.config_manager.update(section_name, new_data)
Thomas Kluyver
Return updated config from PATCH requests
r18707 self.finish(json.dumps(section))
Thomas Kluyver
Add REST API for retrieving, storing and updating config
r18703
# URL to handler mappings
section_name_regex = r"(?P<section_name>\w+)"
default_handlers = [
(r"/api/config/%s" % section_name_regex, ConfigHandler),
]