def __init__(self, host, port=443, conn=None, inflight=100): self.counter = 1 self.deflate = deflator() self.inflate = inflator() self.send_mutex = coro.mutex() http_client.client.__init__(self, host, port, conn, inflight) # replace the fifo with a dictionary (spdy is not serialized) self.pending = {}
def __init__ (self, *args, **kwargs): websocket.__init__ (self, *args, **kwargs) self.send_mutex = coro.mutex() self.repl = repl (self) self.history = [] self.history_index = 0 self.line = [] self.repl.read_eval_print_loop()
def __init__(self, *args, **kwargs): websocket.__init__(self, *args, **kwargs) self.send_mutex = coro.mutex() self.repl = repl(self) self.history = [] self.history_index = 0 self.line = [] self.repl.read_eval_print_loop()
def _trylock(self, key): # Could use setdefault, but that would mean the default argument # would cause a mutex object to be created every time and then thrown # away. if self.locks.has_key(key): lock = self.locks[key] else: lock = self.locks[key] = coro.mutex() return lock.trylock()
def _lock(self, key): # Could use setdefault, but that would mean the default argument # would cause a mutex object to be created every time and then thrown # away. if key in self.locks: lock = self.locks[key] else: lock = self.locks[key] = coro.mutex() lock.lock()
def __init__(self, field, *args, **kwargs): websocket.__init__(self, *args, **kwargs) self.send_mutex = coro.mutex() self.field = field rx = random.randint(0, self.field.w - 1024) ry = random.randint(0, self.field.h - 1024) self.set_rect(rx, ry, rx + 1024, ry + 1024) self.draw_window() self.mouse_down = None, None
def __init__ (self, field, *args, **kwargs): websocket.__init__ (self, *args, **kwargs) self.send_mutex = coro.mutex() self.field = field rx = random.randint (0, self.field.w-1024) ry = random.randint (0, self.field.h-1024) self.set_rect (rx, ry, rx+1024, ry+1024) self.draw_window() self.mouse_down = None, None
def test_unlock_resume(self): """Test that unlock resume.""" m = coro.mutex() coro.spawn(self._test_unlock_resume, m) coro.yield_slice() # This will block, bounce over to other thread. self.assertTrue(m.lock()) self.assertTrue(m.has_lock()) self.assertFalse(m.unlock()) self.assertFalse(m.has_lock())
def trylock(self, key): """trylock(self, key) -> boolean Attempts to lock the mutex. If it is already locked, then it returns 1. If it successfully acquires the lock, it returns 0. """ if self.locks.has_key(key): lock = self.locks[key] else: lock = self.locks[key] = coro.mutex() return lock.trylock()
def test_ownership(self): """Test mutex ownership.""" m = coro.mutex() m.lock() t = coro.spawn(self._test_ownership, m) coro.yield_slice() self.assertTrue(m.has_lock()) self.assertFalse(m.has_lock(t)) self.assertTrue(m.unlock()) coro.yield_slice() self.assertFalse(m.has_lock()) self.assertTrue(m.has_lock(t)) coro.yield_slice()
def __init__(self, proto, http_request, handler): self.request = http_request self.handler = handler self.stream = http_request.client.stream self.conn = http_request.client.conn self.send_mutex = coro.mutex() # tlslite has a deeply buried "except: shutdown()" clause # that breaks coro timeouts. self.tlslite = hasattr(self.conn, 'ignoreAbruptClose') self.proto = proto if proto == 'rfc6455': coro.spawn(self.read_thread) else: coro.spawn(self.read_thread_hixie_76)
def __init__(self, proto, http_request, handler): self.request = http_request self.handler = handler self.stream = http_request.client.stream self.conn = http_request.client.conn self.send_mutex = coro.mutex() # tlslite has a deeply buried "except: shutdown()" clause # that breaks coro timeouts. self.tlslite = hasattr(self.conn, "ignoreAbruptClose") self.proto = proto if proto == "rfc6455": coro.spawn(self.read_thread) else: coro.spawn(self.read_thread_hixie_76)
def __init__ (self, my_addr, other_addr, conn=None): self.my_addr = my_addr self.other_addr = other_addr self.nonce = make_nonce() self.other_version = None self.send_mutex = coro.mutex() if conn is None: if ':' in other_addr[0]: self.conn = coro.tcp6_sock() else: self.conn = coro.tcp_sock() else: self.conn = conn self.packet_count = 0 self.stream = coro.read_stream.sock_stream (self.conn)
def __init__(self, my_addr, other_addr, conn=None): self.my_addr = my_addr self.other_addr = other_addr self.nonce = make_nonce() self.other_version = None self.send_mutex = coro.mutex() if conn is None: if ':' in other_addr[0]: self.conn = coro.tcp6_sock() else: self.conn = coro.tcp_sock() else: self.conn = conn self.packet_count = 0 self.stream = coro.read_stream.sock_stream(self.conn)
def test_multiple_lock(self): """Test locking mutex multiple times.""" m = coro.mutex() self.assertFalse(m.locked()) self.assertFalse(m.has_lock()) self.assertFalse(m.lock()) self.assertTrue(m.locked()) self.assertTrue(m.has_lock()) self.assertFalse(m.lock()) self.assertTrue(m.locked()) self.assertTrue(m.has_lock()) self.assertFalse(m.unlock()) self.assertTrue(m.locked()) self.assertTrue(m.has_lock()) self.assertFalse(m.unlock()) self.assertFalse(m.locked()) self.assertFalse(m.has_lock())
def __init__ (self, my_addr, other_addr, conn=None, log_fun=None, verbose=False, packet=False): self.log_fun = log_fun self.verbose = verbose self.packet = packet self.my_addr = my_addr self.other_addr = other_addr self.nonce = make_nonce() self.other_version = None self.send_mutex = coro.mutex() if conn is None: if ':' in other_addr[0]: self.conn = coro.tcp6_sock() else: self.conn = coro.tcp_sock() else: self.conn = conn self.packet_count = 0 coro.spawn (self.go)
def test_mutex_schedule_interrupt(self): """Test schedule then interrupt on mutex.""" m = coro.mutex() m.lock() self._resume_count = 0 threads = [] # Spawn some threads that will block and be interrupted. for unused in xrange(5): threads.append(coro.spawn(self._mutex_block, m)) # Spawn a thread that we will not interrupt. no_interrupt_thread = coro.spawn(self._mutex_block, m) coro.yield_slice() # Schedule all of the threads. m.unlock() # Now interrupt them. for t in threads: t.shutdown() coro.yield_slice() # Verify that it ran. self.assertEqual(self._resume_count, 1)
def __init__(self, client_transport=None, server_transport=None, debug=None): self.tmc = Thread_Message_Callbacks() self.send_mutex = coro.mutex() # This is the registry of modules that want to receive certain messages. # The key is the module name, the value is a dictionary of message number # to callback function. The function takes 1 parameter (the packet). self.message_callback_registry = {} # This is a mapping of SSH message numbers to the function to call when # that message is received. It is an optimized version computed from # message_callback_registry. self.message_callbacks = {} if debug is None: self.debug = ssh_debug.Debug() else: self.debug = debug if client_transport is None: self.c2s = One_Way_SSH_Transport(self) else: self.c2s = client_transport if server_transport is None: self.s2c = One_Way_SSH_Transport(self) else: self.s2c = server_transport self.supported_key_storages = [OpenSSH_Key_Storage()] # XXX who/what sets self.is_server? can we use self.is_server # to decide which callbacks to register? Or should that be done # by the subclass? self.register_callbacks( '__base__', { SSH_MSG_IGNORE: self.msg_ignore, SSH_MSG_DEBUG: self.msg_debug, SSH_MSG_DISCONNECT: self.msg_disconnect, SSH_MSG_UNIMPLEMENTED: self.msg_unimplemented, # SSH_MSG_KEXINIT:self.msg_kexinit, SSH_MSG_NEWKEYS: self.msg_newkeys, })
def __init__(self, client_transport=None, server_transport=None, debug=None): self.tmc = Thread_Message_Callbacks() self.send_mutex = coro.mutex() # This is the registry of modules that want to receive certain messages. # The key is the module name, the value is a dictionary of message number # to callback function. The function takes 1 parameter (the packet). self.message_callback_registry = {} # This is a mapping of SSH message numbers to the function to call when # that message is received. It is an optimized version computed from # message_callback_registry. self.message_callbacks = {} if debug is None: self.debug = ssh_debug.Debug() else: self.debug = debug if client_transport is None: self.c2s = One_Way_SSH_Transport(self) else: self.c2s = client_transport if server_transport is None: self.s2c = One_Way_SSH_Transport(self) else: self.s2c = server_transport self.supported_key_storages = [OpenSSH_Key_Storage()] # XXX who/what sets self.is_server? can we use self.is_server # to decide which callbacks to register? Or should that be done # by the subclass? self.register_callbacks('__base__', {SSH_MSG_IGNORE: self.msg_ignore, SSH_MSG_DEBUG: self.msg_debug, SSH_MSG_DISCONNECT:self.msg_disconnect, SSH_MSG_UNIMPLEMENTED:self.msg_unimplemented, #SSH_MSG_KEXINIT:self.msg_kexinit, SSH_MSG_NEWKEYS:self.msg_newkeys, } )
def __init__(self, my_addr, other_addr, conn=None, log_fun=None, verbose=False, packet=False): self.log_fun = log_fun self.verbose = verbose self.packet = packet self.my_addr = my_addr self.other_addr = other_addr self.nonce = make_nonce() self.other_version = None self.send_mutex = coro.mutex() if conn is None: if ':' in other_addr[0]: self.conn = coro.tcp6_sock() else: self.conn = coro.tcp_sock() else: self.conn = conn self.packet_count = 0 coro.spawn(self.go)
# furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import coro m = coro.mutex() def test_mutex(): m.lock() coro.spawn(locker, 1) coro.spawn(locker, 2) coro.yield_and_schedule() m.unlock() coro.yield_and_schedule() coro._exit = 1 def locker(n): print 'locker %i' % n m.lock()
def __init__(self): self._lock = coro.mutex()
def __init__ (self, server, *args, **kwargs): self.send_mutex = coro.mutex() self.server = server self.mouse_down = False self.line_start = None, None websocket.__init__ (self, *args, **kwargs)
def __init__(self, server, *args, **kwargs): self.send_mutex = coro.mutex() self.server = server self.mouse_down = False self.line_start = None, None websocket.__init__(self, *args, **kwargs)
# furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import coro m = coro.mutex() def test_mutex(): m.lock() coro.spawn(locker, 1) coro.spawn(locker, 2) coro.yield_and_schedule() m.unlock() coro.yield_and_schedule() coro._exit = 1 def locker(n): print 'locker %i' % n m.lock() print 'locker %i got it' % n m.unlock()