upgrade waktime-cli to v2.1.8 to fix #17 unicode decode error when building user agent string
This commit is contained in:
parent
85856f2c53
commit
4cd4a26f91
4 changed files with 37 additions and 21 deletions
|
@ -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)
|
||||
++++++++++++++++++
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
from __future__ import print_function
|
||||
|
||||
__title__ = 'wakatime'
|
||||
__version__ = '2.1.7'
|
||||
__version__ = '2.1.8'
|
||||
__author__ = 'Alan Hamlett'
|
||||
__license__ = 'BSD'
|
||||
__copyright__ = 'Copyright 2014 Alan Hamlett'
|
||||
|
@ -122,7 +122,7 @@ def parseConfigFile(configFile):
|
|||
print(traceback.format_exc())
|
||||
return None
|
||||
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
|
||||
|
||||
|
||||
|
@ -227,8 +227,8 @@ def should_ignore(fileName, patterns):
|
|||
return pattern
|
||||
except re.error as ex:
|
||||
log.warning(u('Regex error ({msg}) for ignore pattern: {pattern}').format(
|
||||
msg=str(ex),
|
||||
pattern=pattern,
|
||||
msg=u(ex),
|
||||
pattern=u(pattern),
|
||||
))
|
||||
except TypeError:
|
||||
pass
|
||||
|
@ -239,14 +239,14 @@ def get_user_agent(plugin):
|
|||
ver = sys.version_info
|
||||
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(
|
||||
ver=__version__,
|
||||
platform=platform.platform(),
|
||||
ver=u(__version__),
|
||||
platform=u(platform.platform()),
|
||||
py_ver=python_version,
|
||||
)
|
||||
if plugin:
|
||||
user_agent = u('{user_agent} {plugin}').format(
|
||||
user_agent=user_agent,
|
||||
plugin=plugin,
|
||||
plugin=u(plugin),
|
||||
)
|
||||
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:
|
||||
data['file'] = data['file'].rsplit('/', 1)[-1].rsplit('\\', 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:
|
||||
data['file'] = u('HIDDEN')
|
||||
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)
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
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({
|
||||
'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)
|
||||
elif log.isEnabledFor(logging.DEBUG):
|
||||
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({
|
||||
'response_code': response.getcode(),
|
||||
})
|
||||
else:
|
||||
log.error(exception_data)
|
||||
else:
|
||||
if response.getcode() == 201:
|
||||
if response is not None and response.getcode() == 201:
|
||||
log.debug({
|
||||
'response_code': response.getcode(),
|
||||
})
|
||||
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:
|
||||
queue = Queue()
|
||||
queue.push(data, plugin)
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
log.warn({
|
||||
'response_code': response.getcode(),
|
||||
'response_content': response.read(),
|
||||
'response_code': response_code,
|
||||
'response_content': response_content,
|
||||
})
|
||||
else:
|
||||
log.error({
|
||||
'response_code': response.getcode(),
|
||||
'response_content': response.read(),
|
||||
'response_code': response_code,
|
||||
'response_content': response_content,
|
||||
})
|
||||
else:
|
||||
log.error({
|
||||
'response_code': response.getcode(),
|
||||
'response_content': response.read(),
|
||||
'response_code': response_code,
|
||||
'response_content': response_content,
|
||||
})
|
||||
return False
|
||||
|
||||
|
@ -379,7 +381,7 @@ def main(argv=None):
|
|||
ignore = should_ignore(args.targetFile, args.ignore)
|
||||
if ignore is not False:
|
||||
log.debug(u('File ignored because matches pattern: {pattern}').format(
|
||||
pattern=ignore,
|
||||
pattern=u(ignore),
|
||||
))
|
||||
return 0
|
||||
|
||||
|
|
|
@ -21,9 +21,13 @@ is_py3 = (sys.version_info[0] == 3)
|
|||
if is_py2:
|
||||
|
||||
def u(text):
|
||||
if isinstance(text, str):
|
||||
try:
|
||||
return text.decode('utf-8')
|
||||
except:
|
||||
try:
|
||||
return unicode(text)
|
||||
except:
|
||||
return text
|
||||
open = codecs.open
|
||||
basestring = basestring
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ import logging
|
|||
import os
|
||||
import traceback
|
||||
from time import sleep
|
||||
|
||||
from .compat import u
|
||||
|
||||
try:
|
||||
import sqlite3
|
||||
HAS_SQL = True
|
||||
|
@ -90,7 +93,7 @@ class Queue(object):
|
|||
for row_name in ['file', 'time', 'project', 'language', 'lines', 'branch', 'is_write']:
|
||||
if row[index] is not None:
|
||||
clauses.append('{0}=?'.format(row_name))
|
||||
values.append(row[index])
|
||||
values.append(u(row[index]))
|
||||
else:
|
||||
clauses.append('{0} IS NULL'.format(row_name))
|
||||
index += 1
|
||||
|
|
Loading…
Reference in a new issue