Exemplo n.º 1
0
def asynchook(v):
  import builtins
  if iscoroutine(v):
    builtins._ = get_event_loop().run_until_complete(v)
    pprint.pprint(builtins._)
  else:
    sys.__displayhook__(v)
Exemplo n.º 2
0
 def auto_display(value):
     if dt_display_hook:
         expr = dt_display_hook(value)
     if hasattr(value, "_repr_html_"):
         print_html(value._repr_html_())
         return
     sys.__displayhook__(value)
Exemplo n.º 3
0
def asynchook(v):
    import builtins
    if iscoroutine(v):
        builtins._ = get_event_loop().run_until_complete(v)
        pprint.pprint(builtins._)
    else:
        sys.__displayhook__(v)
Exemplo n.º 4
0
 def __call__(self, value):
     print
     print ' Previous:', self.previous_value
     print ' New      :', value
     print
     if value != self.previous_value:
         self.count += 1
         sys.ps1 = '(%3d)>' % self.count
     self.previous_value = value
     sys.__displayhook__(value)
 def __call__(self, value):
     print()
     print('  Precedente:', self.previous_value)
     print('  Nuovo     :', value)
     print()
     if value != self.previous_value:
         self.count += 1
         sys.ps1 = '({:3d})> '.format(self.count)
     self.previous_value = value
     sys.__displayhook__(value)
Exemplo n.º 6
0
 def __call__(self, value):
     print()
     print('  Previous:', self.previous_value)
     print('  New     :', value)
     print()
     if value != self.previous_value:
         self.count += 1
         sys.ps1 = '({:3d})> '.format(self.count)
     self.previous_value = value
     sys.__displayhook__(value)
Exemplo n.º 7
0
 def __call__(self, value):
     print
     print '  Previous:', self.previous_value
     print '  New     :', value
     print
     if value != self.previous_value:
         self.count += 1
         sys.ps1 = '(%3d)> ' % self.count
     self.previous_value = value
     sys.__displayhook__(value)
Exemplo n.º 8
0
    def test_original_displayhook_unencodable(self):
        import sys, _io
        out = _io.BytesIO()
        savestdout = sys.stdout
        sys.stdout = _io.TextIOWrapper(out, encoding='ascii')

        sys.__displayhook__("a=\xe9 b=\uDC80 c=\U00010000 d=\U0010FFFF")
        assert (out.getvalue() ==
                b"'a=\\xe9 b=\\udc80 c=\\U00010000 d=\\U0010ffff'")

        sys.stdout = savestdout
Exemplo n.º 9
0
    def test_original_displayhook_unencodable(self):
        import sys, _io
        out = _io.BytesIO()
        savestdout = sys.stdout
        sys.stdout = _io.TextIOWrapper(out, encoding='ascii')

        sys.__displayhook__("a=\xe9 b=\uDC80 c=\U00010000 d=\U0010FFFF")
        assert (out.getvalue() ==
                b"'a=\\xe9 b=\\udc80 c=\\U00010000 d=\\U0010ffff'")

        sys.stdout = savestdout
Exemplo n.º 10
0
def displayhook(value):
    """
    Runs all of the registered display hook methods with the given value.
    Look at the sys.displayhook documentation for more information.
    
    :param      value | <variant>
    """
    global _displayhooks
    new_hooks = []

    for hook_ref in _displayhooks:
        hook = hook_ref()
        if hook:
            hook(value)
            new_hooks.append(hook_ref)

    _displayhooks = new_hooks

    sys.__displayhook__(value)
Exemplo n.º 11
0
def displayhook(value):
    """
    Runs all of the registered display hook methods with the given value.
    Look at the sys.displayhook documentation for more information.
    
    :param      value | <variant>
    """
    global _displayhooks
    new_hooks = []

    for hook_ref in _displayhooks:
        hook = hook_ref()
        if hook:
            hook(value)
            new_hooks.append(hook_ref)

    _displayhooks = new_hooks

    sys.__displayhook__(value)
Exemplo n.º 12
0
 def display_hook(self, obj):
     try:
         if obj is None:
             return
         if print_hooks.is_pretty_printable(obj):
             if print_hooks.needs_packing(obj):
                 packed = print_hooks.pack_for_transport(obj)
                 if not self.write_object.emit(packed):
                     logger.debug(msg("error sending packed object"))
                     sys.stdout.write(print_hooks.html_repr(obj))
             else:
                 if not self.write_object.emit(obj):
                     logger.debug(msg("error sending object"))
                     logger.debug(msg("error sending packed object"))
                     sys.stdout.write(print_hooks.html_repr(obj))
         else:
             logger.debug(msg("object", obj, "is not prettyprintable"))
             sys.stdout.write(repr(obj))
         return
     except Exception, e:
         logger.debug(msg("Exception", e, "encountered while printing object", obj))
         sys.__displayhook__(obj)
Exemplo n.º 13
0
def pretty_print (object):
    """
    Try to pretty print the object in an intelligent way. For many
    things, this will convert the object to latex inside of html and
    rely on a latex-aware front end (like jsMath) to render the text
    """
    if object is None:
        return
    import __builtin__
    __builtin__._=object

    from sage.plot.plot import Graphics
    from sage.plot.plot3d.base import Graphics3d
    if isinstance(object, (Graphics, Graphics3d)):
        print repr(object)
        return
    else:
        try:
            print '<html><span class="math">%s</span></html>'%latex(object)
        except:
            import sys
            sys.__displayhook__(object)
Exemplo n.º 14
0
 def displayhook(obj):
     sys.__displayhook__(obj)
     monitor.refresh()
Exemplo n.º 15
0
# while True:
#   # output to stdout:
#   print "Yet another iteration ..."
#   try:
#     # reading from sys.stdin (stop with Ctrl-D):
#     number = raw_input("Enter a number: ")
#   except EOFError:
#     print "\nciao"
#     break
#   else:
#     number = int(number)
#     if number == 0:
#       print >> sys.stderr, "0 has no inverse"
#     else:
#       print "inverse of %d is %f" % (number, 1.0/number) 

print sys.__displayhook__(None)
print sys.float_info.dig

print '\n'
for i in sys.argv:
    print i
    
print '\n'
print 'The PYTHONPATH is ', sys.path
for i in sys.path:
    print i
    
print '\n'
user_input = sys.stdin.readline
print("User input: " + user_input)
Exemplo n.º 16
0
 def displayhook(obj):
     sys.__displayhook__(obj)
     monitor.refresh()
Exemplo n.º 17
0
 def __call__(self, value):
     if not self.history or value != self.history[-1]:
         self.count += 1
         sys.ps1 = '(%d)> ' % self.count
         self.history.append(value)
     sys.__displayhook__(value)