From 366996236fa458226806dd948ffc7c7983ce9373 2011-08-13 22:53:35 From: Brian E. Granger Date: 2011-08-13 22:53:35 Subject: [PATCH] Adding tracebacks, evalue and etype to the nbformat and notebook. --- diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 2f53693..aa272a4 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -166,20 +166,6 @@ class NotebookHandler(web.RequestHandler): # RST web service handlers #----------------------------------------------------------------------------- -_rst_header = """======== -Heading1 -======== - -Heading2 -======== - -Heading3 --------- - -Heading4 -^^^^^^^^ - -""" class RSTHandler(web.RequestHandler): @@ -187,15 +173,14 @@ class RSTHandler(web.RequestHandler): if publish_string is None: raise web.HTTPError(503) body = self.request.body.strip() - source = _rst_header + body - template_path=os.path.join(os.path.dirname(__file__), u'templates', u'rst_template.html') + source = body + # template_path=os.path.join(os.path.dirname(__file__), u'templates', u'rst_template.html') print template_path defaults = {'file_insertion_enabled': 0, 'raw_enabled': 0, '_disable_config': 1, 'stylesheet_path': 0, - 'initial_header_level': 3, - 'template': template_path + # 'template': template_path } try: html = publish_string(source, writer_name='html', @@ -204,8 +189,6 @@ class RSTHandler(web.RequestHandler): except: raise web.HTTPError(400) print html -# html = '\n'.join(html.split('\n')[7:-3]) -# print html self.set_header('Content-Type', 'text/html') self.finish(html) diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index ed305aa..883ec9c 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -204,7 +204,7 @@ var IPython = (function (IPython) { CodeCell.prototype.append_pyerr = function (json) { var tb = json.traceback; - if (tb !== undefined) { + if (tb !== undefined && tb.length > 0) { var s = ''; var len = tb.length; for (var i=0; i").addClass("output_stream"); - toinsert.append($("
").html(utils.fixConsole(data)));
+        toinsert.append($("
").html(data));
         element.append(toinsert);
         return element;
     };
diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js
index 10c31c1..cfd37b6 100644
--- a/IPython/frontend/html/notebook/static/js/notebook.js
+++ b/IPython/frontend/html/notebook/static/js/notebook.js
@@ -520,7 +520,7 @@ var IPython = (function (IPython) {
         var json = {};
         json.output_type = msg_type;
         if (msg_type === "stream") {
-            json.text = content.data + '\n';
+            json.text = utils.fixConsole(content.data + '\n');
         } else if (msg_type === "display_data") {
             json = this.convert_mime_types(json, content.data);
         } else if (msg_type === "pyout") {
@@ -529,7 +529,11 @@ var IPython = (function (IPython) {
         } else if (msg_type === "pyerr") {
             json.ename = content.ename;
             json.evalue = content.evalue;
-            json.traceback = content.traceback;
+            var traceback = [];
+            for (var i=0; i',
         output_json=u'json data',
-        output_javascript=u'var i=0;',
-        prompt_number=4
+        output_javascript=u'var i=0;'
+    ),new_output(
+        output_type=u'pyerr',
+        etype=u'NameError',
+        evalue=u'NameError was here',
+        traceback=[u'frame 0', u'frame 1', u'frame 2']
     )]
 ))
 
@@ -65,7 +69,7 @@ nb0 = new_notebook(
     name='nb0',
     worksheets=[ws, new_worksheet(name='worksheet2')],
     author='Bart Simpson',
-    email='bsimple@fox.com',
+    email='bsimpson@fox.com',
     saved='ISO8601_goes_here',
     created='ISO8601_goes_here',
     license='BSD'
diff --git a/IPython/nbformat/v2/tests/test_nbbase.py b/IPython/nbformat/v2/tests/test_nbbase.py
index f054165..a263e6a 100644
--- a/IPython/nbformat/v2/tests/test_nbbase.py
+++ b/IPython/nbformat/v2/tests/test_nbbase.py
@@ -27,6 +27,14 @@ class TestCell(TestCase):
         self.assertEquals(cc.outputs[0].prompt_number, 0)
         self.assertEquals(cc.collapsed, True)
 
+    def test_pyerr(self):
+        o = new_output(output_type=u'pyerr', etype=u'NameError',
+            evalue=u'Name not found', traceback=[u'frame 0', u'frame 1', u'frame 2']
+        )
+        self.assertEquals(o.output_type, u'pyerr')
+        self.assertEquals(o.etype, u'NameError')
+        self.assertEquals(o.evalue, u'Name not found')
+        self.assertEquals(o.traceback, [u'frame 0', u'frame 1', u'frame 2'])
 
     def test_empty_html_cell(self):
         tc = new_text_cell(u'html')