コード例 #1
0
 def connect(self, addr):
     assert self._stream is None, "must not be disconneted before connecting"
     self._stream = BufferedStream(Socket.connect(addr, Timeout.current()))
     self._command_queue = Deque()
     self._response_queue = Deque()
     self._command_writer_task = Tasklet.new(self._command_writer)()
     self._response_reader_task = Tasklet.new(self._response_reader)()
コード例 #2
0
ファイル: client.py プロジェクト: bradjasper/concurrence
 def connect(self, addr):
     assert self._stream is None, "must not be disconneted before connecting"
     self._stream = BufferedStream(Socket.connect(addr, Timeout.current()))
     self._command_queue = Deque()
     self._response_queue = Deque()
     self._command_writer_task = Tasklet.new(self._command_writer)()
     self._response_reader_task = Tasklet.new(self._response_reader)()
コード例 #3
0
ファイル: __init__.py プロジェクト: winner0911/concurrence
 def connect(cls, endpoint):
     if isinstance(endpoint, Connector):
         assert False, "TODO"
     else:
         #default is to connect to Socket and endpoint is address
         from concurrence.io.socket import Socket
         from concurrence.timer import Timeout
         return Socket.connect(endpoint, Timeout.current())
コード例 #4
0
ファイル: __init__.py プロジェクト: bradjasper/concurrence
 def connect(cls, endpoint):
     if isinstance(endpoint, Connector):
         assert False, "TODO"
     else:
         #default is to connect to Socket and endpoint is address
         from concurrence.io.socket import Socket
         from concurrence.timer import Timeout
         return Socket.connect(endpoint, Timeout.current())
コード例 #5
0
ファイル: client.py プロジェクト: panjiang/concurrence
 def connect(self, timeout=HTTPS_CONNECTION_TIMEOUT):
     "Connect to a host on a given (SSL) port."
     sock = Socket.connect((self.host, self.port), timeout=timeout)
     sock.socket.setblocking(1)
     _sock = _socketobject(_sock=sock.socket)
     
     if self._tunnel_host:
         self.sock = sock
         self._tunnel()
     self.sock = ssl.wrap_socket(_sock, self.key_file, self.cert_file)
     self.sock.setblocking(0)
コード例 #6
0
    def connect(self,
                host="localhost",
                port=3306,
                user="",
                passwd="",
                db="",
                autocommit=None,
                charset=None):
        """connects to the given host and port with user and passwd"""
        #self.log.debug("connect mysql client %s %s %s %s %s", id(self), host, port, user, passwd)
        try:
            #print 'connect', host, user, passwd, db
            #parse addresses of form str <host:port>
            if type(host) == str:
                if host[0] == '/':  #assume unix domain socket
                    addr = host
                elif ':' in host:
                    host, port = host.split(':')
                    port = int(port)
                    addr = (host, port)
                else:
                    addr = (host, port)

            assert self.state == self.STATE_INIT, "make sure connection is not already connected or closed"

            self.state = self.STATE_CONNECTING
            self.socket = Socket.connect(addr, timeout=Timeout.current())
            self.reader = BufferedPacketReader(self.socket, self.buffer)
            self.writer = BufferedPacketWriter(self.socket, self.buffer)
            self._handshake(user, passwd, db)
            #handshake complete client can now send commands
            self.state = self.STATE_CONNECTED

            if autocommit == False:
                self.set_autocommit(False)
            elif autocommit == True:
                self.set_autocommit(True)
            else:
                pass  #whatever is the default of the db (ON in the case of mysql)

            if charset is not None:
                self.set_charset(charset)

            return self
        except TimeoutError:
            self.state = self.STATE_INIT
            raise
        except ClientLoginError:
            self.state = self.STATE_INIT
            raise
        except:
            self.state = self.STATE_ERROR
            raise
コード例 #7
0
ファイル: client.py プロジェクト: fullc0de/concurrence
    def connect(self, host = "localhost", port = 3306, user = "", passwd = "", db = "", autocommit = None, charset = None):
        """connects to the given host and port with user and passwd"""
        #self.log.debug("connect mysql client %s %s %s %s %s", id(self), host, port, user, passwd)
        try:
            #print 'connect', host, user, passwd, db
            #parse addresses of form str <host:port>
            if type(host) == str:
                if host[0] == '/': #assume unix domain socket
                    addr = host
                elif ':' in host:
                    host, port = host.split(':')
                    port = int(port)
                    addr = (host, port)
                else:
                    addr = (host, port)

            assert self.state == self.STATE_INIT, "make sure connection is not already connected or closed"

            self.state = self.STATE_CONNECTING
            self.socket = Socket.connect(addr, TIMEOUT_CURRENT)
            self.reader = BufferedPacketReader(self.socket, self.buffer)
            self.writer = BufferedPacketWriter(self.socket, self.buffer)
            self._handshake(user, passwd, db)
            #handshake complete client can now send commands
            self.state = self.STATE_CONNECTED

            if autocommit == False:
                self.set_autocommit(False)
            elif autocommit == True:
                self.set_autocommit(True)
            else:
                pass #whatever is the default of the db (ON in the case of mysql)

            if charset is not None:
                self.set_charset(charset)

            return self
        except TimeoutError:
            self.state = self.STATE_INIT
            raise
        except ClientLoginError:
            self.state = self.STATE_INIT
            raise
        except:
            self.state = self.STATE_ERROR
            raise