From a1f9399b069a3561047000d7f7d8b7b274d722bf Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Thu, 3 May 2012 18:11:28 -0400 Subject: [PATCH] reversed order of EnumType mapping argument --- p2pool/bitcoin/p2p.py | 4 ++-- p2pool/p2p.py | 2 +- p2pool/util/pack.py | 27 +++++++++++++-------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/p2pool/bitcoin/p2p.py b/p2pool/bitcoin/p2p.py index 87fdb28..3ec241c 100644 --- a/p2pool/bitcoin/p2p.py +++ b/p2pool/bitcoin/p2p.py @@ -65,7 +65,7 @@ class Protocol(p2protocol.Protocol): message_inv = pack.ComposedType([ ('invs', pack.ListType(pack.ComposedType([ - ('type', pack.EnumType(pack.IntType(32), {'tx': 1, 'block': 2})), + ('type', pack.EnumType(pack.IntType(32), {1: 'tx', 2: 'block'})), ('hash', pack.IntType(256)), ]))), ]) @@ -80,7 +80,7 @@ class Protocol(p2protocol.Protocol): message_getdata = pack.ComposedType([ ('requests', pack.ListType(pack.ComposedType([ - ('type', pack.EnumType(pack.IntType(32), {'tx': 1, 'block': 2})), + ('type', pack.EnumType(pack.IntType(32), {1: 'tx', 2: 'block'})), ('hash', pack.IntType(256)), ]))), ]) diff --git a/p2pool/p2p.py b/p2pool/p2p.py index 3681b2f..75c8773 100644 --- a/p2pool/p2p.py +++ b/p2pool/p2p.py @@ -230,7 +230,7 @@ class Protocol(p2protocol.Protocol): message_sharereply = pack.ComposedType([ ('id', pack.IntType(256)), - ('result', pack.EnumType(pack.VarIntType(), {'good': 0, 'too long': 1, 'unk2': 2, 'unk3': 3, 'unk4': 4, 'unk5': 5, 'unk6': 6})), + ('result', pack.EnumType(pack.VarIntType(), {0: 'good', 1: 'too long', 2: 'unk2', 3: 'unk3', 4: 'unk4', 5: 'unk5', 6: 'unk6'})), ('shares', pack.ListType(p2pool_data.share_type)), ]) def handle_sharereply(self, id, result, shares): diff --git a/p2pool/util/pack.py b/p2pool/util/pack.py index 5a4f6ba..6b6c3e5 100644 --- a/p2pool/util/pack.py +++ b/p2pool/util/pack.py @@ -119,27 +119,26 @@ class VarStrType(Type): return self._inner_size.write(file, len(item)), item class EnumType(Type): - def __init__(self, inner, values): + def __init__(self, inner, pack_to_unpack): self.inner = inner - self.values = values + self.pack_to_unpack = pack_to_unpack - keys = {} - for k, v in values.iteritems(): - if v in keys: - raise ValueError('duplicate value in values') - keys[v] = k - self.keys = keys + self.unpack_to_pack = {} + for k, v in pack_to_unpack.iteritems(): + if v in self.unpack_to_pack: + raise ValueError('duplicate value in pack_to_unpack') + self.unpack_to_pack[v] = k def read(self, file): data, file = self.inner.read(file) - if data not in self.keys: - raise ValueError('enum data (%r) not in values (%r)' % (data, self.values)) - return self.keys[data], file + if data not in self.pack_to_unpack: + raise ValueError('enum data (%r) not in pack_to_unpack (%r)' % (data, self.pack_to_unpack)) + return self.pack_to_unpack[data], file def write(self, file, item): - if item not in self.values: - raise ValueError('enum item (%r) not in values (%r)' % (item, self.values)) - return self.inner.write(file, self.values[item]) + if item not in self.unpack_to_pack: + raise ValueError('enum item (%r) not in unpack_to_pack (%r)' % (item, self.unpack_to_pack)) + return self.inner.write(file, self.unpack_to_pack[item]) class ListType(Type): _inner_size = VarIntType() -- 1.7.1