Skip to content

Commit 5e76dc5

Browse files
committed
Clarify client protocol version handling.
1 parent f4c883c commit 5e76dc5

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
include=pynuodb/*
33

44
[report]
5-
omit=tests/*
5+
omit=tests/*

pynuodb/connection.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ def connect(database, host, user, password, options=None):
4242
return Connection(database, host, user, password, options)
4343

4444
class Connection(object):
45-
45+
4646
"""Class for establishing a connection with host.
47-
47+
4848
Public Functions:
4949
testConnection -- Tests to ensure the connection was properly established.
5050
close -- Closes the connection with the host.
5151
commit -- Sends a message to the host to commit transaction.
5252
rollback -- Sends a message to the host to rollback uncommitted changes.
5353
cursor -- Return a new Cursor object using the connection.
54-
54+
5555
Private Functions:
5656
__init__ -- Constructor for the Connection class.
5757
_check_closed -- Checks if the connection to the host is closed.
58-
58+
5959
Special Function:
6060
auto_commit (getter) -- Gets the value of auto_commit from the database.
6161
auto_commit (setter) -- Sets the value of auto_commit on the database.
@@ -64,10 +64,10 @@ class Connection(object):
6464
from .exception import Warning, Error, InterfaceError, DatabaseError, \
6565
OperationalError, IntegrityError, InternalError, \
6666
ProgrammingError, NotSupportedError
67-
67+
6868
def __init__(self, dbName, broker, username, password, options):
6969
"""Constructor for the Connection class.
70-
70+
7171
Arguments:
7272
dbName -- Name of database you are accessing.
7373
broker -- Address of the broker you are connecting too.
@@ -76,7 +76,7 @@ def __init__(self, dbName, broker, username, password, options):
7676
options -- A dictionary of NuoDB connection options
7777
Some common options include:
7878
"schema"
79-
79+
8080
Returns:
8181
a Connection instance
8282
@@ -91,7 +91,7 @@ def __init__(self, dbName, broker, username, password, options):
9191
self._trans_id = None
9292

9393
cp = ClientPassword()
94-
94+
9595
parameters = {'user' : username, 'timezone' : time.strftime('%Z')}
9696
if options:
9797
parameters.update(options)
@@ -101,7 +101,8 @@ def __init__(self, dbName, broker, username, password, options):
101101
parameters['clientProcessId'] = str(getpid())
102102

103103
version, serverKey, salt = self.__session.open_database(dbName, parameters, cp)
104-
104+
self.__protocolVersion = version
105+
105106
sessionKey = cp.computeSessionKey(username.upper(), password, salt, serverKey)
106107
self.__session.setCiphers(RC4Cipher(sessionKey), RC4Cipher(sessionKey))
107108

@@ -112,12 +113,12 @@ def __init__(self, dbName, broker, username, password, options):
112113

113114
def testConnection(self):
114115
"""Tests to ensure the connection was properly established.
115-
116+
116117
This function will test the connection and if it was created should print out:
117118
count: 1
118119
name: ONE
119120
value: 1
120-
121+
121122
:rtype: None
122123
"""
123124
self.__session.test_connection()
@@ -127,7 +128,7 @@ def auto_commit(self):
127128
"""Gets the value of auto_commit from the database."""
128129
self._check_closed()
129130
return self.__session.get_autocommit()
130-
131+
131132
@auto_commit.setter
132133
def auto_commit(self, value):
133134
"""Sets the value of auto_commit on the database."""

pynuodb/encodedsession.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def __init__(self, host, port, service='SQL2'):
114114
:type : uuid.UUID
115115
"""
116116

117-
self.__serverVersion = 0
117+
self.__sessionVersion = 0
118118
"""
119-
Server's current version
119+
Client protocol version for the session
120120
:type : int
121121
"""
122122

@@ -128,7 +128,7 @@ def __init__(self, host, port, service='SQL2'):
128128

129129
self.__effectivePlatformVersion = 0
130130
"""
131-
Agreed upon version by the server (for multiple nodes)
131+
Database protocol version when the session is created (may change!)
132132
:type : int
133133
"""
134134

@@ -175,7 +175,7 @@ def open_database(self, db_name, parameters, cp):
175175
self.__connectedNodeID = self.getInt()
176176
self.__maxNodes = self.getInt()
177177

178-
self.__serverVersion = protocolVersion
178+
self.__sessionVersion = protocolVersion
179179

180180
return protocolVersion, serverKey, salt
181181

@@ -188,6 +188,12 @@ def check_auth(self):
188188
except SessionException as e:
189189
raise ProgrammingError('Failed to authenticate: ' + str(e))
190190

191+
def get_version(self):
192+
"""
193+
:rtype sessionVersion: int
194+
"""
195+
return self.__sessionVersion
196+
191197
def get_auth_types(self):
192198
self._putMessageId(protocol.AUTHORIZETYPESREQUEST)
193199
self._exchangeMessages()
@@ -1025,7 +1031,6 @@ def getValue(self):
10251031
def _exchangeMessages(self, getResponse=True):
10261032
"""Exchange the pending message for an optional response from the server."""
10271033
try:
1028-
#print("message to server: %s" % (self.__output))
10291034
self.send(self.__output)
10301035
finally:
10311036
self.__output = None
@@ -1058,7 +1063,7 @@ def _setup_statement(self, handle, msgId):
10581063
:type msgId: int
10591064
"""
10601065
self._putMessageId(msgId)
1061-
if(self.__serverVersion >= protocol.PROTOCOL_VERSION17):
1066+
if self.__sessionVersion >= protocol.PROTOCOL_VERSION17:
10621067
self.putInt(self.getCommitInfo(self.__connectedNodeID))
10631068
self.putInt(handle)
10641069

pynuodb/session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(self, host, port=None, service="Identity"):
9191

9292
self.__service = service
9393

94-
self.__version = sys.version[0]
94+
self.__pyversion = sys.version[0]
9595

9696
@property
9797
def address(self):
@@ -196,7 +196,7 @@ def send(self, message):
196196

197197
try:
198198
messageBuilder = None
199-
if self.__version == '3':
199+
if self.__pyversion == '3':
200200
messageBuilder = lenStr + bytes(message, 'latin-1')
201201

202202
else:
@@ -228,7 +228,7 @@ def recv(self, doStrip=True):
228228
else:
229229
msg = self.__cipherIn.transform(msg)
230230

231-
if type(msg) is bytes and self.__version == '3':
231+
if type(msg) is bytes and self.__pyversion == '3':
232232
msg = msg.decode("latin-1")
233233
return msg
234234

@@ -244,7 +244,7 @@ def __readFully(self, msgLength):
244244
if not received:
245245
raise SessionException("Session was closed while receiving msgLength=[%d] len(msg)=[%d] "
246246
"len(received)=[%d]" % (msgLength, len(msg), len(received)))
247-
if self.__version == '3':
247+
if self.__pyversion == '3':
248248
msg = b''.join([msg, received])
249249
msgLength = msgLength - len(received.decode('latin-1'))
250250
else:

0 commit comments

Comments
 (0)