{"action":"created","comment":{"url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/comments/56518322","id":56518322,"diff_hunk":"@@ -49,9 +52,9 @@ def prefixed_lines():\n         return ''.join(prefixed_lines())\n \n try:\n-    from StringIO import StringIO\n+    from BytesIO import BytesIO\n except ImportError:\n-    from io import StringIO\n+    from io import BytesIO","path":"sphinx_gallery/gen_rst.py","position":21,"original_position":21,"commit_id":"2410e90f59c878e6715ccb178b9cc7381c60fd80","original_commit_id":"2410e90f59c878e6715ccb178b9cc7381c60fd80","user":{"login":"lesteve","id":1680079,"avatar_url":"https://avatars.githubusercontent.com/u/1680079?v=3","gravatar_id":"","url":"https://api.github.com/users/lesteve","html_url":"https://github.com/lesteve","followers_url":"https://api.github.com/users/lesteve/followers","following_url":"https://api.github.com/users/lesteve/following{/other_user}","gists_url":"https://api.github.com/users/lesteve/gists{/gist_id}","starred_url":"https://api.github.com/users/lesteve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lesteve/subscriptions","organizations_url":"https://api.github.com/users/lesteve/orgs","repos_url":"https://api.github.com/users/lesteve/repos","events_url":"https://api.github.com/users/lesteve/events{/privacy}","received_events_url":"https://api.github.com/users/lesteve/received_events","type":"User","site_admin":false},"body":"I think this can be replaced by `from io import StringIO` if you are using the NonUnicodeFriendlyStringIO class below.\r\n\r\nI wasn't aware of this but StringIO.StringIO doesn't have the same behaviour as io.StringIO (both exist in Python 2.7 so it's not a Python 2 vs Python 3 import difference as I naively thought). For example you can both write unicode and non unicode strings into it but then you get into trouble when you are trying to do `.getvalue`:\r\n\r\n```python\r\nfrom StringIO import StringIO\r\ns.write('é')\r\ns.write(u'é')\r\ns.getvalue()\r\n```\r\n\r\n```\r\n---------------------------------------------------------------------------\r\nUnicodeDecodeError                        Traceback (most recent call last)\r\n<ipython-input-7-67a6f2fbafbe> in <module>()\r\n----> 1 s.getvalue()\r\n\r\n/volatile/le243287/miniconda3/envs/py27/lib/python2.7/StringIO.pyc in getvalue(self)\r\n    269         _complain_ifclosed(self.closed)\r\n    270         if self.buflist:\r\n--> 271             self.buf += ''.join(self.buflist)\r\n    272             self.buflist = []\r\n    273         return self.buf\r\n\r\nUnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)\r\n```","created_at":"2016-03-17T15:01:53Z","updated_at":"2016-03-17T15:01:53Z","html_url":"https://github.com/sphinx-gallery/sphinx-gallery/pull/106#discussion_r56518322","pull_request_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/106","_links":{"self":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/comments/56518322"},"html":{"href":"https://github.com/sphinx-gallery/sphinx-gallery/pull/106#discussion_r56518322"},"pull_request":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/106"}}},"pull_request":{"url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/106","id":62691973,"html_url":"https://github.com/sphinx-gallery/sphinx-gallery/pull/106","diff_url":"https://github.com/sphinx-gallery/sphinx-gallery/pull/106.diff","patch_url":"https://github.com/sphinx-gallery/sphinx-gallery/pull/106.patch","issue_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/issues/106","number":106,"state":"open","locked":false,"title":"[MRG+1]: Allow unicode in code and outputs","user":{"login":"Eric89GXL","id":2365790,"avatar_url":"https://avatars.githubusercontent.com/u/2365790?v=3","gravatar_id":"","url":"https://api.github.com/users/Eric89GXL","html_url":"https://github.com/Eric89GXL","followers_url":"https://api.github.com/users/Eric89GXL/followers","following_url":"https://api.github.com/users/Eric89GXL/following{/other_user}","gists_url":"https://api.github.com/users/Eric89GXL/gists{/gist_id}","starred_url":"https://api.github.com/users/Eric89GXL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eric89GXL/subscriptions","organizations_url":"https://api.github.com/users/Eric89GXL/orgs","repos_url":"https://api.github.com/users/Eric89GXL/repos","events_url":"https://api.github.com/users/Eric89GXL/events{/privacy}","received_events_url":"https://api.github.com/users/Eric89GXL/received_events","type":"User","site_admin":false},"body":"Previously, [our] (https://github.com/mne-tools/mne-python) code had unicode in the `stdout` which gave:\r\n```\r\n../examples/preprocessing/plot_maxwell_filter.py is not compiling:\r\nTraceback (most recent call last):\r\n  File \"/home/larsoner/custombuilds/sphinx-gallery/sphinx_gallery/gen_rst.py\", line 474, in execute_script\r\n    my_stdout = my_buffer.getvalue().strip().expandtabs()\r\n  File \"/usr/lib/python2.7/StringIO.py\", line 271, in getvalue\r\n    self.buf += ''.join(self.buflist)\r\nUnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 36: ordinal not in range(128)\r\n```\r\nModified a test that fails on `master` and passes on this PR.\r\n\r\nWorks on my system (™) on Py3k and Python 2.7.\r\n\r\nCloses #18.\r\nCloses #19.","created_at":"2016-03-14T01:47:55Z","updated_at":"2016-03-17T15:01:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d0bf923a83327530ab32a8bd937f980751534e2a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/106/commits","review_comments_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/106/comments","review_comment_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/issues/106/comments","statuses_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/statuses/2410e90f59c878e6715ccb178b9cc7381c60fd80","head":{"label":"Eric89GXL:unicode","ref":"unicode","sha":"2410e90f59c878e6715ccb178b9cc7381c60fd80","user":{"login":"Eric89GXL","id":2365790,"avatar_url":"https://avatars.githubusercontent.com/u/2365790?v=3","gravatar_id":"","url":"https://api.github.com/users/Eric89GXL","html_url":"https://github.com/Eric89GXL","followers_url":"https://api.github.com/users/Eric89GXL/followers","following_url":"https://api.github.com/users/Eric89GXL/following{/other_user}","gists_url":"https://api.github.com/users/Eric89GXL/gists{/gist_id}","starred_url":"https://api.github.com/users/Eric89GXL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eric89GXL/subscriptions","organizations_url":"https://api.github.com/users/Eric89GXL/orgs","repos_url":"https://api.github.com/users/Eric89GXL/repos","events_url":"https://api.github.com/users/Eric89GXL/events{/privacy}","received_events_url":"https://api.github.com/users/Eric89GXL/received_events","type":"User","site_admin":false},"repo":{"id":39034777,"name":"sphinx-gallery","full_name":"Eric89GXL/sphinx-gallery","owner":{"login":"Eric89GXL","id":2365790,"avatar_url":"https://avatars.githubusercontent.com/u/2365790?v=3","gravatar_id":"","url":"https://api.github.com/users/Eric89GXL","html_url":"https://github.com/Eric89GXL","followers_url":"https://api.github.com/users/Eric89GXL/followers","following_url":"https://api.github.com/users/Eric89GXL/following{/other_user}","gists_url":"https://api.github.com/users/Eric89GXL/gists{/gist_id}","starred_url":"https://api.github.com/users/Eric89GXL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eric89GXL/subscriptions","organizations_url":"https://api.github.com/users/Eric89GXL/orgs","repos_url":"https://api.github.com/users/Eric89GXL/repos","events_url":"https://api.github.com/users/Eric89GXL/events{/privacy}","received_events_url":"https://api.github.com/users/Eric89GXL/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Eric89GXL/sphinx-gallery","description":"Sphinx extension for automatic generation of an example gallery","fork":true,"url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery","forks_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/forks","keys_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/teams","hooks_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/hooks","issue_events_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/issues/events{/number}","events_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/events","assignees_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/assignees{/user}","branches_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/branches{/branch}","tags_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/tags","blobs_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/git/refs{/sha}","trees_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/statuses/{sha}","languages_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/languages","stargazers_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/stargazers","contributors_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/contributors","subscribers_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/subscribers","subscription_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/subscription","commits_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/commits{/sha}","git_commits_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/git/commits{/sha}","comments_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/comments{/number}","issue_comment_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/issues/comments{/number}","contents_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/contents/{+path}","compare_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/merges","archive_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/downloads","issues_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/issues{/number}","pulls_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/pulls{/number}","milestones_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/milestones{/number}","notifications_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/labels{/name}","releases_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/releases{/id}","deployments_url":"https://api.github.com/repos/Eric89GXL/sphinx-gallery/deployments","created_at":"2015-07-13T20:10:41Z","updated_at":"2015-07-13T20:10:41Z","pushed_at":"2016-03-17T13:16:23Z","git_url":"git://github.com/Eric89GXL/sphinx-gallery.git","ssh_url":"git@github.com:Eric89GXL/sphinx-gallery.git","clone_url":"https://github.com/Eric89GXL/sphinx-gallery.git","svn_url":"https://github.com/Eric89GXL/sphinx-gallery","homepage":"http://sphinx-gallery.readthedocs.org","size":624,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sphinx-gallery:master","ref":"master","sha":"feb9f8c5d203b5781f7de446b5ef307db068cc05","user":{"login":"sphinx-gallery","id":9541799,"avatar_url":"https://avatars.githubusercontent.com/u/9541799?v=3","gravatar_id":"","url":"https://api.github.com/users/sphinx-gallery","html_url":"https://github.com/sphinx-gallery","followers_url":"https://api.github.com/users/sphinx-gallery/followers","following_url":"https://api.github.com/users/sphinx-gallery/following{/other_user}","gists_url":"https://api.github.com/users/sphinx-gallery/gists{/gist_id}","starred_url":"https://api.github.com/users/sphinx-gallery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sphinx-gallery/subscriptions","organizations_url":"https://api.github.com/users/sphinx-gallery/orgs","repos_url":"https://api.github.com/users/sphinx-gallery/repos","events_url":"https://api.github.com/users/sphinx-gallery/events{/privacy}","received_events_url":"https://api.github.com/users/sphinx-gallery/received_events","type":"Organization","site_admin":false},"repo":{"id":25860190,"name":"sphinx-gallery","full_name":"sphinx-gallery/sphinx-gallery","owner":{"login":"sphinx-gallery","id":9541799,"avatar_url":"https://avatars.githubusercontent.com/u/9541799?v=3","gravatar_id":"","url":"https://api.github.com/users/sphinx-gallery","html_url":"https://github.com/sphinx-gallery","followers_url":"https://api.github.com/users/sphinx-gallery/followers","following_url":"https://api.github.com/users/sphinx-gallery/following{/other_user}","gists_url":"https://api.github.com/users/sphinx-gallery/gists{/gist_id}","starred_url":"https://api.github.com/users/sphinx-gallery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sphinx-gallery/subscriptions","organizations_url":"https://api.github.com/users/sphinx-gallery/orgs","repos_url":"https://api.github.com/users/sphinx-gallery/repos","events_url":"https://api.github.com/users/sphinx-gallery/events{/privacy}","received_events_url":"https://api.github.com/users/sphinx-gallery/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sphinx-gallery/sphinx-gallery","description":"Sphinx extension for automatic generation of an example gallery","fork":false,"url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery","forks_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/forks","keys_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/teams","hooks_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/hooks","issue_events_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/issues/events{/number}","events_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/events","assignees_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/assignees{/user}","branches_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/branches{/branch}","tags_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/tags","blobs_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/git/refs{/sha}","trees_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/statuses/{sha}","languages_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/languages","stargazers_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/stargazers","contributors_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/contributors","subscribers_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/subscribers","subscription_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/subscription","commits_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/commits{/sha}","git_commits_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/git/commits{/sha}","comments_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/comments{/number}","issue_comment_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/issues/comments{/number}","contents_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/contents/{+path}","compare_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/merges","archive_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/downloads","issues_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/issues{/number}","pulls_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls{/number}","milestones_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/milestones{/number}","notifications_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/labels{/name}","releases_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/releases{/id}","deployments_url":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/deployments","created_at":"2014-10-28T08:41:46Z","updated_at":"2016-03-12T22:10:33Z","pushed_at":"2016-03-17T14:52:03Z","git_url":"git://github.com/sphinx-gallery/sphinx-gallery.git","ssh_url":"git@github.com:sphinx-gallery/sphinx-gallery.git","clone_url":"https://github.com/sphinx-gallery/sphinx-gallery.git","svn_url":"https://github.com/sphinx-gallery/sphinx-gallery","homepage":"http://sphinx-gallery.readthedocs.org","size":688,"stargazers_count":32,"watchers_count":32,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":22,"forks":13,"open_issues":22,"watchers":32,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/106"},"html":{"href":"https://github.com/sphinx-gallery/sphinx-gallery/pull/106"},"issue":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/issues/106"},"comments":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/issues/106/comments"},"review_comments":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/106/comments"},"review_comment":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/pulls/106/commits"},"statuses":{"href":"https://api.github.com/repos/sphinx-gallery/sphinx-gallery/statuses/2410e90f59c878e6715ccb178b9cc7381c60fd80"}}}}