upgrade wakatime-cli to v2.1.8 to fix unicode decode errors

This commit is contained in:
Alan Hamlett 2014-12-04 11:43:20 -08:00
parent 048c21c084
commit 9309203a3c
4 changed files with 37 additions and 21 deletions

View file

@ -3,6 +3,13 @@ History
------- -------
2.1.8 (2014-12-04)
++++++++++++++++++
- fix UnicodeDecodeError when building user agent string
- handle case where response is None
2.1.7 (2014-11-30) 2.1.7 (2014-11-30)
++++++++++++++++++ ++++++++++++++++++

View file

@ -13,7 +13,7 @@
from __future__ import print_function from __future__ import print_function
__title__ = 'wakatime' __title__ = 'wakatime'
__version__ = '2.1.7' __version__ = '2.1.8'
__author__ = 'Alan Hamlett' __author__ = 'Alan Hamlett'
__license__ = 'BSD' __license__ = 'BSD'
__copyright__ = 'Copyright 2014 Alan Hamlett' __copyright__ = 'Copyright 2014 Alan Hamlett'
@ -122,7 +122,7 @@ def parseConfigFile(configFile):
print(traceback.format_exc()) print(traceback.format_exc())
return None return None
except IOError: except IOError:
print(u('Error: Could not read from config file {0}').format(configFile)) print(u('Error: Could not read from config file {0}').format(u(configFile)))
return configs return configs
@ -227,8 +227,8 @@ def should_ignore(fileName, patterns):
return pattern return pattern
except re.error as ex: except re.error as ex:
log.warning(u('Regex error ({msg}) for ignore pattern: {pattern}').format( log.warning(u('Regex error ({msg}) for ignore pattern: {pattern}').format(
msg=str(ex), msg=u(ex),
pattern=pattern, pattern=u(pattern),
)) ))
except TypeError: except TypeError:
pass pass
@ -239,14 +239,14 @@ def get_user_agent(plugin):
ver = sys.version_info ver = sys.version_info
python_version = '%d.%d.%d.%s.%d' % (ver[0], ver[1], ver[2], ver[3], ver[4]) python_version = '%d.%d.%d.%s.%d' % (ver[0], ver[1], ver[2], ver[3], ver[4])
user_agent = u('wakatime/{ver} ({platform}) Python{py_ver}').format( user_agent = u('wakatime/{ver} ({platform}) Python{py_ver}').format(
ver=__version__, ver=u(__version__),
platform=platform.platform(), platform=u(platform.platform()),
py_ver=python_version, py_ver=python_version,
) )
if plugin: if plugin:
user_agent = u('{user_agent} {plugin}').format( user_agent = u('{user_agent} {plugin}').format(
user_agent=user_agent, user_agent=user_agent,
plugin=plugin, plugin=u(plugin),
) )
return user_agent return user_agent
@ -263,7 +263,7 @@ def send_action(project=None, branch=None, stats=None, key=None, targetFile=None
if hidefilenames and targetFile is not None: if hidefilenames and targetFile is not None:
data['file'] = data['file'].rsplit('/', 1)[-1].rsplit('\\', 1)[-1] data['file'] = data['file'].rsplit('/', 1)[-1].rsplit('\\', 1)[-1]
if len(data['file'].strip('.').split('.', 1)) > 1: if len(data['file'].strip('.').split('.', 1)) > 1:
data['file'] = u('HIDDEN.{ext}').format(ext=data['file'].strip('.').rsplit('.', 1)[-1]) data['file'] = u('HIDDEN.{ext}').format(ext=u(data['file'].strip('.').rsplit('.', 1)[-1]))
else: else:
data['file'] = u('HIDDEN') data['file'] = u('HIDDEN')
if stats.get('lines'): if stats.get('lines'):
@ -314,7 +314,7 @@ def send_action(project=None, branch=None, stats=None, key=None, targetFile=None
queue.push(data, plugin) queue.push(data, plugin)
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
log.warn(exception_data) log.warn(exception_data)
if response.getcode() in ALWAYS_LOG_CODES: if response is not None and response.getcode() in ALWAYS_LOG_CODES:
log.error({ log.error({
'response_code': response.getcode(), 'response_code': response.getcode(),
}) })
@ -333,35 +333,37 @@ def send_action(project=None, branch=None, stats=None, key=None, targetFile=None
log.error(exception_data) log.error(exception_data)
elif log.isEnabledFor(logging.DEBUG): elif log.isEnabledFor(logging.DEBUG):
log.warn(exception_data) log.warn(exception_data)
if response.getcode() in ALWAYS_LOG_CODES: if response is not None and response.getcode() in ALWAYS_LOG_CODES:
log.error({ log.error({
'response_code': response.getcode(), 'response_code': response.getcode(),
}) })
else: else:
log.error(exception_data) log.error(exception_data)
else: else:
if response.getcode() == 201: if response is not None and response.getcode() == 201:
log.debug({ log.debug({
'response_code': response.getcode(), 'response_code': response.getcode(),
}) })
return True return True
response_code = response.getcode() if response is not None else None
response_content = response.read() if response is not None else None
if offline: if offline:
queue = Queue() queue = Queue()
queue.push(data, plugin) queue.push(data, plugin)
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
log.warn({ log.warn({
'response_code': response.getcode(), 'response_code': response_code,
'response_content': response.read(), 'response_content': response_content,
}) })
else: else:
log.error({ log.error({
'response_code': response.getcode(), 'response_code': response_code,
'response_content': response.read(), 'response_content': response_content,
}) })
else: else:
log.error({ log.error({
'response_code': response.getcode(), 'response_code': response_code,
'response_content': response.read(), 'response_content': response_content,
}) })
return False return False
@ -379,7 +381,7 @@ def main(argv=None):
ignore = should_ignore(args.targetFile, args.ignore) ignore = should_ignore(args.targetFile, args.ignore)
if ignore is not False: if ignore is not False:
log.debug(u('File ignored because matches pattern: {pattern}').format( log.debug(u('File ignored because matches pattern: {pattern}').format(
pattern=ignore, pattern=u(ignore),
)) ))
return 0 return 0

View file

@ -21,9 +21,13 @@ is_py3 = (sys.version_info[0] == 3)
if is_py2: if is_py2:
def u(text): def u(text):
if isinstance(text, str): try:
return text.decode('utf-8') return text.decode('utf-8')
return unicode(text) except:
try:
return unicode(text)
except:
return text
open = codecs.open open = codecs.open
basestring = basestring basestring = basestring

View file

@ -15,6 +15,9 @@ import logging
import os import os
import traceback import traceback
from time import sleep from time import sleep
from .compat import u
try: try:
import sqlite3 import sqlite3
HAS_SQL = True HAS_SQL = True
@ -90,7 +93,7 @@ class Queue(object):
for row_name in ['file', 'time', 'project', 'language', 'lines', 'branch', 'is_write']: for row_name in ['file', 'time', 'project', 'language', 'lines', 'branch', 'is_write']:
if row[index] is not None: if row[index] is not None:
clauses.append('{0}=?'.format(row_name)) clauses.append('{0}=?'.format(row_name))
values.append(row[index]) values.append(u(row[index]))
else: else:
clauses.append('{0} IS NULL'.format(row_name)) clauses.append('{0} IS NULL'.format(row_name))
index += 1 index += 1