# check archive format
basename, ext = os.path.splitext(filename)
ext = ext.lower()
- if ext in ['.nar', '.zip']:
+ if ext in [b'.nar', b'.zip']:
pass
else:
fatal('unknown archive format')
if filename is None:
shutil.rmtree(tmpdir)
fatal('cannot download the archive file')
+ else:
+ filename = os.fsencode(filename)
+ self.check_archive(filename)
try:
- with zipfile.ZipFile(filename) as zf:
+ with zipfile.ZipFile(os.fsdecode(filename)) as zf: # XXX
for name in zf.namelist():
path = os.path.join(os.fsencode(tmpdir), os.fsencode(name))
dname, fname = os.path.split(path)
return filetype
def install(self, filename, homedir):
- self.check_archive(filename)
homedir = os.fsencode(homedir) # XXX
tmpdir = self.extract_files(filename)
filetype = self.get_file_type(tmpdir)
if not os.path.exists(arcdir):
os.makedirs(arcdir)
basedir = arcdir
- filename = os.path.join(basedir, os.path.basename(url))
+ filename = os.path.join(basedir, os.fsencode(os.path.basename(url)))
try:
with open(filename, 'wb') as ofile:
while 1:
# check the format of the downloaded file
self.check_archive(filename) ## FIXME
try:
- zf = zipfile.ZipFile(filename)
+ zf = zipfile.ZipFile(os.fsdecode(filename)) # XXX
except:
return None
test_zip = zf.testzip()
def open_file_chooser(self):
response = self.file_chooser.run()
if response == Gtk.ResponseType.OK:
- filename = self.file_chooser.get_filename()
+ filename = self.file_chooser.get_filename() # XXX: don't use os.fsencode() here
self.app.do_install(filename)
self.update()
elif response == Gtk.ResponseType.CANCEL:
urllib.parse.urlparse(uri)
pathname = urllib.request.url2pathname(path)
if scheme == 'file' and os.path.exists(pathname):
- filelist.append(pathname)
+ filelist.append(pathname) # XXX: don't use os.fsencode() here
+ elif scheme == 'http' or scheme == 'ftp':
+ filelist.append(uri)
if filelist:
- filelist = [os.fsencode(filename) for filename in filelist]
for filename in filelist:
self.app.do_install(filename)
self.update()
- return True
class UsageDialog: