Update transports.py

Under p3k, this code throws NameError (because of the unicode() function)
This fix should be valid under both python2 and python3
This commit is contained in:
Adam Kecer 2015-02-11 18:45:23 +01:00
commit fc3a8b5e32

View file

@ -68,7 +68,10 @@ class _AbstractTransport(object):
def send_packet(self, code, path='', data='', callback=None):
packet_id = self.set_ack_callback(callback) if callback else ''
packet_parts = str(code), packet_id, path, unicode(data).encode('utf-8')
try:
packet_parts = str(code), packet_id, path, unicode(data).encode('utf-8')
except NameError: # fix for p3k
packet_parts = str(code), packet_id, path, data
packet_text = ':'.join(packet_parts)
self.send(packet_text)
self._log(logging.DEBUG, '[packet sent] %s', packet_text)