@@ -104,21 +104,23 @@ def reset_running_time(self):
104104 self .running_time = 0
105105
106106 def runsource (self , source , filename = None , symbol = 'single' ,
107- encode = True ):
107+ encode = 'auto' ):
108108 """Execute Python code.
109109
110110 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.
113114
114- encode doesn't encode the source, it just adds an encoding comment
115- that specifies the encoding of the source.
116115 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.
118118
119119 In Python 3, source must be a unicode string
120120 In Python 2, source may be latin-1 bytestring or unicode string,
121121 following the interface of code.InteractiveInterpreter"""
122+ if encode == 'auto' :
123+ encode = filename is None
122124 if encode and not py3 :
123125 if isinstance (source , str ):
124126 # encoding only makes sense for bytestrings
0 commit comments