@@ -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
0 commit comments