decode file names with filesystem encoding, then encode as utf-8 before encoding with simplejson
This commit is contained in:
parent
6c7e722390
commit
59de87799e
2 changed files with 3 additions and 2 deletions
|
@ -1,4 +1,3 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
wakatime-cli
|
wakatime-cli
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from .packages import simplejson as json
|
from .packages import simplejson as json
|
||||||
try:
|
try:
|
||||||
|
@ -28,7 +29,8 @@ class CustomEncoder(json.JSONEncoder):
|
||||||
try:
|
try:
|
||||||
encoded = super(CustomEncoder, self).default(obj)
|
encoded = super(CustomEncoder, self).default(obj)
|
||||||
except UnicodeDecodeError:
|
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)
|
encoded = super(CustomEncoder, self).default(obj)
|
||||||
return encoded
|
return encoded
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue