Less indentation

main
Bob Mottram 2022-08-19 17:00:33 +01:00
parent 04e64c7ef7
commit ced75a7b3d
1 changed files with 22 additions and 21 deletions

View File

@ -201,28 +201,29 @@ def cache_svg_images(session, base_dir: str, http_prefix: str,
image_data = fp_svg.read() image_data = fp_svg.read()
except OSError: except OSError:
print('EX: unable to read svg file data') print('EX: unable to read svg file data')
if image_data: if not image_data:
image_data = image_data.decode() continue
cleaned_up = \ image_data = image_data.decode()
remove_script(image_data, log_filename, actor, url) cleaned_up = \
if cleaned_up != image_data: remove_script(image_data, log_filename, actor, url)
# write the cleaned up svg image if cleaned_up != image_data:
svg_written = False # write the cleaned up svg image
cleaned_up = cleaned_up.encode('utf-8') svg_written = False
try: cleaned_up = cleaned_up.encode('utf-8')
with open(image_filename, 'wb') as im_file: try:
im_file.write(cleaned_up) with open(image_filename, 'wb') as im_file:
svg_written = True im_file.write(cleaned_up)
except OSError: svg_written = True
print('EX: unable to write cleaned up svg ' + url) except OSError:
if svg_written: print('EX: unable to write cleaned up svg ' + url)
# change the url to be the local version if svg_written:
obj['attachment'][index]['url'] = \ # change the url to be the local version
http_prefix + '://' + domain_full + '/media/' + \ obj['attachment'][index]['url'] = \
post_id + '_' + filename http_prefix + '://' + domain_full + '/media/' + \
cached = True post_id + '_' + filename
else:
cached = True cached = True
else:
cached = True
return cached return cached