From 915eeae9afe0cbbf7ce767fb6602c62535a3593a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 31 Aug 2018 14:49:59 +0200 Subject: [PATCH] Use get_uris on SelectionData and remove encoding into file system SelectionData does not have data attribute with the introspection. And the uris are str which does not require to be encoded in Python3. issue7649 review66351002 --- tryton/gui/window/attachment.py | 12 +++++------- tryton/gui/window/form.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tryton/gui/window/attachment.py b/tryton/gui/window/attachment.py index b570bd9cb2..291cf926b2 100644 --- a/tryton/gui/window/attachment.py +++ b/tryton/gui/window/attachment.py @@ -2,9 +2,8 @@ # this repository contains the full copyright notices and license terms. "Attachment" import os -import urllib.request -import urllib.parse -import sys +from urllib.request import urlopen +from urllib.parse import urlparse, unquote import gettext from tryton.gui.window.view_form.screen import Screen @@ -42,9 +41,8 @@ class Attachment(WinForm): data_field = self.screen.group.fields['data'] name_field = self.screen.group.fields[data_field.attrs['filename']] new_record = self.screen.new() - file_name = os.path.basename(urllib.parse.urlparse(uri).path) + uri = unquote(uri) + file_name = os.path.basename(urlparse(uri).path) name_field.set_client(new_record, file_name) - uri = urllib.parse.unquote(uri) - uri = uri.decode('utf-8').encode(sys.getfilesystemencoding()) - data_field.set_client(new_record, urllib.request.urlopen(uri).read()) + data_field.set_client(new_record, urlopen(uri).read()) self.screen.display() diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index 0718bd4354..ffcee1feb9 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -680,7 +680,7 @@ class Form(SignalEvent, TabContent): win_attach = Attachment(record, lambda: self.update_attachment_count(reload=True)) if info == 0: - for uri in selection.data.splitlines(): + for uri in selection.get_uris(): # Win32 cut&paste terminates the list with a NULL character if not uri or uri == '\0': continue