| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dfb44cf commit df29ae1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,21 +104,23 @@ def reset_running_time(self): | |||
| 104 | 104 | self.running_time = 0 | |
| 105 | 105 | ||
| 106 | 106 | def runsource(self, source, filename=None, symbol='single', | |
| 107 | - encode=True): | ||
| 107 | + encode='auto'): | ||
| 108 | 108 | """Execute Python code. | |
| 109 | 109 | ||
| 110 | 110 | source, filename and symbol are passed on to | |
| 111 | - code.InteractiveInterpreter.runsource. If encode is True, the source | ||
| 112 | - will be encoded. On Python 3.X, encode will be ignored. | ||
| 111 | + code.InteractiveInterpreter.runsource. If encode is True, | ||
| 112 | + an encoding comment will be added to the source. | ||
| 113 | + On Python 3.X, encode will be ignored. | ||
| 113 | 114 | ||
| 114 | - encode doesn't encode the source, it just adds an encoding comment | ||
| 115 | - that specifies the encoding of the source. | ||
| 116 | 115 | encode should only be used for interactive interpreter input, | |
| 117 | - files should always have an encoding comment or be ASCII. | ||
| 116 | + files should always already have an encoding comment or be ASCII. | ||
| 117 | + By default an encoding line will be added if no filename is given. | ||
| 118 | 118 | ||
| 119 | 119 | In Python 3, source must be a unicode string | |
| 120 | 120 | In Python 2, source may be latin-1 bytestring or unicode string, | |
| 121 | 121 | following the interface of code.InteractiveInterpreter""" | |
| 122 | + if encode == 'auto': | ||
| 123 | + encode = filename is None | ||
| 122 | 124 | if encode and not py3: | |
| 123 | 125 | if isinstance(source, str): | |
| 124 | 126 | # encoding only makes sense for bytestrings | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,6 @@ def test_exec_dunder_file(self): | |||
| 36 | 36 | ||
| 37 | 37 | self.assertEquals(stderr.strip(), f.name) | |
| 38 | 38 | ||
| 39 | - | ||
| 40 | 39 | def test_exec_nonascii_file(self): | |
| 41 | 40 | with tempfile.NamedTemporaryFile(mode="w") as f: | |
| 42 | 41 | f.write(dedent('''\ | |
@@ -52,6 +51,23 @@ def test_exec_nonascii_file(self): | |||
| 52 | 51 | except subprocess.CalledProcessError: | |
| 53 | 52 | self.fail('Error running module with nonascii characters') | |
| 54 | 53 | ||
| 54 | + def test_exec_nonascii_file_linenums(self): | ||
| 55 | + with tempfile.NamedTemporaryFile(mode="w") as f: | ||
| 56 | + f.write(dedent("""\ | ||
| 57 | + #!/usr/bin/env python2 | ||
| 58 | + # coding: utf-8 | ||
| 59 | + 1/0 | ||
| 60 | + """)) | ||
| 61 | + f.flush() | ||
| 62 | + p = subprocess.Popen( | ||
| 63 | + [sys.executable, "-m", "bpython.curtsies", | ||
| 64 | + f.name], | ||
| 65 | + stderr=subprocess.PIPE, | ||
| 66 | + universal_newlines=True) | ||
| 67 | + (_, stderr) = p.communicate() | ||
| 68 | + | ||
| 69 | + self.assertIn('line 3', stderr) | ||
| 70 | + | ||
| 55 | 71 | ||
| 56 | 72 | class TestParse(TestCase): | |
| 57 | 73 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments