Fix make event upload more stable with regard to quoting issues

This commit is contained in:
allegroai 2020-11-29 23:28:54 +02:00
parent cc894dc1d6
commit 89f5e78a93

View File

@ -1,6 +1,7 @@
import abc import abc
import hashlib import hashlib
import time import time
from functools import reduce
from logging import getLevelName from logging import getLevelName
from multiprocessing import Lock from multiprocessing import Lock
@ -207,10 +208,8 @@ class UploadEvent(MetricsEventAdapter):
# replace the three quote symbols we cannot have, # replace the three quote symbols we cannot have,
# notice % will be converted to %25 when the link is quoted, so we should not use it # notice % will be converted to %25 when the link is quoted, so we should not use it
# Replace quote safe characters: ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," # Replace quote safe characters: ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ","
return part.replace('\\', '/').strip('/').replace('/', '.slash.').replace('?', '0x3f').\ return reduce(lambda a, b: a.replace(b, "0x{:02x}".format(ord(b))), "#\"\';?:@&=+$,%!",
replace('#', '0x23').replace('"', '0x22').replace(';', '0x3b').replace(':', '0x3a').\ part.replace('\\', '/').strip('/').replace('/', '.slash.'))
replace('@', '0x40').replace('&', '0x26').replace('=', '0x3d').replace('+', '0x2b').\
replace('$', '0x24').replace(',', '0x2c')
def __init__(self, metric, variant, image_data, local_image_path=None, iter=0, upload_uri=None, def __init__(self, metric, variant, image_data, local_image_path=None, iter=0, upload_uri=None,
file_history_size=None, delete_after_upload=False, **kwargs): file_history_size=None, delete_after_upload=False, **kwargs):