From 58015fd681dadbe31068ecfb4f4c0eb506de8efa Mon Sep 17 00:00:00 2001 From: Eduard Tudenhoefner Date: Tue, 7 Apr 2020 17:16:40 +0200 Subject: [PATCH] Use Exception.message in copyutil.py only if it exists Exception.message was removed in Python 3, so only refer to it when it exists on an Exception instance. Also fix code style compliance in formatting.py (missing blank lines) patch by Eduard Tudenhoefner; reviewed by Stefania Alborghetti for CASSANDRA-15702 --- pylib/cqlshlib/copyutil.py | 8 ++++---- pylib/cqlshlib/formatting.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pylib/cqlshlib/copyutil.py b/pylib/cqlshlib/copyutil.py index 853893c2a8..169a6e0c4f 100644 --- a/pylib/cqlshlib/copyutil.py +++ b/pylib/cqlshlib/copyutil.py @@ -146,7 +146,7 @@ class SendingChannel(object): msg = self.pending_messages.get() self.pipe.send(msg) except Exception as e: - printmsg('%s: %s' % (e.__class__.__name__, e.message)) + printmsg('%s: %s' % (e.__class__.__name__, e.message if hasattr(e, 'message') else str(e))) feeding_thread = threading.Thread(target=feed) feeding_thread.setDaemon(True) @@ -1342,7 +1342,7 @@ class FeedingProcess(mp.Process): try: reader.start() except IOError as exc: - self.outmsg.send(ImportTaskError(exc.__class__.__name__, exc.message)) + self.outmsg.send(ImportTaskError(exc.__class__.__name__, exc.message if hasattr(exc, 'message') else str(exc))) channels = self.worker_channels max_pending_chunks = self.max_pending_chunks @@ -1371,7 +1371,7 @@ class FeedingProcess(mp.Process): if rows: sent += self.send_chunk(ch, rows) except Exception as exc: - self.outmsg.send(ImportTaskError(exc.__class__.__name__, exc.message)) + self.outmsg.send(ImportTaskError(exc.__class__.__name__, exc.message if hasattr(exc, 'message') else str(exc))) if reader.exhausted: break @@ -2632,7 +2632,7 @@ class ImportProcess(ChildProcess): pk = get_row_partition_key_values(row) rows_by_ring_pos[get_ring_pos(ring, pk_to_token_value(pk))].append(row) except Exception as e: - errors[e.message].append(row) + errors[e.message if hasattr(e, 'message') else str(e)].append(row) if errors: for msg, rows in errors.items(): diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py index e00d91f2d6..a8ee51d225 100644 --- a/pylib/cqlshlib/formatting.py +++ b/pylib/cqlshlib/formatting.py @@ -239,6 +239,7 @@ def formatter_for(typname): return f return registrator + class BlobType(object): def __init__(self, val): self.val = val @@ -246,6 +247,7 @@ class BlobType(object): def __str__(self): return str(self.val) + @formatter_for('BlobType') def format_value_blob(val, colormap, **_): bval = ensure_text('0x') + ensure_text(binascii.hexlify(val))