mirror of
https://github.com/JoelBender/bacpypes
synced 2025-09-28 22:15:23 +08:00
be more explicit with bytes in upstream and downstream PDUs
This commit is contained in:
parent
9b288405ef
commit
1864cc5422
|
@ -49,8 +49,12 @@ class ConsoleClient(asyncore.file_dispatcher, Client):
|
|||
|
||||
def handle_read(self):
|
||||
deferred(ConsoleClient._debug, "handle_read")
|
||||
|
||||
# read from stdin (implicit encoding)
|
||||
data = sys.stdin.read()
|
||||
deferred(ConsoleClient._debug, " - data: %r", data)
|
||||
|
||||
# make a PDU and send it downstream
|
||||
deferred(self.request, PDU(data))
|
||||
|
||||
def confirmation(self, pdu):
|
||||
|
@ -81,15 +85,19 @@ class ConsoleServer(asyncore.file_dispatcher, Server):
|
|||
|
||||
def handle_read(self):
|
||||
deferred(ConsoleServer._debug, "handle_read")
|
||||
|
||||
# read from stdin (implicit encoding)
|
||||
data = sys.stdin.read()
|
||||
deferred(ConsoleServer._debug, " - data: %r", data)
|
||||
|
||||
# make a PDU and send it upstream
|
||||
deferred(self.response, PDU(data))
|
||||
|
||||
def indication(self, pdu):
|
||||
deferred(ConsoleServer._debug, "Indication %r", pdu)
|
||||
deferred(ConsoleServer._debug, "indication %r", pdu)
|
||||
try:
|
||||
sys.stdout.write(pdu.pduData)
|
||||
except Exception, err:
|
||||
ConsoleServer._exception("Indication sys.stdout.write exception: %r", err)
|
||||
ConsoleServer._exception("indication sys.stdout.write exception: %r", err)
|
||||
|
||||
bacpypes_debugging(ConsoleServer)
|
||||
|
|
|
@ -50,14 +50,23 @@ class ConsoleClient(asyncore.file_dispatcher, Client):
|
|||
|
||||
def handle_read(self):
|
||||
if _debug: deferred(ConsoleClient._debug, "handle_read")
|
||||
data = sys.stdin.read()
|
||||
|
||||
# read from stdin and encode it
|
||||
data = sys.stdin.read().encode('utf-8')
|
||||
if _debug: deferred(ConsoleClient._debug, " - data: %r", data)
|
||||
|
||||
# make a PDU and send it downstream
|
||||
deferred(self.request, PDU(data))
|
||||
|
||||
def confirmation(self, pdu):
|
||||
if _debug: deferred(ConsoleClient._debug, "confirmation %r", pdu)
|
||||
try:
|
||||
sys.stdout.write(pdu.pduData)
|
||||
# decode the data
|
||||
data = pdu.pduData.decode('utf-8')
|
||||
if _debug: deferred(ConsoleClient._debug, " - data: %r", data)
|
||||
|
||||
# send it out
|
||||
sys.stdout.write(data)
|
||||
except Exception as err:
|
||||
ConsoleClient._exception("Confirmation sys.stdout.write exception: %r", err)
|
||||
|
||||
|
@ -81,13 +90,22 @@ class ConsoleServer(asyncore.file_dispatcher, Server):
|
|||
|
||||
def handle_read(self):
|
||||
if _debug: deferred(ConsoleServer._debug, "handle_read")
|
||||
data = sys.stdin.read()
|
||||
|
||||
# read from stdin and encode it
|
||||
data = sys.stdin.read().encode('utf-8')
|
||||
if _debug: deferred(ConsoleServer._debug, " - data: %r", data)
|
||||
|
||||
# make a PDU and send it upstream
|
||||
deferred(self.response, PDU(data))
|
||||
|
||||
def indication(self, pdu):
|
||||
if _debug: deferred(ConsoleServer._debug, "Indication %r", pdu)
|
||||
if _debug: deferred(ConsoleServer._debug, "indication %r", pdu)
|
||||
try:
|
||||
sys.stdout.write(pdu.pduData)
|
||||
# decode the data
|
||||
data = pdu.pduData.decode('utf-8')
|
||||
if _debug: deferred(ConsoleServer._debug, " - data: %r", data)
|
||||
|
||||
# send it out
|
||||
sys.stdout.write(data)
|
||||
except Exception as err:
|
||||
ConsoleServer._exception("Indication sys.stdout.write exception: %r", err)
|
||||
ConsoleServer._exception("indication sys.stdout.write exception: %r", err)
|
||||
|
|
|
@ -50,14 +50,23 @@ class ConsoleClient(asyncore.file_dispatcher, Client):
|
|||
|
||||
def handle_read(self):
|
||||
if _debug: deferred(ConsoleClient._debug, "handle_read")
|
||||
data = sys.stdin.read()
|
||||
|
||||
# read from stdin and encode it
|
||||
data = sys.stdin.read().encode('utf-8')
|
||||
if _debug: deferred(ConsoleClient._debug, " - data: %r", data)
|
||||
deferred(self.request, PDU(data.encode('utf_8')))
|
||||
|
||||
# make a PDU and send it downstream
|
||||
deferred(self.request, PDU(data))
|
||||
|
||||
def confirmation(self, pdu):
|
||||
if _debug: deferred(ConsoleClient._debug, "confirmation %r", pdu)
|
||||
try:
|
||||
sys.stdout.write(pdu.pduData.decode('utf_8'))
|
||||
# decode the data
|
||||
data = pdu.pduData.decode('utf-8')
|
||||
if _debug: deferred(ConsoleClient._debug, " - data: %r", data)
|
||||
|
||||
# send it out
|
||||
sys.stdout.write(data)
|
||||
except Exception as err:
|
||||
ConsoleClient._exception("Confirmation sys.stdout.write exception: %r", err)
|
||||
|
||||
|
@ -81,13 +90,22 @@ class ConsoleServer(asyncore.file_dispatcher, Server):
|
|||
|
||||
def handle_read(self):
|
||||
if _debug: deferred(ConsoleServer._debug, "handle_read")
|
||||
data = sys.stdin.read()
|
||||
|
||||
# read from stdin and encode it
|
||||
data = sys.stdin.read().encode('utf-8')
|
||||
if _debug: deferred(ConsoleServer._debug, " - data: %r", data)
|
||||
deferred(self.response, PDU(data.encode('utf_8')))
|
||||
|
||||
# make a PDU and send it upstream
|
||||
deferred(self.response, PDU(data))
|
||||
|
||||
def indication(self, pdu):
|
||||
if _debug: deferred(ConsoleServer._debug, "Indication %r", pdu)
|
||||
if _debug: deferred(ConsoleServer._debug, "indication %r", pdu)
|
||||
try:
|
||||
sys.stdout.write(pdu.pduData.decode('utf_8'))
|
||||
# decode the data
|
||||
data = pdu.pduData.decode('utf-8')
|
||||
if _debug: deferred(ConsoleServer._debug, " - data: %r", data)
|
||||
|
||||
# send it out
|
||||
sys.stdout.write(data)
|
||||
except Exception as err:
|
||||
ConsoleServer._exception("Indication sys.stdout.write exception: %r", err)
|
||||
ConsoleServer._exception("indication sys.stdout.write exception: %r", err)
|
||||
|
|
Loading…
Reference in New Issue
Block a user