def on_close(e): twitter.disconnect() import AsyncoreThread AsyncoreThread.join() f.Destroy()
def __init__(self, conn = None, family = socket.AF_INET, type = socket.SOCK_STREAM): ''' conn: an existing socket, None (to create a new socket), or False (no socket provided but don't make one yet) family and type default to TCP/IP. Changing them only matters if you don't provide a connection (i.e. it is None). ''' object.__init__(self) self._lock = threading.RLock() self.__refcount = 0 self._proxy_setup = False self.__proxysocket = None self._handlers = [] self.data = '' self.family = family self.type = type if conn is False: #do not use/make a socket at this time async_chat.__init__(self) self.__refcount += 1 AsyncoreThread.start() else: if conn is None: #make a socket async_chat.__init__(self) self.make_socket(family = family, type = type) else: #use an existing socket async_chat.__init__(self, conn) self.__refcount += 1 AsyncoreThread.start()
def __init__(self, conn=None, family=socket.AF_INET, type=socket.SOCK_STREAM): ''' conn: an existing socket, None (to create a new socket), or False (no socket provided but don't make one yet) family and type default to TCP/IP. Changing them only matters if you don't provide a connection (i.e. it is None). ''' object.__init__(self) self._lock = threading.RLock() self.__refcount = 0 self._proxy_setup = False self.__proxysocket = None self._handlers = [] self.data = '' self.family = family self.type = type if conn is False: #do not use/make a socket at this time async_chat.__init__(self) self.__refcount += 1 AsyncoreThread.start() else: if conn is None: #make a socket async_chat.__init__(self) self.make_socket(family=family, type=type) else: #use an existing socket async_chat.__init__(self, conn) self.__refcount += 1 AsyncoreThread.start()
def connect(self, address, use_proxy=True, callback=None): if not (self.family == socket.AF_INET and self.type == socket.SOCK_STREAM): use_proxy = False if use_proxy: proxyinfo = self.GetProxyInfo() else: proxyinfo = {} log.info('asyncsocket.connect%r', address) if isinstance(self, ProxySocket): log.info('\t\twas already a proxy socket') old_error, callback.error = callback.error, lambda: ( self.handle_close(), old_error()) async_chat.connect(self, address) else: if not self._proxy_setup and proxyinfo: log.info('\t\tneed to setup proxies') sck = self.socket self.del_channel() psck = ProxySocket(proxyinfo, sck, self.set_socket) self.__proxysocket = psck import common if common.pref('socket.retry_noproxy', type=bool, default=sys.DEV): def retry_noproxy(*a): log.info("Retry no proxy: %r", self) self.__proxysocket = None self.make_socket(proxy=False, family=self.family, type=self.type) AsyncSocket.connect(self, address, use_proxy=False, callback=callback) psck.connect(address, success=callback.success, error=retry_noproxy) else: psck.connect(address, callback=callback) elif self._proxy_setup: log.info('\t\tproxy was already setup, calling handle_connect') self.handle_connect_event() elif not proxyinfo: log.info('\t\tno proxy neecessary') self._proxy_setup = True AsyncoreThread.call_later( lambda: async_chat.connect(self, address), callback=callback, verbose=False) else: log.info('\t\terrr you didnt finish') pass
def connect(self): if self._request_q is None: self._request_q = [] if self.conn is None: self.conn = self._make_connection() self.bind_events() AsyncoreThread.call_later(self._do_connect)
def make_socket(self, proxy=True, family = socket.AF_INET, type = socket.SOCK_STREAM): if getattr(self, '_fileno', None) is not None: self.del_channel() if proxy: proxy = util.GetProxyInfo() self.create_socket(family, type) self.__refcount += 1 AsyncoreThread.start()
def close(self): def _doit(): log.info('closing socket %r', self) psck = self.__proxysocket if psck is not None: log.info('Closing proxy socket: %r', psck) psck.close() self.__proxysocket = None async_chat.close(self) AsyncoreThread.call_later(_doit)
def make_socket(self, proxy=True, family=socket.AF_INET, type=socket.SOCK_STREAM): if getattr(self, '_fileno', None) is not None: self.del_channel() if proxy: proxy = util.GetProxyInfo() self.create_socket(family, type) self.__refcount += 1 AsyncoreThread.start()
def main(): fix_logging() AsyncoreThread.start() import wx; a = testapp('../../..') a.toggle_crust() from oscar import protocol oscar = protocol('digsby01', 'no passwords', user = object(), server = ('login.oscar.aol.com',5190)) oscar.Connect() oscar.send_im('digsby04', u'hello world') a.MainLoop()
def start(self): ''' turns this server on, if not already ''' if not self.started: self.started = True self.create_socket(AF_INET, SOCK_STREAM) try: self.bind( self.bind_addr ) # GET IP ADDRESS except Exception, e: self.log_info("failed to bind on (%r, %r)" % self.bind_addr) raise e self.listen(5) AsyncoreThread.start()
def main(): fix_logging() AsyncoreThread.start() import wx a = testapp('../../..') a.toggle_crust() from oscar import protocol oscar = protocol('digsby01', 'no passwords', user=object(), server=('login.oscar.aol.com', 5190)) oscar.Connect() oscar.send_im('digsby04', u'hello world') a.MainLoop()
def connect(self, address, use_proxy = True, callback = None): if not (self.family == socket.AF_INET and self.type == socket.SOCK_STREAM): use_proxy = False if use_proxy: proxyinfo = self.GetProxyInfo() else: proxyinfo = {} log.info('asyncsocket.connect%r', address) if isinstance(self, ProxySocket): log.info('\t\twas already a proxy socket') old_error, callback.error = callback.error, lambda : (self.handle_close(), old_error()) async_chat.connect(self, address) else: if not self._proxy_setup and proxyinfo: log.info('\t\tneed to setup proxies') sck = self.socket self.del_channel() psck = ProxySocket(proxyinfo, sck, self.set_socket) self.__proxysocket = psck import common if common.pref('socket.retry_noproxy', type = bool, default = sys.DEV): def retry_noproxy(*a): log.info("Retry no proxy: %r", self) self.__proxysocket = None self.make_socket(proxy = False, family = self.family, type = self.type) AsyncSocket.connect(self, address, use_proxy = False, callback = callback) psck.connect(address, success = callback.success, error = retry_noproxy) else: psck.connect(address, callback = callback) elif self._proxy_setup: log.info('\t\tproxy was already setup, calling handle_connect') self.handle_connect_event() elif not proxyinfo: log.info('\t\tno proxy neecessary') self._proxy_setup = True AsyncoreThread.call_later(lambda: async_chat.connect(self, address), callback = callback, verbose = False) else: log.info('\t\terrr you didnt finish') pass
def test_one_proxy(): global client if not test_proxies: print 'done' client.close() server.close() import AsyncoreThread; AsyncoreThread.end_thread() return pname, proxy = test_proxies.pop(0) myproxy.clear() myproxy.update(proxy) if client is not None: client.close() print ('asyncsocket with proxy = %r' % pname), client = TestClientSocket(on_done = test_one_proxy) client.connect(TEST_ADDR)
def main(): fix_logging() AsyncoreThread.start() import wx; a = testapp('../../..') a.toggle_crust() from jabber import protocol global jabber jargs, jkwargs = connection_settings['gtalk'] jabber = protocol(*jargs, **jkwargs) jabber.Connect() a.MainLoop() try: jabber.Disconnect() except: pass AsyncoreThread.join(timeout = None)
def test_one_proxy(): global client if not test_proxies: print 'done' client.close() server.close() import AsyncoreThread AsyncoreThread.end_thread() return pname, proxy = test_proxies.pop(0) myproxy.clear() myproxy.update(proxy) if client is not None: client.close() print('asyncsocket with proxy = %r' % pname), client = TestClientSocket(on_done=test_one_proxy) client.connect(TEST_ADDR)
def main(): fix_logging() AsyncoreThread.start() import wx a = testapp('../../..') a.toggle_crust() from jabber import protocol global jabber jargs, jkwargs = connection_settings['gtalk'] jabber = protocol(*jargs, **jkwargs) jabber.Connect() a.MainLoop() try: jabber.Disconnect() except: pass AsyncoreThread.join(timeout=None)
return return _default_server_manager.stop_serving(pattern, host, port) def shutdown(): global _default_server_manager if _default_server_manager is None: return _default_server_manager.shutdown() _default_server_manager = None if __name__ == '__main__': logging.basicConfig() import AsyncoreThread as AT AT.start() srv = HTTPServerManager() class ClosingHandler(DefaultHandler): def handle(self, client, request): print 'closing!' client.push('HTTP/1.1 200 OK\r\n' 'Connection: close\r\n' '\r\n' 'server has been shutdown') client.close() srv.shutdown() host, port = srv.serve('/close', ClosingHandler, host='', port=0) srv.serve(lambda *a: True, DefaultHandler, host='', port=0)
def close_when_done(self): AsyncoreThread.call_later(lambda: async_chat.close_when_done(self))
return _default_server_manager.stop_serving(pattern, host, port) def shutdown(): global _default_server_manager if _default_server_manager is None: return _default_server_manager.shutdown() _default_server_manager = None if __name__ == "__main__": logging.basicConfig() import AsyncoreThread as AT AT.start() srv = HTTPServerManager() class ClosingHandler(DefaultHandler): def handle(self, client, request): print "closing!" client.push("HTTP/1.1 200 OK\r\n" "Connection: close\r\n" "\r\n" "server has been shutdown") client.close() srv.shutdown() host, port = srv.serve("/close", ClosingHandler, host="", port=0) srv.serve(lambda *a: True, DefaultHandler, host="", port=0) print AT.net_thread.map import time