Skip to content

Commit

Permalink
fix: ipc encoding on Windows for import paths encoded as cp1252
Browse files Browse the repository at this point in the history
  • Loading branch information
kratico committed Jan 9, 2019
1 parent 1192b29 commit b9cf774
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mapillary_tools/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from tqdm import tqdm
from . import ipc
from .error import print_error
from .utils import force_decode

STATUS_PAIRS = {"success": "failed",
"failed": "success"
Expand Down Expand Up @@ -823,9 +824,11 @@ def create_and_log_process(image, process, status, mapillary_description={}, ver
process))
os.remove(log_MAPJson)

decoded_image = force_decode(image)

ipc.send(
process,
{ 'image': image, 'status': status, 'description': mapillary_description })
{ 'image': decoded_image, 'status': status, 'description': mapillary_description })


def user_properties(user_name,
Expand Down
5 changes: 4 additions & 1 deletion mapillary_tools/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import processing
from . import ipc
from .error import print_error
from .utils import force_decode

if os.getenv("AWS_S3_ENDPOINT", None) is None:
MAPILLARY_UPLOAD_URL = "https://d22zcsn13kp53w.cloudfront.net/"
Expand Down Expand Up @@ -723,10 +724,12 @@ def create_upload_log(filepath, status):
if os.path.isfile(upload_opposite_log_filepath):
os.remove(upload_opposite_log_filepath)

decoded_filepath = force_decode(filepath)

ipc.send(
'upload',
{
'image': filepath,
'image': decoded_filepath,
'status': 'success' if status == 'upload_success' else 'failed',
})

Expand Down
8 changes: 8 additions & 0 deletions mapillary_tools/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def force_decode(string, codecs=['utf8', 'cp1252']):
for i in codecs:
try:
return string.decode(i)
except UnicodeDecodeError:
pass
print('cannot decode string: %s' % (string))
return string.decode('utf8', errors='replace')

1 comment on commit b9cf774

@velmyshanovnyi
Copy link

@velmyshanovnyi velmyshanovnyi commented on b9cf774 Mar 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLS add cp1251 (Cirylic)

encoding on Windows for import paths encoded as cp1251

def force_decode(string, codecs=['utf8', 'cp1251']):

Please sign in to comment.