Skip to content

Commit

Permalink
Merge pull request #97 from jjappi/python3.4-support
Browse files Browse the repository at this point in the history
Fix for python 3.4: don't use % formatting for bytes.
  • Loading branch information
fiorix committed Jan 12, 2016
2 parents 5469ca1 + 85e344f commit 765806f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:

python:
- 2.7
- 3.4
- 3.5
env:
- TEST_HIREDIS=0
Expand Down
15 changes: 10 additions & 5 deletions txredisapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,16 @@ def _build_command(self, *args, **kwargs):
# Build the redis command.
cmds = bytearray()
cmd_count = 0
cmd_template = six.b("$%d\r\n%s\r\n")
for s in args:
cmd = self._encode_value(s)
cmds.extend(cmd_template % (len(cmd), cmd))
cmds.extend(six.b("$"))
for token in self._encode_value(len(cmd)), cmd:
cmds.extend(token)
cmds.extend(six.b("\r\n"))
cmd_count += 1

command = bytes(six.b("*%d\r\n") % (cmd_count,) + cmds)
command = bytes(six.b("").join(
[six.b("*"), self._encode_value(cmd_count), six.b("\r\n")]) + cmds)
if not isinstance(command, six.binary_type):
command = command.encode()
return command
Expand Down Expand Up @@ -1960,7 +1963,8 @@ def add_node(self, node):
uuid = node._factory.uuid
if isinstance(uuid, six.text_type):
uuid = uuid.encode()
crckey = zlib.crc32(six.b("%s:%d") % (uuid, x))
crckey = zlib.crc32(six.b(":").join(
[uuid, str(x).format().encode()]))
self.ring[crckey] = node
self.sorted_keys.append(crckey)

Expand All @@ -1969,7 +1973,8 @@ def add_node(self, node):
def remove_node(self, node):
self.nodes.remove(node)
for x in range(self.replicas):
crckey = zlib.crc32(six.b("%s:%d") % (node, x))
crckey = zlib.crc32(six.b(":").join(
[node, str(x).format().encode()]))
self.ring.remove(crckey)
self.sorted_keys.remove(crckey)

Expand Down

0 comments on commit 765806f

Please sign in to comment.