Repository: cassandra Updated Branches: refs/heads/trunk 15265689f -> 1f5c4f7ba
Fix handling of incorrect %z cqlshlib output on Windows Patch by jmckenzie; reviewed by aweisberg for CASSANDRA-9418 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/99decd8e Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/99decd8e Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/99decd8e Branch: refs/heads/trunk Commit: 99decd8eface9cd38ddd70542aa28a2773810526 Parents: 51ff499 Author: Joshua McKenzie <jmcken...@apache.org> Authored: Thu Jul 23 13:21:10 2015 -0400 Committer: Joshua McKenzie <jmcken...@apache.org> Committed: Thu Jul 23 13:21:10 2015 -0400 ---------------------------------------------------------------------- bin/cqlsh.py | 2 +- pylib/cqlshlib/formatting.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/99decd8e/bin/cqlsh.py ---------------------------------------------------------------------- diff --git a/bin/cqlsh.py b/bin/cqlsh.py index 999ddc4..6df1d75 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: http://git-wip-us.apache.org/repos/asf/cassandra/blob/99decd8e/pylib/cqlshlib/formatting.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py index ff5b118..00d5b40 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, **_):