diff --git a/bin/cqlsh.py b/bin/cqlsh.py index 999ddc42f8..6df1d75ab1 100644 --- a/bin/cqlsh.py +++ b/bin/cqlsh.py @@ -945,7 +945,7 @@ class Shell(cmd.Cmd): try: import readline except ImportError: - if platform.system() == 'Windows': + if myplatform == 'Windows': print "WARNING: pyreadline dependency missing. Install to enable tab completion." pass else: diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py index ff5b118fa9..00d5b405df 100644 --- a/pylib/cqlshlib/formatting.py +++ b/pylib/cqlshlib/formatting.py @@ -16,16 +16,20 @@ import calendar import math +import platform import re import sys import platform import time from collections import defaultdict + from . import wcwidth from .displaying import colorme, FormattedValue, DEFAULT_VALUE_COLORS from datetime import datetime, timedelta from cassandra.cqltypes import EMPTY +is_win = platform.system() == 'Windows' + unicode_controlchars_re = re.compile(r'[\x00-\x31\x7f-\xa0]') controlchars_re = re.compile(r'[\x00-\x31\x7f-\xff]') @@ -193,15 +197,24 @@ def strftime(time_format, seconds): offset = -time.altzone else: offset = -time.timezone - if formatted[-4:] != '0000' or time_format[-2:] != '%z' or offset == 0: + if not is_win and (formatted[-4:] != '0000' or time_format[-2:] != '%z' or offset == 0): return formatted + elif is_win and time_format[-2:] != '%z': + return formatted + # deal with %z on platforms where it isn't supported. see CASSANDRA-4746. if offset < 0: sign = '-' else: sign = '+' hours, minutes = divmod(abs(offset) / 60, 60) - return formatted[:-5] + sign + '{0:0=2}{1:0=2}'.format(hours, minutes) + # Need to strip out invalid %z output on Windows. C libs give us 'Eastern Standard Time' instead of +/- GMT + if is_win and time_format[-2:] == '%z': + # Remove chars and strip trailing spaces left behind + formatted = re.sub('[A-Za-z]', '', formatted).rstrip() + return formatted + sign + '{0:0=2}{1:0=2}'.format(hours, minutes) + else: + return formatted[:-5] + sign + '{0:0=2}{1:0=2}'.format(hours, minutes) @formatter_for('Date') def format_value_date(val, colormap, **_):