# if srcStr is an expr, eval it and store any non-None result in _ codeObj = code.compile_command(srcStr, '<stdin>', 'eval') if codeObj is None: # empty line return with restricted: result = eval(codeObj, restrictedScope) if result is not None: print repr(result) restrictedScope['_'] = result except SyntaxError: # non-expressions are just exec'd and have no effect on _ with restricted: exec codeObj in restrictedScope srcStr = '' else: srcStr += '\n' except: try: (exc_type, exc_value) = sys.exc_info()[:2] traceback.print_exception(exc_type, exc_value, None) finally: exc_type = exc_value = None srcStr = '' protocol.addMessageHook('eval', evalCmd) while True: try: protocol.dispatchMessage(readObject()) except: break
import weakref as _weakref import protocol as _protocol _elements = _weakref.WeakValueDictionary() def _eventHandlerHook(msg): try: _elements[msg['id']].triggerEvent(msg['type']) except: pass _protocol.addMessageHook('event', _eventHandlerHook) class _Element(object): _nextId = 0 def __init__(self, **kwargs): assert self.__class__ is not _Element self.id = _Element._nextId self.parent = None self.eventListeners = None _Element._nextId += 1 _elements[self.id] = self if self.id: _protocol.writeObj({'msg': 'create', 'id': self.id, 'type': self.__class__.__name__}) if not kwargs.get('detached'): _defaultContainer.children.append(self) def __del__(self): _protocol.writeObj({'msg': 'del', 'id': self.id})
if codeObj is None: # empty line return with restricted: result = eval(codeObj, restrictedScope) if result is not None: print repr(result) restrictedScope['_'] = result except SyntaxError: # non-expressions are just exec'd and have no effect on _ with restricted: exec codeObj in restrictedScope srcStr = '' else: srcStr += '\n' except: try: (exc_type, exc_value) = sys.exc_info()[:2] traceback.print_exception(exc_type, exc_value, None) finally: exc_type = exc_value = None srcStr = '' protocol.addMessageHook('eval', evalCmd) while True: try: protocol.dispatchMessage(readObject()) except: break