Fix handling of incorrect %z cqlshlib output on Windows

Patch by jmckenzie; reviewed by aweisberg for CASSANDRA-9418
This commit is contained in:
Joshua McKenzie 2015-07-23 13:21:10 -04:00
parent 51ff499754
commit 99decd8efa
2 changed files with 16 additions and 3 deletions

View File

@ -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:

View File

@ -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, **_):