style cleanup
[p2pool.git] / p2pool / bitcoin / p2p.py
index dab765a..aaf46d6 100644 (file)
@@ -8,10 +8,10 @@ import hashlib
 import random
 import struct
 import time
-import traceback
 import zlib
 
 from twisted.internet import defer, protocol, reactor
+from twisted.python import log
 
 from . import data as bitcoin_data
 from p2pool.util import variable, datachunker, deferral
@@ -49,7 +49,7 @@ class BaseProtocol(protocol.Protocol):
                     print 'INVALID HASH'
                     continue
             
-            type_ = getattr(self, "message_" + command, None)
+            type_ = getattr(self, 'message_' + command, None)
             if type_ is None:
                 print 'RECV', command, checksum.encode('hex') if checksum is not None else None, repr(payload.encode('hex')), len(payload)
                 print 'NO TYPE FOR', repr(command)
@@ -59,7 +59,7 @@ class BaseProtocol(protocol.Protocol):
                 payload2 = type_.unpack(payload)
             except:
                 print 'RECV', command, checksum.encode('hex') if checksum is not None else None, repr(payload.encode('hex')), len(payload)
-                traceback.print_exc()
+                log.err()
                 continue
             
             handler = getattr(self, 'handle_' + command, None)
@@ -74,13 +74,13 @@ class BaseProtocol(protocol.Protocol):
                 handler(**payload2)
             except:
                 print 'RECV', command, checksum.encode('hex') if checksum is not None else None, repr(payload.encode('hex')), len(payload)
-                traceback.print_exc()
+                log.err()
                 continue
     
     def sendPacket(self, command, payload2):
         if len(command) >= 12:
             raise ValueError('command too long')
-        type_ = getattr(self, "message_" + command, None)
+        type_ = getattr(self, 'message_' + command, None)
         if type_ is None:
             raise ValueError('invalid command')
         #print 'SEND', command, repr(payload2)[:500]
@@ -184,7 +184,7 @@ class Protocol(BaseProtocol):
             elif inv['type'] == 'block':
                 self.factory.new_block.happened(inv['hash'])
             else:
-                print "Unknown inv type", item
+                print 'Unknown inv type', item
     
     message_getdata = bitcoin_data.ComposedType([
         ('requests', bitcoin_data.ListType(bitcoin_data.ComposedType([
@@ -248,7 +248,7 @@ class Protocol(BaseProtocol):
     message_reply = bitcoin_data.ComposedType([
         ('hash', bitcoin_data.HashType()),
         ('reply',  bitcoin_data.EnumType(bitcoin_data.StructType('<I'), {'success': 0, 'failure': 1, 'denied': 2})),
-        ('script', bitcoin_data.PossiblyNone("", bitcoin_data.VarStrType())),
+        ('script', bitcoin_data.PossiblyNone('', bitcoin_data.VarStrType())),
     ])
     def handle_reply(self, hash, reply, script):
         self.check_order.got_response(hash, dict(reply=reply, script=script))
@@ -263,7 +263,7 @@ class Protocol(BaseProtocol):
         ('signature', bitcoin_data.VarStrType()),
     ])
     def handle_alert(self, message, signature):
-        print "ALERT:", (message, signature)
+        print 'ALERT:', (message, signature)
     
     def connectionLost(self, reason):
         if hasattr(self.factory, 'gotConnection'):
@@ -372,7 +372,7 @@ class HeightTracker(object):
         print len(self.tracker.shares)
     
     def request(self, have, last):
-        #print "REQ", ('[' + ', '.join(map(hex, have)) + ']', hex(last) if last is not None else None)
+        #print 'REQ', ('[' + ', '.join(map(hex, have)) + ']', hex(last) if last is not None else None)
         if self.factory.conn.value is not None:
             self.factory.conn.value.send_getheaders(version=1, have=have, last=last)
     
@@ -408,6 +408,6 @@ if __name__ == '__main__':
             try:
                 print h.getHeight(0xa285c3cb2a90ac7194cca034512748289e2526d9d7ae6ee7523)
             except Exception, e:
-                traceback.print_exc()
+                log.err()
     
     reactor.run()