changing syntax for print lock

This commit is contained in:
Chuck 2013-07-06 18:45:51 +07:00
parent 8760153f7f
commit d747394234
4 changed files with 56 additions and 69 deletions

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'settings.ui' # Form implementation generated from reading ui file 'settings.ui'
# #
# Created: Sat Jul 06 18:17:40 2013 # Created: Sat Jul 06 18:24:20 2013
# by: PyQt4 UI code generator 4.10.1 # by: PyQt4 UI code generator 4.10.1
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -9,9 +9,8 @@ class asyncoreThread(threading.Thread):
threading.Thread.__init__(self) threading.Thread.__init__(self)
def run(self): def run(self):
shared.printLock.acquire() with shared.printLock:
print "Asyncore thread started" print "Asyncore thread started"
shared.printLock.release()
while True: while True:
asyncore.loop(timeout=1) # Despite the horrible parameter name, this function will not timeout until all channels are closed. asyncore.loop(timeout=1) # Despite the horrible parameter name, this function will not timeout until all channels are closed.

View File

@ -104,11 +104,10 @@ class bitmessagePOP3Connection(asyncore.dispatcher):
def sendline(self, data, END=END): def sendline(self, data, END=END):
if self.debug: if self.debug:
shared.printLock.acquire() with shared.printLock:
sys.stdout.write("sending ") sys.stdout.write("sending ")
sys.stdout.write(data) sys.stdout.write(data)
sys.stdout.write("\n") sys.stdout.write("\n")
shared.printLock.release()
data = data + END data = data + END
while len(data) > 4096: while len(data) > 4096:
self.send(data[:4096]) self.send(data[:4096])
@ -130,11 +129,10 @@ class bitmessagePOP3Connection(asyncore.dispatcher):
self.data_buffer.append(chunk) self.data_buffer.append(chunk)
if self.debug: if self.debug:
shared.printLock.acquire() with shared.printLock:
print('data_buffer', self.data_buffer) print('data_buffer', self.data_buffer)
print('commands', self.commands) print('commands', self.commands)
print('-') print('-')
shared.printLock.release()
while len(self.commands): while len(self.commands):
line = self.commands.popleft() line = self.commands.popleft()
@ -170,7 +168,7 @@ class bitmessagePOP3Connection(asyncore.dispatcher):
status, addressVersionNumber, streamNumber, ripe = decodeAddress(self.address) status, addressVersionNumber, streamNumber, ripe = decodeAddress(self.address)
if status != 'success': if status != 'success':
shared.printLock.acquire() with shared.printLock:
print 'Error: Could not decode address: ' + self.address + ' : ' + status print 'Error: Could not decode address: ' + self.address + ' : ' + status
if status == 'checksumfailed': if status == 'checksumfailed':
print 'Error: Checksum failed for address: ' + self.address print 'Error: Checksum failed for address: ' + self.address
@ -178,7 +176,6 @@ class bitmessagePOP3Connection(asyncore.dispatcher):
print 'Error: Invalid characters in address: ' + self.address print 'Error: Invalid characters in address: ' + self.address
if status == 'versiontoohigh': if status == 'versiontoohigh':
print 'Error: Address version number too high (or zero) in address: ' + self.address print 'Error: Address version number too high (or zero) in address: ' + self.address
shared.printLock.release()
raise Exception("Invalid Bitmessage address: {}".format(self.address)) raise Exception("Invalid Bitmessage address: {}".format(self.address))
username = '{}@{}'.format(getBase58Capitaliation(self.address), self.address) username = '{}@{}'.format(getBase58Capitaliation(self.address), self.address)
@ -237,9 +234,8 @@ class bitmessagePOP3Connection(asyncore.dispatcher):
msg = self.messages[index] msg = self.messages[index]
content = self.getMessageContent(msg['msgid']) content = self.getMessageContent(msg['msgid'])
if self.debug: if self.debug:
shared.printLock.acquire() with shared.printLock:
sys.stdout.write(str(msg) + ": " + str(content)) sys.stdout.write(str(msg) + ": " + str(content))
shared.printLock.release()
yield "+OK {} octets".format(msg['size']) yield "+OK {} octets".format(msg['size'])
yield content['message'] yield content['message']
yield '.' yield '.'
@ -281,9 +277,8 @@ class bitmessagePOP3Server(asyncore.dispatcher):
self.bind((bindAddress, pop3port)) self.bind((bindAddress, pop3port))
self.listen(10) self.listen(10)
shared.printLock.acquire() with shared.printLock:
print "POP3 server started: SSL enabled={}".format(str(self.ssl)) print "POP3 server started: SSL enabled={}".format(str(self.ssl))
shared.printLock.release()
def handle_accept(self): def handle_accept(self):
sock, peer_address = self.accept() sock, peer_address = self.accept()

View File

@ -179,7 +179,7 @@ class bitmessageSMTPChannel(asynchat.async_chat):
status, addressVersionNumber, streamNumber, ripe = decodeAddress(self.address) status, addressVersionNumber, streamNumber, ripe = decodeAddress(self.address)
if status != 'success': if status != 'success':
shared.printLock.acquire() with shared.printLock:
print 'Error: Could not decode address: ' + self.address + ' : ' + status print 'Error: Could not decode address: ' + self.address + ' : ' + status
if status == 'checksumfailed': if status == 'checksumfailed':
print 'Error: Checksum failed for address: ' + self.address print 'Error: Checksum failed for address: ' + self.address
@ -187,7 +187,6 @@ class bitmessageSMTPChannel(asynchat.async_chat):
print 'Error: Invalid characters in address: ' + self.address print 'Error: Invalid characters in address: ' + self.address
if status == 'versiontoohigh': if status == 'versiontoohigh':
print 'Error: Address version number too high (or zero) in address: ' + self.address print 'Error: Address version number too high (or zero) in address: ' + self.address
shared.printLock.release()
raise Exception("Invalid Bitmessage address: {}".format(self.address)) raise Exception("Invalid Bitmessage address: {}".format(self.address))
self.fullUsername = '{}@{}'.format(getBase58Capitaliation(self.address), address) self.fullUsername = '{}@{}'.format(getBase58Capitaliation(self.address), address)
@ -324,9 +323,8 @@ class bitmessageSMTPServer(smtpd.SMTPServer):
bindAddress = '127.0.0.1' bindAddress = '127.0.0.1'
smtpd.SMTPServer.__init__(self, (bindAddress, smtpport), None) smtpd.SMTPServer.__init__(self, (bindAddress, smtpport), None)
shared.printLock.acquire() with shared.printLock:
print "SMTP server started: SSL enabled={}".format(str(self.ssl)) print "SMTP server started: SSL enabled={}".format(str(self.ssl))
shared.printLock.release()
def handle_accept(self): def handle_accept(self):
# Override SMTPServer's handle_accept so that we can start an SSL connection. # Override SMTPServer's handle_accept so that we can start an SSL connection.
@ -363,7 +361,7 @@ class bitmessageSMTPServer(smtpd.SMTPServer):
else: else:
status, addressVersionNumber, streamNumber, fromRipe = decodeAddress(fromAddress) status, addressVersionNumber, streamNumber, fromRipe = decodeAddress(fromAddress)
if status != 'success': if status != 'success':
shared.printLock.acquire() with shared.printLock:
print 'Error: Could not decode address: ' + fromAddress + ' : ' + status print 'Error: Could not decode address: ' + fromAddress + ' : ' + status
if status == 'checksumfailed': if status == 'checksumfailed':
print 'Error: Checksum failed for address: ' + fromAddress print 'Error: Checksum failed for address: ' + fromAddress
@ -371,21 +369,18 @@ class bitmessageSMTPServer(smtpd.SMTPServer):
print 'Error: Invalid characters in address: ' + fromAddress print 'Error: Invalid characters in address: ' + fromAddress
if status == 'versiontoohigh': if status == 'versiontoohigh':
print 'Error: Address version number too high (or zero) in address: ' + fromAddress print 'Error: Address version number too high (or zero) in address: ' + fromAddress
shared.printLock.release()
raise Exception("Invalid Bitmessage address: {}".format(fromAddress)) raise Exception("Invalid Bitmessage address: {}".format(fromAddress))
#fromAddress = addBMIfNotPresent(fromAddress) # I know there's a BM-, because it's required when using SMTP #fromAddress = addBMIfNotPresent(fromAddress) # I know there's a BM-, because it's required when using SMTP
try: try:
fromAddressEnabled = shared.config.getboolean(fromAddress, 'enabled') fromAddressEnabled = shared.config.getboolean(fromAddress, 'enabled')
except: except:
shared.printLock.acquire() with shared.printLock:
print 'Error: Could not find your fromAddress in the keys.dat file.' print 'Error: Could not find your fromAddress in the keys.dat file.'
shared.printLock.release()
raise Exception("Could not find address in keys.dat: {}".format(fromAddress)) raise Exception("Could not find address in keys.dat: {}".format(fromAddress))
if not fromAddressEnabled: if not fromAddressEnabled:
shared.printLock.acquire() with shared.printLock:
print 'Error: Your fromAddress is disabled. Cannot send.' print 'Error: Your fromAddress is disabled. Cannot send.'
shared.printLock.release()
raise Exception("The fromAddress is disabled: {}".format(fromAddress)) raise Exception("The fromAddress is disabled: {}".format(fromAddress))
for recipient in rcpttos: for recipient in rcpttos:
@ -402,7 +397,7 @@ class bitmessageSMTPServer(smtpd.SMTPServer):
# into a utility func! # into a utility func!
status, addressVersionNumber, streamNumber, toRipe = decodeAddress(toAddress) status, addressVersionNumber, streamNumber, toRipe = decodeAddress(toAddress)
if status != 'success': if status != 'success':
shared.printLock.acquire() with shared.printLock:
print 'Error: Could not decode address: ' + toAddress + ' : ' + status print 'Error: Could not decode address: ' + toAddress + ' : ' + status
if status == 'checksumfailed': if status == 'checksumfailed':
print 'Error: Checksum failed for address: ' + toAddress print 'Error: Checksum failed for address: ' + toAddress
@ -410,7 +405,6 @@ class bitmessageSMTPServer(smtpd.SMTPServer):
print 'Error: Invalid characters in address: ' + toAddress print 'Error: Invalid characters in address: ' + toAddress
if status == 'versiontoohigh': if status == 'versiontoohigh':
print 'Error: Address version number too high (or zero) in address: ' + toAddress print 'Error: Address version number too high (or zero) in address: ' + toAddress
shared.printLock.release()
raise Exception("Invalid Bitmessage address: {}".format(toAddress)) raise Exception("Invalid Bitmessage address: {}".format(toAddress))
toAddressIsOK = False toAddressIsOK = False
@ -423,9 +417,8 @@ class bitmessageSMTPServer(smtpd.SMTPServer):
# The toAddress is one owned by me. We cannot send # The toAddress is one owned by me. We cannot send
# messages to ourselves without significant changes # messages to ourselves without significant changes
# to the codebase. # to the codebase.
shared.printLock.acquire() with shared.printLock:
print "Error: One of the addresses to which you are sending a message, {}, is yours. Unfortunately the Bitmessage client cannot process its own messages. Please try running a second client on a different computer or within a VM.".format(toAddress) print "Error: One of the addresses to which you are sending a message, {}, is yours. Unfortunately the Bitmessage client cannot process its own messages. Please try running a second client on a different computer or within a VM.".format(toAddress)
shared.printLock.release()
raise Exception("An address that you are sending a message to, {}, is yours. Unfortunately the Bitmessage client cannot process its own messages. Please try running a second client on a different computer or within a VM.".format(toAddress)) raise Exception("An address that you are sending a message to, {}, is yours. Unfortunately the Bitmessage client cannot process its own messages. Please try running a second client on a different computer or within a VM.".format(toAddress))
# The subject is specially formatted to identify it from non-E-mail messages. # The subject is specially formatted to identify it from non-E-mail messages.