code style fixes
authorForrest Voight <forrest@forre.st>
Thu, 28 Jul 2011 17:26:46 +0000 (13:26 -0400)
committerForrest Voight <forrest@forre.st>
Thu, 28 Jul 2011 17:26:46 +0000 (13:26 -0400)
p2pool/bitcoin/data.py
p2pool/bitcoin/p2p.py
p2pool/bitcoin/script.py
p2pool/data.py
p2pool/main.py
p2pool/util/jsonrpc.py
p2pool/util/math.py
p2pool/worker_interface.py

index 667eb4c..8ee3761 100644 (file)
@@ -673,8 +673,8 @@ if __name__ == '__main__':
     
     #t.remove(99)
     
-    print "HEADS", t.heads
-    print "TAILS", t.tails
+    print 'HEADS', t.heads
+    print 'TAILS', t.tails
     
     import random
     
@@ -689,15 +689,15 @@ if __name__ == '__main__':
             t.add(FakeShare(i, x))
         while t.shares:
             x = random.choice(list(t.shares))
-            print "DEL", x, t.__dict__
+            print 'DEL', x, t.__dict__
             try:
                 t.remove(x)
             except NotImplementedError:
-                print "aborted; not implemented"
+                print 'aborted; not implemented'
         import time
         time.sleep(.1)
-        print "HEADS", t.heads
-        print "TAILS", t.tails
+        print 'HEADS', t.heads
+        print 'TAILS', t.tails
     
     #for share_hash, share in sorted(t.shares.iteritems()):
     #    print share_hash, share.previous_hash, t.heads.get(share_hash), t.tails.get(share_hash)
index 9ffb9c5..702c86b 100644 (file)
@@ -30,7 +30,7 @@ class BaseProtocol(protocol.Protocol):
             length, = struct.unpack('<I', (yield 4))
             
             if length > self.max_net_payload_length:
-                print "length too long"
+                print 'length too long'
                 continue
             
             if self.use_checksum:
@@ -45,7 +45,7 @@ class BaseProtocol(protocol.Protocol):
                     d = zlib.decompressobj()
                     payload = d.decompress(compressed_payload, self.max_payload_length)
                     if d.unconsumed_tail:
-                        print "compressed payload expanded too much"
+                        print 'compressed payload expanded too much'
                         continue
                     assert not len(payload) > self.max_payload_length
                 except:
@@ -53,7 +53,7 @@ class BaseProtocol(protocol.Protocol):
                     continue
             else:
                 if len(compressed_payload) > self.max_payload_length:
-                    print "compressed payload expanded too much"
+                    print 'compressed payload expanded too much'
                     continue
                 payload = compressed_payload
             
@@ -375,7 +375,7 @@ class HeightTracker(object):
         self.think()
         
         if len(self.tracker.shares) > self.last_notified_size + 10:
-            print "Have %i block headers" % len(self.tracker.shares)
+            print 'Have %i block headers' % len(self.tracker.shares)
             self.last_notified_size = len(self.tracker.shares)
     
     def heard_block(self, block_hash):
index ead6416..3a0b658 100644 (file)
@@ -15,7 +15,7 @@ def protoPUSHDATA(size_len):
 
 opcodes = {}
 for i in xrange(256):
-    opcodes[i] = "UNK_" + str(i), reads_nothing
+    opcodes[i] = 'UNK_' + str(i), reads_nothing
 
 opcodes[0] = '0', reads_nothing
 for i in xrange(1, 76):
index bb32016..13e9111 100644 (file)
@@ -349,7 +349,7 @@ class OkayTracker(bitcoin_data.Tracker):
                 if not self.attempt_verify(share, now):
                     break
                 if random.random() < .001:
-                    #print "YIELDING"
+                    #print 'YIELDING'
                     yield deferral.sleep(.01)
             if head_height < self.net.CHAIN_LENGTH and last_last_hash is not None:
                 desired.add((self.verified.shares[random.choice(list(self.verified.reverse_shares[last_hash]))].peer, last_last_hash))
@@ -382,7 +382,7 @@ class OkayTracker(bitcoin_data.Tracker):
             best_share = self.verified.shares[best]
             if ht.get_min_height(best_share.header['previous_block']) < ht.get_min_height(previous_block) and best_share.bitcoin_hash != previous_block and best_share.peer is not None:
                 if p2pool.DEBUG:
-                    print "Stale detected!"
+                    print 'Stale detected!'
                 best = best_share.previous_hash
         
         defer.returnValue((best, desired))
index fbaf6df..aa2da02 100644 (file)
@@ -165,7 +165,7 @@ def main(args):
         
         def p2p_shares(shares, peer=None):
             if len(shares) > 5:
-                print "Processing %i shares..." % (len(shares),)
+                print 'Processing %i shares...' % (len(shares),)
             
             some_new = False
             for share in shares:
@@ -197,7 +197,7 @@ def main(args):
                 tracker_updated.happened()
             
             if len(shares) > 5:
-                print "... done processing %i shares." % (len(shares),)
+                print '... done processing %i shares.' % (len(shares),)
         
         def p2p_share_hashes(share_hashes, peer):
             get_hashes = []
@@ -279,7 +279,7 @@ def main(args):
         
         def compute(state, all_targets):
             if state['best_share_hash'] is None:
-                raise jsonrpc.Error(-12345, u"p2pool is downloading shares")
+                raise jsonrpc.Error(-12345, u'p2pool is downloading shares')
             pre_extra_txs = [tx for tx in tx_pool.itervalues() if tx.is_good()]
             pre_extra_txs = pre_extra_txs[:2**16 - 1] # merkle_branch limit
             extra_txs = []
@@ -348,7 +348,7 @@ def main(args):
                     return False
                 share = p2pool.Share.from_block(block)
                 my_shares.add(share.hash)
-                print 'GOT SHARE! %x prev %x age %.2fs' % (share.hash % 2**32, 0 if share.previous_hash is None else share.previous_hash % 2**32, time.time() - times[share.nonce]) + (" DEAD ON ARRIVAL" if share.previous_hash != current_work.value['best_share_hash'] else "")
+                print 'GOT SHARE! %x prev %x age %.2fs' % (share.hash % 2**32, 0 if share.previous_hash is None else share.previous_hash % 2**32, time.time() - times[share.nonce]) + (' DEAD ON ARRIVAL' if share.previous_hash != current_work.value['best_share_hash'] else '')
                 good = share.previous_hash == current_work.value['best_share_hash']
                 # maybe revert back to tracker being non-blocking so 'good' can be more accurate?
                 p2p_shares([share])
@@ -415,9 +415,9 @@ def main(args):
         def new_tx(tx_hash):
             try:
                 assert isinstance(tx_hash, (int, long))
-                #print "REQUESTING", tx_hash
+                #print 'REQUESTING', tx_hash
                 tx = yield (yield factory.getProtocol()).get_tx(tx_hash)
-                #print "GOT", tx
+                #print 'GOT', tx
                 tx_pool[bitcoin.data.tx_type.hash256(tx)] = Tx(tx, current_work.value['previous_block'])
             except:
                 log.err(None, 'Error handling tx:')
@@ -536,13 +536,13 @@ def run():
         class TimestampingPipe(object):
             def __init__(self, inner_file):
                 self.inner_file = inner_file
-                self.buf = ""
+                self.buf = ''
                 self.softspace = 0
             def write(self, data):
                 buf = self.buf + data
                 lines = buf.split('\n')
                 for line in lines[:-1]:
-                    self.inner_file.write("%s %s\n" % (time.strftime("%H:%M:%S"), line))
+                    self.inner_file.write('%s %s\n' % (time.strftime('%H:%M:%S'), line))
                 self.buf = lines[-1]
             def flush(self):
                 self.inner_file.flush()
@@ -560,7 +560,7 @@ def run():
         try:
             args.pubkey_hash = bitcoin.data.address_to_pubkey_hash(args.address, args.net)
         except Exception, e:
-            raise ValueError("error parsing address: " + repr(e))
+            raise ValueError('error parsing address: ' + repr(e))
     else:
         args.pubkey_hash = None
     
index 0d5473c..45d5dcc 100644 (file)
@@ -117,7 +117,7 @@ class Server(deferred_resource.DeferredResource):
                 raise Error(-32601, u'Method not found')
             method_meth = getattr(self, method_name)
             
-            if hasattr(method_meth, "takes_request"):
+            if hasattr(method_meth, 'takes_request'):
                 params = [request] + list(params)
             
             try:
index 84e2baa..acf8a60 100644 (file)
@@ -56,17 +56,17 @@ def add_dicts(dicts):
     return dict((k, v) for k, v in res.iteritems() if v)
 
 def format(x):
-    prefixes = "kMGTPEZY"
+    prefixes = 'kMGTPEZY'
     count = 0
     while x >= 10000 and count < len(prefixes) - 2:
         x = x//1000
         count += 1
-    s = "" if count == 0 else prefixes[count - 1]
-    return "%i" % (x,) + s
+    s = '' if count == 0 else prefixes[count - 1]
+    return '%i' % (x,) + s
 
-if __name__ == "__main__":
+if __name__ == '__main__':
     import random
     a = 1
     while True:
-        print a, format(a) + "H/s"
+        print a, format(a) + 'H/s'
         a = a * random.randrange(2, 5)
index 887076f..4ca70d9 100644 (file)
@@ -18,7 +18,7 @@ def get_memory(user_agent):
     if 'cgminer' in user_agent2: return 1
     if 'poclbm' in user_agent2: return 1
     if 'phoenix' in user_agent2: return 2
-    print "Unknown miner User-Agent:", repr(user_agent)
+    print 'Unknown miner User-Agent:', repr(user_agent)
     return 0
 
 def get_id(request):
@@ -49,7 +49,7 @@ class LongPollingWorkerInterface(deferred_resource.DeferredResource):
             try:
                 id = random.randrange(10000)
                 if p2pool.DEBUG:
-                    print "LONG POLL", id
+                    print 'LONG POLL', id
                 
                 request_id = get_id(request)
                 memory = get_memory(request.getHeader('User-Agent'))
@@ -63,7 +63,7 @@ class LongPollingWorkerInterface(deferred_resource.DeferredResource):
                     if work != thought_work[-1]:
                         break
                     if p2pool.DEBUG:
-                        print "POLL %i WAITING" % (id,)
+                        print 'POLL %i WAITING' % (id,)
                     yield defer.DeferredList([self.work.changed.get_deferred(), last_cache_invalidation[request_id].changed.get_deferred()], fireOnOneCallback=True)
                 
                 if thought_work[-1] is not None and work != thought_work[-1] and any(x is None or work['previous_block'] == x['previous_block'] for x in thought_work[-memory or len(thought_work):]):
@@ -71,7 +71,7 @@ class LongPollingWorkerInterface(deferred_resource.DeferredResource):
                     newwork = work.copy()
                     newwork['previous_block'] = random.randrange(2**256)
                     if p2pool.DEBUG:
-                        print "longpoll faked", id
+                        print 'longpoll faked', id
                     res = self.compute(work, request.getHeader('X-All-Targets') is not None)
                     newres = self.compute(newwork, request.getHeader('X-All-Targets') is not None)
                 else:
@@ -104,7 +104,7 @@ class LongPollingWorkerInterface(deferred_resource.DeferredResource):
         
         
         if p2pool.DEBUG:
-            print "END POLL %i %x" % (id, work['best_share_hash'] % 2**32 if work['best_share_hash'] is not None else 0)
+            print 'END POLL %i %x' % (id, work['best_share_hash'] % 2**32 if work['best_share_hash'] is not None else 0)
     render_POST = render_GET
 
 class RateInterface(deferred_resource.DeferredResource):
@@ -150,7 +150,7 @@ class WorkerInterface(jsonrpc.Server):
             newwork = work.copy()
             newwork['previous_block'] = random.randrange(2**256)
             if p2pool.DEBUG:
-                print "getwork faked"
+                print 'getwork faked'
             res = self.compute(work, request.getHeader('X-All-Targets') is not None)
             newres = self.compute(newwork, request.getHeader('X-All-Targets') is not None)
         else:
@@ -159,7 +159,7 @@ class WorkerInterface(jsonrpc.Server):
         
         reactor.callLater(.01, lambda: last_cache_invalidation[request_id].set((thought_work[-1], newwork)))
         if p2pool.DEBUG:
-            print "END GETWORK %i" % (work['best_share_hash'] % 2**32 if work['best_share_hash'] is not None else 0,)
+            print 'END GETWORK %i' % (work['best_share_hash'] % 2**32 if work['best_share_hash'] is not None else 0,)
         
         return merge(newres.getwork(), res.getwork())
     rpc_getwork.takes_request = True