def establish_connection(self): self.conn_ready = False s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.host, self.port)) self.socketf = s.makefile(bufsize=0) self.sockfd = s self.open_socket = True supported = self.wait_for_request(OptionsMessage()) self.supported_cql_versions = supported.cqlversions self.remote_supported_compressions = supported.options['COMPRESSION'] if self.cql_version: if self.cql_version not in self.supported_cql_versions: raise ProgrammingError("cql_version %r is not supported by" " remote (w/ native protocol). Supported" " versions: %r" % (self.cql_version, self.supported_cql_versions)) else: self.cql_version = self.supported_cql_versions[0] opts = {} compresstype = None if self.compression: overlap = set(locally_supported_compressions) \ & set(self.remote_supported_compressions) if len(overlap) == 0: warn("No available compression types supported on both ends." " locally supported: %r. remotely supported: %r" % (locally_supported_compressions, self.remote_supported_compressions)) else: compresstype = iter(overlap).next() # choose any opts['COMPRESSION'] = compresstype compr, decompr = locally_supported_compressions[compresstype] # set the decompressor here, but set the compressor only after # a successful Ready message self.decompressor = decompr sm = StartupMessage(cqlversion=self.cql_version, options=opts) startup_response = self.wait_for_request(sm) while True: if isinstance(startup_response, ReadyMessage): self.conn_ready = True if compresstype: self.compressor = compr break if isinstance(startup_response, AuthenticateMessage): self.authenticator = startup_response.authenticator if self.credentials is None: raise ProgrammingError('Remote end requires authentication.') cm = CredentialsMessage(creds=self.credentials) startup_response = self.wait_for_request(cm) elif isinstance(startup_response, ErrorMessage): raise ProgrammingError("Server did not accept credentials. %s" % startup_response.summarymsg()) else: raise cql.InternalError("Unexpected response %r during connection setup" % startup_response)
def establish_connection(self): self.conn_ready = False s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.host, self.port)) self.socketf = s.makefile(bufsize=0) self.sockfd = s self.open_socket = True supported = self.wait_for_request(OptionsMessage()) self.supported_cql_versions = supported.cqlversions self.supported_compressions = supported.options['COMPRESSION'] if self.cql_version: if self.cql_version not in self.supported_cql_versions: raise ProgrammingError( "cql_version %r is not supported by" " remote (w/ native protocol). Supported" " versions: %r" % (self.cql_version, self.supported_cql_versions)) else: self.cql_version = self.supported_cql_versions[0] opts = {} if self.compression: if self.compression not in self.supported_compressions: raise ProgrammingError( "Compression type %r is not supported by" " remote. Supported compression types: %r" % (self.compression, self.supported_compressions)) # XXX: Remove this once some compressions are supported raise NotImplementedError( "CQL driver does not yet support compression") opts['COMPRESSION'] = self.compression sm = StartupMessage(cqlversion=self.cql_version, options=opts) startup_response = self.wait_for_request(sm) while True: if isinstance(startup_response, ReadyMessage): self.conn_ready = True break if isinstance(startup_response, AuthenticateMessage): self.authenticator = startup_response.authenticator if self.credentials is None: raise ProgrammingError( 'Remote end requires authentication.') cm = CredentialsMessage(creds=self.credentials) startup_response = self.wait_for_request(cm) elif isinstance(startup_response, ErrorMessage): raise ProgrammingError( "Server did not accept credentials. %s" % startup_response.summarymsg()) else: raise cql.InternalError( "Unexpected response %r during connection setup" % startup_response)
def cursor(self): if not self.open_socket: raise ProgrammingError("Connection has been closed.") curs = self.cursorclass(self) curs.compression = self.compression curs.consistency_level = self.consistency_level return curs
def __init__(self, querytext, itemid, vartypes, paramnames): self.querytext = querytext self.itemid = itemid self.vartypes = map(lookup_casstype, vartypes) self.paramnames = paramnames if len(self.vartypes) != len(self.paramnames): raise ProgrammingError("Length of variable types list is not the same" " length as the list of parameter names")
def value_decode_error(self, err, namebytes, valuebytes, expectedtype): raise ProgrammingError("value %r (in col %r) can't be deserialized as %s: %s" % (valuebytes, namebytes, expectedtype, err))
def name_decode_error(self, err, namebytes, expectedtype): raise ProgrammingError("column name %r can't be deserialized as %s: %s" % (namebytes, expectedtype, err))