52
52
from .config import getpreferredencoding
53
53
from .formatter import Parenthesis
54
54
from .history import History
55
+ from .lazyre import LazyReCompile
55
56
from .paste import PasteHelper , PastePinnwand , PasteFailed
56
57
from .patch_linecache import filename_for_console_input
57
58
from .translations import _ , ngettext
@@ -83,6 +84,8 @@ def estimate(self):
83
84
class Interpreter (code .InteractiveInterpreter ):
84
85
"""Source code interpreter for use in bpython."""
85
86
87
+ bpython_input_re = LazyReCompile (r'<bpython-input-\d+>' )
88
+
86
89
def __init__ (self , locals = None , encoding = None ):
87
90
"""Constructor.
88
91
@@ -197,7 +200,7 @@ def showsyntaxerror(self, filename=None):
197
200
else :
198
201
# Stuff in the right filename and right lineno
199
202
# strip linecache line number
200
- if re . match (r'<bpython-input-\d+>' , filename ):
203
+ if self . bpython_input_re . match (filename ):
201
204
filename = '<input>'
202
205
if filename == '<input>' and not py3 :
203
206
lineno -= 2
@@ -220,7 +223,7 @@ def showtraceback(self):
220
223
221
224
for i , (fname , lineno , module , something ) in enumerate (tblist ):
222
225
# strip linecache line number
223
- if re . match (r'<bpython-input-\d+>' , fname ):
226
+ if self . bpython_input_re . match (fname ):
224
227
fname = '<input>'
225
228
tblist [i ] = (fname , lineno , module , something )
226
229
# Set the right lineno (encoding header adds an extra line)
0 commit comments