当前位置: 首页>>代码示例>>Python>>正文


Python sys.__displayhook__方法代码示例

本文整理汇总了Python中sys.__displayhook__方法的典型用法代码示例。如果您正苦于以下问题:Python sys.__displayhook__方法的具体用法?Python sys.__displayhook__怎么用?Python sys.__displayhook__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.__displayhook__方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_original_displayhook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __displayhook__ [as 别名]
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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_sys.py

示例2: dhook_wrap

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __displayhook__ [as 别名]
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 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:doctestreload.py

示例3: _reset_py_display

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __displayhook__ [as 别名]
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__ 
开发者ID:TuuuNya,项目名称:WebPocket,代码行数:24,代码来源:cmd2.py

示例4: test_original_displayhook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __displayhook__ [as 别名]
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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_sys.py

示例5: test_original_displayhook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __displayhook__ [as 别名]
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 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:27,代码来源:test_sys.py

示例6: debugger

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __displayhook__ [as 别名]
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 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:45,代码来源:ultratb.py

示例7: cleanup

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __displayhook__ [as 别名]
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' ] 
开发者ID:dnanexus,项目名称:parliament2,代码行数:61,代码来源:ROOT.py

示例8: cleanup

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __displayhook__ [as 别名]
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' ] 
开发者ID:XENON1T,项目名称:pax,代码行数:59,代码来源:modified_ROOT_v5.34.25.py


注:本文中的sys.__displayhook__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。