def __init__(self, socket=None, host='', port=0): """ Establish a new XML stream. Arguments: socket -- Use an existing socket for the stream. Defaults to None to generate a new socket. host -- The name of the target server. Defaults to the empty string. port -- The port to use for the connection. Defaults to 0. """ # To comply with PEP8, method names now use underscores. # Deprecated method names are re-mapped for backwards compatibility. self.startTLS = self.start_tls self.registerStanza = self.register_stanza self.removeStanza = self.remove_stanza self.registerHandler = self.register_handler self.removeHandler = self.remove_handler self.setSocket = self.set_socket self.sendRaw = self.send_raw self.getId = self.get_id self.getNewId = self.new_id self.sendXML = self.send_xml self.ssl_support = SSL_SUPPORT self.ssl_version = ssl.PROTOCOL_TLSv1 self.state = StateMachine(('disconnected', 'connected')) self.state._set_state('disconnected') self.address = (host, int(port)) self.filesocket = None self.set_socket(socket) if sys.version_info < (3, 0): self.socket_class = Socket26 else: self.socket_class = Socket.socket self.use_ssl = False self.use_tls = False self.default_ns = '' self.stream_header = "<stream>" self.stream_footer = "</stream>" self.stop = threading.Event() self.stream_end_event = threading.Event() self.stream_end_event.set() self.event_queue = queue.Queue() self.send_queue = queue.Queue() self.scheduler = Scheduler(self.event_queue, self.stop) self.namespace_map = {} self.__thread = {} self.__root_stanza = [] self.__handlers = [] self.__event_handlers = {} self.__event_handlers_lock = threading.Lock() self._id = 0 self._id_lock = threading.Lock() self.auto_reconnect = True self.is_client = False try: if hasattr(signal, 'SIGHUP'): signal.signal(signal.SIGHUP, self._handle_kill) if hasattr(signal, 'SIGTERM'): # Used in Windows signal.signal(signal.SIGTERM, self._handle_kill) except: log.debug("Can not set interrupt signal handlers. " + \ "SleekXMPP is not running from a main thread.")
def __init__(self, socket=None, host='', port=0): """ Establish a new XML stream. Arguments: socket -- Use an existing socket for the stream. Defaults to None to generate a new socket. host -- The name of the target server. Defaults to the empty string. port -- The port to use for the connection. Defaults to 0. """ self.ssl_support = SSL_SUPPORT self.ssl_version = ssl.PROTOCOL_TLSv1 self.ca_certs = None self.response_timeout = RESPONSE_TIMEOUT self.reconnect_delay = None self.reconnect_max_delay = RECONNECT_MAX_DELAY self.state = StateMachine(('disconnected', 'connected')) self.state._set_state('disconnected') self.address = (host, int(port)) self.filesocket = None self.set_socket(socket) if sys.version_info < (3, 0): self.socket_class = Socket26 else: self.socket_class = Socket.socket self.use_ssl = False self.use_tls = False self.default_ns = '' self.stream_header = "<stream>" self.stream_footer = "</stream>" self.stop = threading.Event() self.stream_end_event = threading.Event() self.stream_end_event.set() self.session_started_event = threading.Event() self.event_queue = queue.Queue() self.send_queue = queue.Queue() self.__failed_send_stanza = None self.scheduler = Scheduler(self.event_queue, self.stop) self.namespace_map = {StanzaBase.xml_ns: 'xml'} self.__thread = {} self.__root_stanza = [] self.__handlers = [] self.__event_handlers = {} self.__event_handlers_lock = threading.Lock() self._id = 0 self._id_lock = threading.Lock() self.auto_reconnect = True self.is_client = False