diff --git a/stomp/test/utils_test.py b/stomp/test/utils_test.py index ead1bf5d..7746d89c 100644 --- a/stomp/test/utils_test.py +++ b/stomp/test/utils_test.py @@ -19,4 +19,26 @@ def test_convert_frame_to_lines(self): if sys.hexversion >= 0x03000000: self.assertEquals(bytearray('SEND\nheader1:value1\n\nthis is the body\x00', 'ascii'), s) else: - self.assertEquals('SEND\nheader1:value1\n\nthis is the body\x00', s) \ No newline at end of file + self.assertEquals('SEND\nheader1:value1\n\nthis is the body\x00', s) + + def test_parse_headers(self): + lines = [ + r'h1:foo\c\\bar ', + r'h1:2nd h1 ignored -- not a must, but allowed and that is how we behave ATM', + r'h\c2:baz\r\nquux', + ] + self.assertEquals( + {'h1': r'foo:\bar ', 'h:2': 'baz\r\nquux'}, parse_headers(lines)) + + def test_calculate_heartbeats(self): + chb = (3000, 5000) + shb = map(str, reversed(chb)) + self.assertEquals((3000, 5000), calculate_heartbeats(shb, chb)) + shb = ('6000', '2000') + self.assertEquals((3000, 6000), calculate_heartbeats(shb, chb)) + shb = ('0', '0') + self.assertEquals((0, 0), calculate_heartbeats(shb, chb)) + shb = ('10000', '0') + self.assertEquals((0, 10000), calculate_heartbeats(shb, chb)) + chb = (0, 0) + self.assertEquals((0, 0), calculate_heartbeats(shb, chb)) diff --git a/stomp/utils.py b/stomp/utils.py index 7541bddb..75e12291 100755 --- a/stomp/utils.py +++ b/stomp/utils.py @@ -85,6 +85,7 @@ def parse_headers(lines, offset=0): header_match = HEADER_LINE_RE.match(header_line) if header_match: key = header_match.group('key') + key = key.replace('\\n', '\n').replace('\\r', '\r').replace('\\\\', '\\').replace('\\c', ':') if key not in headers: value = header_match.group('value') value = value.replace('\\n', '\n').replace('\\r', '\r').replace('\\\\', '\\').replace('\\c', ':') @@ -156,9 +157,9 @@ def calculate_heartbeats(shb, chb): x = 0 y = 0 if cx != 0 and sy != '0': - x = max(cx, int(sx)) + x = max(cx, int(sy)) if cy != 0 and sx != '0': - y = max(cy, int(sy)) + y = max(cy, int(sx)) return (x, y)