Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-12-20 06:58:53 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-12-20 07:01:05 +0300
commitf0e3ea24be216bd98e8f2b75d722565a68461fb8 (patch)
tree800c3b313fb818b3b88bef26ee0e6aeab0529c2f /io_scene_fbx
parentdba7a10556f31bed867b463f0448d7b378dcef8b (diff)
Fix T72413: FBX import error on missing files
While it's an error case, the ascii detection caused the missing file case to raise a full exception before running code which handles this case more gracefully.
Diffstat (limited to 'io_scene_fbx')
-rw-r--r--io_scene_fbx/import_fbx.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 751a2b17..32b887c1 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -2307,17 +2307,6 @@ class FbxImportHelperNode:
return None
-def is_ascii(filepath, size):
- with open(filepath, 'r', encoding="utf-8") as f:
- try:
- f.read(size)
- return True
- except UnicodeDecodeError:
- pass
-
- return False
-
-
def load(operator, context, filepath="",
use_manual_orientation=False,
axis_forward='-Z',
@@ -2358,10 +2347,24 @@ def load(operator, context, filepath="",
perfmon.step("FBX Import: start importing %s" % filepath)
perfmon.level_up()
- # detect ascii files
- if is_ascii(filepath, 24):
+ # Detect ASCII files.
+
+ # Typically it's bad practice to fail silently on any error,
+ # however the file may fail to read for many reasons,
+ # and this situation is handled later in the code,
+ # right now we only want to know if the file successfully reads as ascii.
+ try:
+ with open(filepath, 'r', encoding="utf-8") as fh:
+ fh.read(24)
+ is_ascii = True
+ except Exception:
+ is_ascii = False
+
+ if is_ascii:
operator.report({'ERROR'}, "ASCII FBX files are not supported %r" % filepath)
return {'CANCELLED'}
+ del is_ascii
+ # End ascii detection.
try:
elem_root, version = parse_fbx.parse(filepath)