示例#1
0
 def __str__(self):
     sio = StringIO()
     namelen = max(len(n) for n in self.names)
     fmt = '%%%is' % namelen
     for ii, nn in enumerate(self.names):
         print((fmt % nn), self[ii], file=sio)
     return sio.getvalue()
示例#2
0
 def __str__(self):
     sio = StringIO()
     namelen = max(len(n) for n in self.names)
     fmt = '%%%is' % namelen
     for ii, nn in enumerate(self.names):
         print((fmt % nn), self[ii], file=sio)
     return sio.getvalue()
示例#3
0
    def __exit__(self, exc_type, exc_value, traceback):
        for mod, cls in self.simulators.items():
            mod.Simulator = cls
        flag.executing = False

        sys.stdout = sys.__stdout__

        # ensure what has been printed is safe to show in html
        s = self.stdout.getvalue()
        s = s.replace('<', '&lt;').replace('>', '&gt;')
        self.stdout = StringIO(s)

        if not self.allow_sim:
            if self.added_directory is not None:
                sys.path.remove(self.added_directory)
                self.added_directory = None
示例#4
0
    def __enter__(self):
        if self.directory is not None and self.directory not in sys.path:
            sys.path.insert(0, self.directory)
            self.added_directory = self.directory

        self.stdout = StringIO()

        flag.executing = True
        self.simulators = {}

        # add hooks to record stdout

        sys.stdout = self.stdout

        if not self.allow_sim:
            for mod in discover_backends().values():
                self.simulators[mod] = mod.Simulator
                mod.Simulator = make_dummy(mod.Simulator)
示例#5
0
class ExecutionEnvironment(object):
    def __init__(self, filename, allow_sim=False):
        if filename is None:
            self.directory = None
        else:
            self.directory = os.path.dirname(filename)
        self.added_directory = None
        self.allow_sim = allow_sim

    def __enter__(self):
        if self.directory is not None and self.directory not in sys.path:
            sys.path.insert(0, self.directory)
            self.added_directory = self.directory

        self.stdout = StringIO()

        flag.executing = True
        self.simulators = {}

        # add hooks to record stdout

        sys.stdout = self.stdout

        if not self.allow_sim:
            for mod in discover_backends().values():
                self.simulators[mod] = mod.Simulator
                mod.Simulator = make_dummy(mod.Simulator)

    def __exit__(self, exc_type, exc_value, traceback):
        for mod, cls in self.simulators.items():
            mod.Simulator = cls
        flag.executing = False

        sys.stdout = sys.__stdout__

        # ensure what has been printed is safe to show in html
        s = self.stdout.getvalue()
        s = s.replace('<', '&lt;').replace('>', '&gt;')
        self.stdout = StringIO(s)

        if not self.allow_sim:
            if self.added_directory is not None:
                sys.path.remove(self.added_directory)
                self.added_directory = None
示例#6
0
    def __enter__(self):
        if self.directory not in sys.path:
            sys.path.insert(0, self.directory)
            self.added_directory = self.directory

        self.stdout = StringIO()

        flag.executing = True
        del found_modules[:]
        self.simulators = {}

        # add hooks to record stdout

        sys.stdout = self.stdout

        if not self.allow_sim:
            for name in known_modules:
                try:
                    mod = importlib.import_module(name)
                except:
                    continue
                found_modules.append(name)
                self.simulators[mod] = mod.Simulator
                mod.Simulator = make_dummy(mod.Simulator)
示例#7
0
文件: signal.py 项目: utsavakru/nengo
 def __str__(self):
     """Pretty-print the signals and current values."""
     sio = StringIO()
     for k in self:
         sio.write("%s %s\n" % (repr(k), repr(self[k])))
     return sio.getvalue()
示例#8
0
 def __str__(self_):
     sio = StringIO()
     for k in self_:
         print(k, self_[k], file=sio)
     return sio.getvalue()
示例#9
0
 def __str__(self):
     """Pretty-print the signals and current values."""
     sio = StringIO()
     for k in self:
         sio.write("%s %s\n" % (repr(k), repr(self[k])))
     return sio.getvalue()
示例#10
0
 def __str__(self_):
     from nengo.utils.compat import StringIO
     sio = StringIO()
     for k in self_:
         print(k, self_[k], file=sio)
     return sio.getvalue()
示例#11
0
 def __str__(self_):
     from nengo.utils.compat import StringIO
     sio = StringIO()
     for k in self_:
         print(k, self_[k], file=sio)
     return sio.getvalue()
示例#12
0
 def __str__(self_):
     sio = StringIO()
     for k in self_:
         print(k, self_[k], file=sio)
     return sio.getvalue()