##// END OF EJS Templates
Backport PR #4163: Fix for incorrect default encoding on Windows....
Backport PR #4163: Fix for incorrect default encoding on Windows. Whilst trying out rendering notebooks in a flask app under Apache on Windows I got the below error when simply trying to import `SlidesExporter` ```python mod_wsgi (pid=6260): Exception occurred processing WSGI script 'flask_test.wsgi'. Traceback (most recent call last): File "flask_test.py", line 81, in render_notebook from IPython.nbconvert.exporters import SlidesExporter File "c:\\dev\\code\\ipython\\IPython\\__init__.py", line 47, in <module> from .terminal.embed import embed File "c:\\dev\\code\\ipython\\IPython\\terminal\\embed.py", line 32, in <module> from IPython.terminal.interactiveshell import TerminalInteractiveShell File "c:\\dev\\code\\ipython\\IPython\\terminal\\interactiveshell.py", line 25, in <module> from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC File "c:\\dev\\code\\ipython\\IPython\\core\\interactiveshell.py", line 59, in <module> from IPython.core.prompts import PromptManager File "c:\\dev\\code\\ipython\\IPython\\core\\prompts.py", line 138, in <module> HOME = py3compat.str_to_unicode(os.environ.get("HOME","//////:::::ZZZZZ,,,~~~")) File "c:\\dev\\code\\ipython\\IPython\\utils\\py3compat.py", line 18, in decode return s.decode(encoding, "replace") LookupError: unknown encoding: cp0 ``` A little bit of [googling](http://bugs.python.org/issue6501) suggests that Windows returns 'cp0' to indicate there is no code page. This fix simply looks for this invalid value and replaces it with something valid. With this change it works for me.

File last commit:

r11033:fa36e98f
r12463:516353d0
Show More
default.js
90 lines | 3.3 KiB | application/javascript | JavascriptLexer
Matthias BUSSONNIER
add default celltoolbar UI
r9078 //----------------------------------------------------------------------------
// Copyright (C) 2012 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
// CellToolbar Default
//============================================================================
/**
* Example Use for the CellToolbar library
*/
// IIFE without asignement, we don't modifiy the IPython namespace
(function (IPython) {
"use strict";
var CellToolbar = IPython.CellToolbar;
var raw_edit = function(cell){
var md = cell.metadata
var error_div = $('<div/>').css('color','red')
var textarea = $('<textarea/>')
.attr('rows','13')
.attr('cols','75')
.attr('name','metadata')
.text(JSON.stringify(md, null,4)||'');
var dialogform = $('<div/>').attr('title','Edit the metadata')
.append(
$('<form/>').append(
$('<fieldset/>').append(
$('<label/>')
.attr('for','metadata')
Matthias BUSSONNIER
Load default.js (for celltoolbar) by default...
r9079 .text("Manually edit the JSON below to manipulate the metadata for this cell. This assumes you know what you are doing and won't complain if it breaks your notebook. We also recommend putting your metadata attributes in an appropriately named sub-structure, so they don't conflict with those of others.")
Matthias BUSSONNIER
add default celltoolbar UI
r9078 )
.append(error_div)
.append($('<br/>'))
.append(
textarea
)
)
);
var editor = CodeMirror.fromTextArea(textarea[0], {
lineNumbers: true,
matchBrackets: true,
});
MinRK
fix cell toolbar
r10935 IPython.dialog.modal({
title: "Edit Cell Metadata",
body: dialogform,
Matthias BUSSONNIER
add default celltoolbar UI
r9078 buttons: {
MinRK
fix cell toolbar
r10935 "OK": { class : "btn-primary",
click: function() {
Matthias BUSSONNIER
add default celltoolbar UI
r9078 //validate json and set it
try {
var json = JSON.parse(editor.getValue());
cell.metadata = json;
MinRK
fix cell toolbar
r10935 } catch(e) {
Matthias BUSSONNIER
add default celltoolbar UI
r9078 error_div.text('Warning, invalid json, not saved');
MinRK
fix cell toolbar
r10935 return false;
Matthias BUSSONNIER
add default celltoolbar UI
r9078 }
MinRK
fix cell toolbar
r10935 }},
Cancel: {}
Matthias BUSSONNIER
add default celltoolbar UI
r9078 }
});
editor.refresh();
}
var add_raw_edit_button = function(div, cell) {
MinRK
fix cell toolbar
r10935 var button_container = div;
var button = $('<button/>')
.addClass("btn btn-mini")
.text("Raw Edit")
.click( function () {
raw_edit(cell);
return false;
});
Matthias BUSSONNIER
add default celltoolbar UI
r9078 button_container.append(button);
}
CellToolbar.register_callback('default.rawedit',add_raw_edit_button);
var example_preset = []
example_preset.push('default.rawedit');
Matthias BUSSONNIER
Capitalize
r9082 CellToolbar.register_preset('Default',example_preset);
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 console.log('Default extension for metadata editing loaded.');
Matthias BUSSONNIER
add default celltoolbar UI
r9078
}(IPython));