From 16c4e7dd2a71a660214a77efa5426b3de75905fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarjei=20Hus=C3=B8y?= Date: Sat, 21 Apr 2018 12:28:39 -0700 Subject: [PATCH] Make startup assertions work in py2 --- postgres_mitm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/postgres_mitm.py b/postgres_mitm.py index bc067b8..a2845bc 100755 --- a/postgres_mitm.py +++ b/postgres_mitm.py @@ -29,6 +29,7 @@ import select import socket import ssl import struct +import sys import tempfile import textwrap import threading @@ -40,6 +41,7 @@ from collections import namedtuple VERSION_SSL = b'\x04\xd2\x16\x2f' VERSION_3 = b'\x00\x03\x00\x00' SSL_STARTUP_RESPONSE = b'S' +PY2 = sys.version_info < (3, 0, 0) _logger = logging.getLogger(__name__) @@ -413,7 +415,10 @@ def parse_options_from_startup_packet(data): raw_key_value_pairs = data[8:] assert raw_key_value_pairs[-1] == 0 raw_key_value_pairs = raw_key_value_pairs[0:-1] - assert raw_key_value_pairs.count(0) % 2 == 0 + if PY2: + assert raw_key_value_pairs.count('\0') % 2 == 0 + else: + assert raw_key_value_pairs.count(0) % 2 == 0 options = {} key_value_pairs = data[8:].split(b'\x00')