本文整理汇总了Python中util.print_error函数的典型用法代码示例。如果您正苦于以下问题:Python print_error函数的具体用法?Python print_error怎么用?Python print_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_parameters
def set_parameters(self, host, port, protocol, proxy, auto_connect):
proxy_str = interface.serialize_proxy(proxy)
server_str = ':'.join([ host, port, protocol ])
self.config.set_key('auto_cycle', auto_connect, True)
self.config.set_key("proxy", proxy_str, True)
self.config.set_key("protocol", protocol, True)
self.config.set_key("server", server_str, True)
if self.proxy != proxy_str or self.protocol != protocol:
print_error('restarting network')
self.proxy = proxy_str
self.protocol = protocol
for i in self.interfaces.values(): i.stop()
if auto_connect:
#self.interface = None
return
if auto_connect:
if not self.interface.is_connected:
self.switch_to_random_interface()
else:
if self.server_is_lagging():
self.stop_interface()
else:
self.set_server(server_str)
示例2: verify_chunk
def verify_chunk(self, index, hexdata):
data = hexdata.decode('hex')
height = index*1920
num = len(data)/80
if index == 0:
previous_hash = ("0"*64)
else:
prev_header = self.read_header(index*1920-1)
if prev_header is None: raise
previous_hash = self.hash_header(prev_header)
if height < 43847:
bits, target = self.get_target(index)
for i in xrange(num):
height = index*1920 + i
raw_header = data[i*80:(i+1)*80]
header = self.header_from_string(raw_header)
_hash = self.pow_hash_header(header)
if height >= 43847:
bits, target = self.get_target(height, data=data)
assert previous_hash == header.get('prev_block_hash')
assert bits == header.get('bits')
assert int('0x'+_hash,16) < target
print_error( 'verified height ', str(height))
previous_header = header
previous_hash = self.hash_header(header)
self.save_chunk(index, data)
print_error("validated chunk %d"%height)
示例3: get_chain
def get_chain(self, interface, final_header):
header = final_header
chain = [ final_header ]
requested_header = False
queue = Queue.Queue()
height = header.get('block_height')
while self.is_running():
if requested_header:
header = self.retrieve_header(interface, queue)
if not header: return
chain = [ header ] + chain
requested_header = False
height = header.get('block_height')
previous_header = self.read_header(height -1)
if not previous_header:
self.request_header(interface, height - 1, queue)
requested_header = True
continue
# verify that it connects to my chain
prev_hash = self.hash_header(previous_header)
if prev_hash != header.get('prev_block_hash'):
print_error("reorg")
self.request_header(interface, height - 1, queue)
requested_header = True
continue
else:
# the chain is complete
return chain
示例4: send
def send(self, messages, callback):
sub = []
for message in messages:
m, v = message
if m[-10:] == '.subscribe':
sub.append(message)
if sub:
with self.lock:
if self.subscriptions.get(callback) is None:
self.subscriptions[callback] = []
for message in sub:
if message not in self.subscriptions[callback]:
self.subscriptions[callback].append(message)
if not self.is_connected:
print_error("interface: trying to send while not connected")
return
if self.protocol in 'st':
with self.lock:
out = self.send_tcp(messages, callback)
else:
# do not use lock, http is synchronous
out = self.send_http(messages, callback)
return out
示例5: run
def run(self):
self.network.start(self.network_queue)
while self.is_running():
try:
response = self.network_queue.get(timeout=0.1)
except Queue.Empty:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# notification
m = response.get('method')
v = response.get('params')
for client in self.clients:
if repr((m, v)) in client.subscriptions:
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")
示例6: daemon_loop
def daemon_loop(server):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
daemon_port = server.config.get('daemon_port', DAEMON_PORT)
daemon_timeout = server.config.get('daemon_timeout', 5*60)
s.bind(('localhost', daemon_port))
s.listen(5)
s.settimeout(1)
t = time.time()
while server.running:
try:
connection, address = s.accept()
except socket.timeout:
if not server.clients:
if time.time() - t > daemon_timeout:
print_error("Daemon timeout")
break
else:
t = time.time()
continue
t = time.time()
client = ClientThread(server, connection)
client.start()
server.stop()
# sleep so that other threads can terminate cleanly
time.sleep(0.5)
print_error("Daemon exiting")
示例7: sign
def sign(self, keypairs):
for i, txin in enumerate(self.inputs()):
num = txin['num_sig']
for x_pubkey in txin['x_pubkeys']:
signatures = filter(None, txin['signatures'])
if len(signatures) == num:
# txin is complete
break
if x_pubkey in keypairs.keys():
print_error("adding signature for", x_pubkey)
# add pubkey to txin
txin = self._inputs[i]
x_pubkeys = txin['x_pubkeys']
ii = x_pubkeys.index(x_pubkey)
sec = keypairs[x_pubkey]
pubkey = public_key_from_private_key(sec)
txin['x_pubkeys'][ii] = pubkey
txin['pubkeys'][ii] = pubkey
self._inputs[i] = txin
# add signature
for_sig = Hash(self.tx_for_sig(i).decode('hex'))
pkey = regenerate_key(sec)
secexp = pkey.secret
private_key = bitcoin.MySigningKey.from_secret_exponent( secexp, curve = SECP256k1 )
public_key = private_key.get_verifying_key()
sig = private_key.sign_digest_deterministic( for_sig, hashfunc=hashlib.sha256, sigencode = ecdsa.util.sigencode_der )
assert public_key.verify_digest( sig, for_sig, sigdecode = ecdsa.util.sigdecode_der)
txin['signatures'][ii] = sig.encode('hex')
self._inputs[i] = txin
print_error("is_complete", self.is_complete())
self.raw = self.serialize()
示例8: server_is_lagging
def server_is_lagging(self):
h = self.get_server_height()
if not h:
print_error('no height for main interface')
return False
lag = self.get_local_height() - self.get_server_height()
return lag > 1
示例9: new_blockchain_height
def new_blockchain_height(self, blockchain_height, i):
if self.is_connected():
if self.server_is_lagging():
print_error( "Server is lagging", blockchain_height, self.get_server_height())
if self.config.get('auto_cycle'):
self.set_server(i.server)
self.notify('updated')
示例10: run
def run(self):
self.blockchain.start()
with self.lock:
self.running = True
while self.is_running():
try:
i = self.queue.get(timeout = 30 if self.interfaces else 3)
except Queue.Empty:
if len(self.interfaces) < NUM_SERVERS:
self.start_random_interface()
continue
if i.is_connected:
self.add_recent_server(i)
i.send([ ('blockchain.headers.subscribe',[])], self.on_header)
if i == self.interface:
print_error('sending subscriptions to', self.interface.server)
self.send_subscriptions()
self.trigger_callback('connected')
else:
self.disconnected_servers.append(i.server)
self.interfaces.pop(i.server)
if i.server in self.heights:
self.heights.pop(i.server)
if i == self.interface:
self.interface = None
self.trigger_callback('disconnected')
if self.interface is None and self.config.get('auto_cycle'):
self.switch_to_random_interface()
示例11: __init__
def __init__(self, options={}):
# system conf, readonly
self.system_config = {}
if options.get('portable') == False:
self.read_system_config()
# user conf, writeable
self.user_dir = user_dir()
self.user_config = {}
if options.get('portable') == False:
self.read_user_config()
# command-line options
self.options_config = options
self.wallet_config = {}
self.wallet_file_exists = False
self.init_path(self.options_config.get('wallet_path'))
print_error( "path", self.path )
if self.path:
self.read_wallet_config(self.path)
# portable wallet: use the same directory for wallet and headers file
if options.get('portable'):
self.wallet_config['blockchain_headers_path'] = os.path.dirname(self.path)
示例12: verify_chunk
def verify_chunk(self, index, hexdata):
data = hexdata.decode('hex')
height = index
num = len(data)/88
if index == 0:
previous_hash = ("0"*64)
else:
prev_header = self.read_header(index-1)
if prev_header is None: raise
previous_hash = self.hash_header(prev_header)
bits, target = self.get_target(index)
for i in range(num):
height = index + i
raw_header = data[i*88:(i+1)*88]
header = self.header_from_string(raw_header)
_hash = self.hash_header(header)
assert previous_hash == header.get('prev_block_hash')
#assert bits == header.get('bits')
#assert int('0x'+_hash,16) < target # Cant do bits for memorycoin yet
previous_header = header
previous_hash = _hash
self.save_chunk(index, data)
print_error("validated chunk %d"%height)
示例13: get_chunks
def get_chunks(self, i, header, height):
requested_chunks = []
min_index = (self.local_height + 1)/2016
max_index = (height + 1)/2016
for n in range(min_index, max_index + 1):
print_error( "requesting chunk", n )
i.send([ ('blockchain.block.get_chunk',[n])], 'get_header')
requested_chunks.append(n)
break
while requested_chunks:
try:
r = i.get_response('get_header',timeout=1)
except Queue.Empty:
continue
if not r: continue
if r.get('error'):
print_error('Verifier received an error:', r)
continue
# 3. handle response
method = r['method']
params = r['params']
result = r['result']
if method == 'blockchain.block.get_chunk':
index = params[0]
self.verify_chunk(index, result)
requested_chunks.remove(index)
示例14: verify_header
def verify_header(self, header):
# add header to the blockchain file
# if there is a reorg, push it in a stack
height = header.get('block_height')
prev_header = self.read_header(height -1)
if not prev_header:
# return False to request previous header
return False
prev_hash = self.hash_header(prev_header)
bits, target = self.get_target(height/2016)
_hash = self.hash_header(header)
try:
assert prev_hash == header.get('prev_block_hash')
assert bits == header.get('bits')
assert eval('0x'+_hash) < target
except:
# this can be caused by a reorg.
print_error("verify header failed"+ repr(header))
verifier.undo_verifications()
# return False to request previous header.
return False
self.save_header(header)
print_error("verify header:", _hash, height)
return True
示例15: process_pending_sends
def process_pending_sends(self):
# Requests needs connectivity. If we don't have an interface,
# we cannot process them.
if not self.interface:
return
with self.lock:
sends = self.pending_sends
self.pending_sends = []
for messages, callback in sends:
for method, params in messages:
r = None
if method.endswith('.subscribe'):
k = self.get_index(method, params)
# add callback to list
l = self.subscriptions.get(k, [])
if callback not in l:
l.append(callback)
self.subscriptions[k] = l
# check cached response for subscriptions
r = self.sub_cache.get(k)
if r is not None:
util.print_error("cache hit", k)
callback(r)
else:
message_id = self.queue_request(method, params)
self.unanswered_requests[message_id] = method, params, callback