-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_script.py
More file actions
54 lines (37 loc) · 1.14 KB
/
exec_script.py
File metadata and controls
54 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import division
from math import *
from ngspice.syntax import *
from ngspice.simulator import *
__env__ = {k:v for k,v in globals().iteritems()}
import sys, os
import code
from cStringIO import StringIO
__all__= ['Interpy']
class Interpy(code.InteractiveInterpreter):
__env__ = __env__
def __init__(self, locals={}):
env = Interpy.__env__
if isinstance(locals, dict):
env.update(locals)
code.InteractiveInterpreter.__init__(self, locals=env)
self.stdout = ""
self.stderr = ""
def runcode(self, code):
sys.stdout = stdout = StringIO()
sys.stderr = stderr = StringIO()
try:
exec code in self.locals
except SystemExit:
pass
except:
self.showtraceback()
finally:
sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__
self.stdout = stdout.getvalue()
self.stderr = stderr.getvalue()
stdout.close()
stderr.close()
def context(self):
return self.__dict__['locals']