##// END OF EJS Templates
fix base64 code in nbformat.v2...
fix base64 code in nbformat.v2 base64 encoding functions were called, but had no effect, because the notebook already has everything as b64-encoded bytestrings, which are valid ascii literals on Python 2. However, the encode/decode logic is actually triggered on Python 3, revealing its errors. This fixes the base64 functions that had no effect to have their intended effect, but does not use them. Rather, it is assumed that bytes objects are already b64-encoded (and thus ascii-safe), which assumption was already made in Python 2.

File last commit:

r4500:79472ea0
r5174:66077063
Show More
heartbeat.py
49 lines | 1.5 KiB | text/x-python | PythonLexer
"""The client and server for a basic ping-pong style heartbeat.
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2010 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import socket
import sys
from threading import Thread
import zmq
from IPython.utils.localinterfaces import LOCALHOST
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class Heartbeat(Thread):
"A simple ping-pong style heartbeat that runs in a thread."
def __init__(self, context, addr=(LOCALHOST, 0)):
Thread.__init__(self)
self.context = context
self.addr = addr
self.ip = addr[0]
self.port = addr[1]
if self.port == 0:
s = socket.socket()
s.bind(self.addr)
self.port = s.getsockname()[1]
s.close()
self.addr = (self.ip, self.port)
self.daemon = True
def run(self):
self.socket = self.context.socket(zmq.REP)
self.socket.bind('tcp://%s:%i' % self.addr)
zmq.device(zmq.FORWARDER, self.socket, self.socket)