Skip to content

Commit

Permalink
Fix bytes vs str formatting for py33 and py34.
Browse files Browse the repository at this point in the history
  • Loading branch information
da4089 committed Nov 12, 2017
1 parent b8a5507 commit f9f41d3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions simplefix/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,21 +512,21 @@ def encode(self, raw=False):
if raw:
# Walk pairs, creating string.
for tag, value in self.pairs:
buf += b"%s=%s%s" % (tag, value, SOH_STR)
buf += tag + b'=' + value + SOH_STR

return buf

# Cooked.
for tag, value in self.pairs:
if int(tag) in (8, 9, 35, 10):
continue
buf += b"%s=%s%s" % (tag, value, SOH_STR)
buf += tag + b'=' + value + SOH_STR

# Prepend the message type.
if self.message_type is None:
raise ValueError("No message type set")

buf = b"35=%s" % self.message_type + SOH_STR + buf
buf = b"35=" + self.message_type + SOH_STR + buf

# Calculate body length.
#
Expand All @@ -538,15 +538,15 @@ def encode(self, raw=False):
if not self.begin_string:
raise ValueError("No begin string set")

buf = b"8=%s" % self.begin_string + SOH_STR + \
b"9=%u" % body_length + SOH_STR + \
buf
buf = b"8=" + self.begin_string + SOH_STR + \
b"9=" + fix_val("%u" % body_length) + SOH_STR + \
buf

# Calculate and append the checksum.
checksum = 0
for c in buf:
checksum += ord(c) if sys.version_info.major == 2 else c
buf += b"10=%03u" % (checksum % 256,) + SOH_STR
buf += b"10=" + fix_val("%03u" % (checksum % 256,)) + SOH_STR

return buf

Expand Down

0 comments on commit f9f41d3

Please sign in to comment.