Python sys.__displayhook__() Examples
The following are 17
code examples of sys.__displayhook__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: test_sys.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_original_displayhook(self): import builtins out = io.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(builtins, "_"): del builtins._ dh(None) self.assertEqual(out.getvalue(), "") self.assertTrue(not hasattr(builtins, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(builtins._, 42) del sys.stdout self.assertRaises(RuntimeError, dh, 42)
Example #2
Source File: test_sys.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_original_displayhook(self): import __builtin__ savestdout = sys.stdout out = cStringIO.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(__builtin__, "_"): del __builtin__._ dh(None) self.assertEqual(out.getvalue(), "") self.assert_(not hasattr(__builtin__, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(__builtin__._, 42) if not test.test_support.is_jython: del sys.stdout self.assertRaises(RuntimeError, dh, 42) sys.stdout = savestdout
Example #3
Source File: test_sys.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_original_displayhook(self): import __builtin__ savestdout = sys.stdout out = cStringIO.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(__builtin__, "_"): del __builtin__._ dh(None) self.assertEqual(out.getvalue(), "") self.assert_(not hasattr(__builtin__, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(__builtin__._, 42) if not test.test_support.is_jython: del sys.stdout self.assertRaises(RuntimeError, dh, 42) sys.stdout = savestdout
Example #4
Source File: test_sys.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_original_displayhook(self): import __builtin__ savestdout = sys.stdout out = cStringIO.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(__builtin__, "_"): del __builtin__._ dh(None) self.assertEqual(out.getvalue(), "") self.assert_(not hasattr(__builtin__, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(__builtin__._, 42) if not test.test_support.is_jython: del sys.stdout self.assertRaises(RuntimeError, dh, 42) sys.stdout = savestdout
Example #5
Source File: test_sys.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_original_displayhook(self): import builtins out = io.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(builtins, "_"): del builtins._ dh(None) self.assertEqual(out.getvalue(), "") self.assertTrue(not hasattr(builtins, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(builtins._, 42) del sys.stdout self.assertRaises(RuntimeError, dh, 42)
Example #6
Source File: cmd2.py From cmd2 with MIT License | 6 votes |
def _reset_py_display() -> None: """ Resets the dynamic objects in the sys module that the py and ipy consoles fight over. When a Python console starts it adopts certain display settings if they've already been set. If an ipy console has previously been run, then py uses its settings and ends up looking like an ipy console in terms of prompt and exception text. This method forces the Python console to create its own display settings since they won't exist. IPython does not have this problem since it always overwrites the display settings when it is run. Therefore this method only needs to be called before creating a Python console. """ # Delete any prompts that have been set attributes = ['ps1', 'ps2', 'ps3'] for cur_attr in attributes: try: del sys.__dict__[cur_attr] except KeyError: pass # Reset functions sys.displayhook = sys.__displayhook__ sys.excepthook = sys.__excepthook__
Example #7
Source File: test_sys.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_original_displayhook(self): import __builtin__ savestdout = sys.stdout out = cStringIO.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(__builtin__, "_"): del __builtin__._ dh(None) self.assertEqual(out.getvalue(), "") self.assertTrue(not hasattr(__builtin__, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(__builtin__._, 42) del sys.stdout self.assertRaises(RuntimeError, dh, 42) sys.stdout = savestdout
Example #8
Source File: test_sys.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_original_displayhook(self): import __builtin__ savestdout = sys.stdout out = cStringIO.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(__builtin__, "_"): del __builtin__._ dh(None) self.assertEqual(out.getvalue(), "") self.assertTrue(not hasattr(__builtin__, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(__builtin__._, 42) del sys.stdout self.assertRaises(RuntimeError, dh, 42) sys.stdout = savestdout
Example #9
Source File: test_sys.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_original_displayhook(self): import builtins out = io.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(builtins, "_"): del builtins._ dh(None) self.assertEqual(out.getvalue(), "") self.assertTrue(not hasattr(builtins, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(builtins._, 42) del sys.stdout self.assertRaises(RuntimeError, dh, 42)
Example #10
Source File: cmd2.py From WebPocket with GNU General Public License v3.0 | 6 votes |
def _reset_py_display() -> None: """ Resets the dynamic objects in the sys module that the py and ipy consoles fight over. When a Python console starts it adopts certain display settings if they've already been set. If an ipy console has previously been run, then py uses its settings and ends up looking like an ipy console in terms of prompt and exception text. This method forces the Python console to create its own display settings since they won't exist. IPython does not have this problem since it always overwrites the display settings when it is run. Therefore this method only needs to be called before creating a Python console. """ # Delete any prompts that have been set attributes = ['ps1', 'ps2', 'ps3'] for cur_attr in attributes: try: del sys.__dict__[cur_attr] except KeyError: pass # Reset functions sys.displayhook = sys.__displayhook__ sys.excepthook = sys.__excepthook__
Example #11
Source File: test_sys.py From oss-ftp with MIT License | 6 votes |
def test_original_displayhook(self): import __builtin__ savestdout = sys.stdout out = cStringIO.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(__builtin__, "_"): del __builtin__._ dh(None) self.assertEqual(out.getvalue(), "") self.assertTrue(not hasattr(__builtin__, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(__builtin__._, 42) del sys.stdout self.assertRaises(RuntimeError, dh, 42) sys.stdout = savestdout
Example #12
Source File: doctestreload.py From Computable with MIT License | 6 votes |
def dhook_wrap(func,*a,**k): """Wrap a function call in a sys.displayhook controller. Returns a wrapper around func which calls func, with all its arguments and keywords unmodified, using the default sys.displayhook. Since IPython modifies sys.displayhook, it breaks the behavior of certain systems that rely on the default behavior, notably doctest. """ def f(*a,**k): dhook_s = sys.displayhook sys.displayhook = sys.__displayhook__ try: out = func(*a,**k) finally: sys.displayhook = dhook_s return out f.__doc__ = func.__doc__ return f
Example #13
Source File: test_sys.py From BinderFilter with MIT License | 6 votes |
def test_original_displayhook(self): import __builtin__ savestdout = sys.stdout out = cStringIO.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) if hasattr(__builtin__, "_"): del __builtin__._ dh(None) self.assertEqual(out.getvalue(), "") self.assertTrue(not hasattr(__builtin__, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") self.assertEqual(__builtin__._, 42) del sys.stdout self.assertRaises(RuntimeError, dh, 42) sys.stdout = savestdout
Example #14
Source File: ROOT.py From parliament2 with Apache License 2.0 | 4 votes |
def cleanup(): # save for later isCocoa = _root.gSystem.InheritsFrom( 'TMacOSXSystem' ) # restore hooks import sys sys.displayhook = sys.__displayhook__ if not _is_ipython: sys.excepthook = sys.__excepthook__ __builtin__.__import__ = _orig_ihook facade = sys.modules[ __name__ ] # shutdown GUI thread, as appropriate (always save to call) if hasattr( _root, 'RemoveGUIEventInputHook' ): _root.RemoveGUIEventInputHook() # prevent further spurious lookups into ROOT libraries del facade.__class__.__getattr__ del facade.__class__.__setattr__ # shutdown GUI thread, as appropriate if hasattr( facade, 'PyGUIThread' ): facade.keeppolling = 0 # if not shutdown from GUI (often the case), wait for it import threading if threading.currentThread() != facade.PyGUIThread: facade.PyGUIThread.join( 3. ) # arbitrary del threading # remove otherwise (potentially) circular references import types items = facade.module.__dict__.items() for k, v in items: if type(v) == types.ModuleType: facade.module.__dict__[ k ] = None del v, k, items, types # destroy facade facade.__dict__.clear() del facade if 'libPyROOT' in sys.modules: # run part the gROOT shutdown sequence ... running it here ensures that # it is done before any ROOT libraries are off-loaded, with unspecified # order of static object destruction; gROOT = sys.modules[ 'libPyROOT' ].gROOT gROOT.EndOfProcessCleanups() del gROOT # cleanup cached python strings sys.modules[ 'libPyROOT' ]._DestroyPyStrings() # destroy ROOT extension module del sys.modules[ 'libPyROOT' ] # destroy ROOT module del sys.modules[ 'ROOT' ]
Example #15
Source File: modified_ROOT_v5.34.25.py From pax with BSD 3-Clause "New" or "Revised" License | 4 votes |
def cleanup(): return # restore hooks import sys sys.displayhook = sys.__displayhook__ if not '__IPYTHON__' in __builtins__: sys.excepthook = sys.__excepthook__ builtins.__import__ = _orig_ihook facade = sys.modules[ __name__ ] # reset gRootModule on the C++ side to prevent fruther lookups _root._ResetRootModule() # shutdown GUI thread, as appropriate (always save to call) _root.RemoveGUIEventInputHook() # prevent further spurious lookups into ROOT libraries del facade.__class__.__getattr__ del facade.__class__.__setattr__ # shutdown GUI thread, as appropriate if hasattr( facade, 'PyGUIThread' ): facade.keeppolling = 0 # if not shutdown from GUI (often the case), wait for it import threading if threading.currentThread() != facade.PyGUIThread: facade.PyGUIThread.join( 3. ) # arbitrary del threading # remove otherwise (potentially) circular references import types items = list(facade.module.__dict__.items()) for k, v in items: if type(v) == types.ModuleType: facade.module.__dict__[ k ] = None del v, k, items, types # destroy facade facade.__dict__.clear() del facade # run part the gROOT shutdown sequence ... running it here ensures that # it is done before any ROOT libraries are off-loaded, with unspecified # order of static object destruction; gROOT = sys.modules[ 'libPyROOT' ].gROOT gROOT.EndOfProcessCleanups(True) del gROOT # cleanup cached python strings sys.modules[ 'libPyROOT' ]._DestroyPyStrings() # destroy ROOT extension module and ROOT module del sys.modules[ 'libPyROOT' ] del sys.modules[ 'ROOT' ]
Example #16
Source File: modified_ROOT_v6.02.05.py From pax with BSD 3-Clause "New" or "Revised" License | 4 votes |
def cleanup(): return # restore hooks import sys sys.displayhook = sys.__displayhook__ if not '__IPYTHON__' in __builtins__: sys.excepthook = sys.__excepthook__ builtins.__import__ = _orig_ihook facade = sys.modules[ __name__ ] # reset gRootModule on the C++ side to prevent fruther lookups _root._ResetRootModule() # shutdown GUI thread, as appropriate (always save to call) _root.RemoveGUIEventInputHook() # prevent further spurious lookups into ROOT libraries del facade.__class__.__getattr__ del facade.__class__.__setattr__ # shutdown GUI thread, as appropriate if hasattr( facade, 'PyGUIThread' ): facade.keeppolling = 0 # if not shutdown from GUI (often the case), wait for it import threading if threading.currentThread() != facade.PyGUIThread: facade.PyGUIThread.join( 3. ) # arbitrary del threading # remove otherwise (potentially) circular references import types items = list(facade.module.__dict__.items()) for k, v in items: if type(v) == types.ModuleType: facade.module.__dict__[ k ] = None del v, k, items, types # destroy facade facade.__dict__.clear() del facade # run part the gROOT shutdown sequence ... running it here ensures that # it is done before any ROOT libraries are off-loaded, with unspecified # order of static object destruction; gROOT = sys.modules[ 'libPyROOT' ].gROOT gROOT.EndOfProcessCleanups(True) del gROOT # cleanup cached python strings sys.modules[ 'libPyROOT' ]._DestroyPyStrings() # destroy ROOT extension module and ROOT module del sys.modules[ 'libPyROOT' ] del sys.modules[ 'ROOT' ]
Example #17
Source File: ultratb.py From Computable with MIT License | 4 votes |
def debugger(self,force=False): """Call up the pdb debugger if desired, always clean up the tb reference. Keywords: - force(False): by default, this routine checks the instance call_pdb flag and does not actually invoke the debugger if the flag is false. The 'force' option forces the debugger to activate even if the flag is false. If the call_pdb flag is set, the pdb interactive debugger is invoked. In all cases, the self.tb reference to the current traceback is deleted to prevent lingering references which hamper memory management. Note that each call to pdb() does an 'import readline', so if your app requires a special setup for the readline completers, you'll have to fix that by hand after invoking the exception handler.""" if force or self.call_pdb: if self.pdb is None: self.pdb = debugger.Pdb( self.color_scheme_table.active_scheme_name) # the system displayhook may have changed, restore the original # for pdb display_trap = DisplayTrap(hook=sys.__displayhook__) with display_trap: self.pdb.reset() # Find the right frame so we don't pop up inside ipython itself if hasattr(self,'tb') and self.tb is not None: etb = self.tb else: etb = self.tb = sys.last_traceback while self.tb is not None and self.tb.tb_next is not None: self.tb = self.tb.tb_next if etb and etb.tb_next: etb = etb.tb_next self.pdb.botframe = etb.tb_frame self.pdb.interaction(self.tb.tb_frame, self.tb) if hasattr(self,'tb'): del self.tb