From 9172ef21bf03c869313c2caf78dfef02e8241f85 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Mon, 2 Dec 2013 09:20:25 +0100 Subject: [PATCH] decode file names with filesystem encoding, then encode as utf-8 before encoding with simplejson --- plugin/packages/wakatime/wakatime-cli.py | 1 - plugin/packages/wakatime/wakatime/log.py | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/packages/wakatime/wakatime-cli.py b/plugin/packages/wakatime/wakatime-cli.py index 1287c89..690712d 100644 --- a/plugin/packages/wakatime/wakatime-cli.py +++ b/plugin/packages/wakatime/wakatime-cli.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- """ wakatime-cli diff --git a/plugin/packages/wakatime/wakatime/log.py b/plugin/packages/wakatime/wakatime/log.py index 860efe8..ee810d7 100644 --- a/plugin/packages/wakatime/wakatime/log.py +++ b/plugin/packages/wakatime/wakatime/log.py @@ -11,6 +11,7 @@ import logging import os +import sys from .packages import simplejson as json try: @@ -28,7 +29,8 @@ class CustomEncoder(json.JSONEncoder): try: encoded = super(CustomEncoder, self).default(obj) except UnicodeDecodeError: - obj = obj.decode('utf-8', 'ignore') + encoding = sys.getfilesystemencoding() + obj = obj.decode(encoding, 'ignore').encode('utf-8') encoded = super(CustomEncoder, self).default(obj) return encoded