Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing logs related to connection establishment #58

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions nzpy/handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def startup(self, database, securityLevel, user, password, pgOptions):
self.log.info("Handshake negotiation unsuccessful")
return False

self.log.info("Sending handshake information to server")
self.log.debug("Sending handshake information to server")
if not self.conn_send_handshake_info(self._sock.write, self._sock.read, self._sock.flush, database, securityLevel, self._hsVersion, self._protocol1, self._protocol2, user, pgOptions):
self.log.warning("Error in conn_send_handshake_info")
return False
Expand Down Expand Up @@ -171,10 +171,11 @@ def conn_send_handshake_info(self, _write, _read, _flush, _database, securityLev
return True

def conn_send_database(self, _write,_read, _flush,_database):
db = None
if _database is not None:
if isinstance(_database, str):
db = _database.encode('utf8')
self.log.info("Database name: %s", db)
self.log.info("Database name: %s", str(db,'utf8'))

val = bytearray( core.h_pack(HSV2_DB))
val.extend(db + core.NULL_BYTE)
Expand All @@ -183,7 +184,7 @@ def conn_send_database(self, _write,_read, _flush,_database):
_flush()

beresp = _read(1)
self.log.debug("Backend response: %s", beresp)
self.log.info("Backend response: %s", str(beresp,'utf8'))
if beresp == b'N':
return True
elif beresp == core.ERROR_RESPONSE:
Expand Down Expand Up @@ -281,7 +282,7 @@ def conn_secure_session(self, securityLevel):

if beresp == b'N':
if information == HSV2_SSL_NEGOTIATE:
self.log.info("Attempting unsecured session")
self.log.debug("Attempting unsecured session")
information = 0
return True

Expand All @@ -308,7 +309,7 @@ def conn_send_handshake_version2(self, _write, _read, _flush, _protocol1, _proto
_write(val)
_flush()
beresp = _read(1)
self.log.debug("Backend response: %s",beresp)
self.log.info("Backend response: %s", str(beresp, 'utf8'))
if beresp == b'N':
if information == HSV2_PROTOCOL:
val = bytearray( core.h_pack(information) + core.h_pack(_protocol1) + core.h_pack(_protocol2))
Expand Down Expand Up @@ -366,7 +367,7 @@ def conn_send_handshake_version4(self, _write, _read, _flush, _protocol1, _proto
_write(val)
_flush()
beresp = _read(1)
self.log.debug("Backend response: %s",beresp)
self.log.info("Backend response: %s", str(beresp,'utf8'))
if beresp == b'N':
if information == HSV2_APPNAME: # App name
val = bytearray( core.h_pack(information))
Expand Down Expand Up @@ -509,15 +510,15 @@ def conn_authenticate(self, _write, _read, _flush, password):
def conn_connection_complete(self, _read):
while (1):
response = _read(1)
self.log.debug("backend response: %s", response)
self.log.info("backend response: %s", str(response,'utf8'))

if response != core.AUTHENTICATION_REQUEST:
_read(4) # do not use just ignore
length = core.i_unpack(_read(4))[0]

if response == core.AUTHENTICATION_REQUEST:
areq = core.i_unpack(_read(4))[0]
self.log.debug("backend response: %s", areq)
self.log.info("backend response: %s", areq)

if response == core.NOTICE_RESPONSE:
notices = str(_read(length),'utf8')
Expand Down