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
This commit is contained in:
1 parent
7f80c2faae
commit
915eeae9af
2 files changed
+6
-8
No files matched your search
@@ -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()
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user