reversed order of EnumType mapping argument
authorForrest Voight <forrest@forre.st>
Thu, 3 May 2012 22:11:28 +0000 (18:11 -0400)
committerForrest Voight <forrest@forre.st>
Thu, 3 May 2012 22:24:54 +0000 (18:24 -0400)
p2pool/bitcoin/p2p.py
p2pool/p2p.py
p2pool/util/pack.py

index 87fdb28..3ec241c 100644 (file)
@@ -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)),
         ]))),
     ])
index 3681b2f..75c8773 100644 (file)
@@ -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):
index 5a4f6ba..6b6c3e5 100644 (file)
@@ -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()