From 908ff9861349166e4f1946e689adc67716ff88fd Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Mon, 2 Dec 2013 09:16:21 +0100 Subject: [PATCH] decode file names with filesystem encoding, then encode as utf-8 before encoding with simplejson --- packages/wakatime/wakatime-cli.py | 1 - packages/wakatime/wakatime/log.py | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/wakatime/wakatime-cli.py b/packages/wakatime/wakatime-cli.py index 1287c89..690712d 100644 --- a/packages/wakatime/wakatime-cli.py +++ b/packages/wakatime/wakatime-cli.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- """ wakatime-cli diff --git a/packages/wakatime/wakatime/log.py b/packages/wakatime/wakatime/log.py index 860efe8..ee810d7 100644 --- a/packages/wakatime/wakatime/log.py +++ b/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