Skip to content

Commit

Permalink
fix raising FileNotFound when reading with plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
megies committed Feb 2, 2018
1 parent 3321d1f commit a3934fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 0 additions & 10 deletions obspy/core/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
unicode_literals)
from future.builtins import * # NOQA
from future.utils import python_2_unicode_compatible, native_str
from future.utils import PY2

import builtins
import copy
import fnmatch
import os
Expand All @@ -39,10 +37,6 @@
SOFTWARE_URI = "https://www.obspy.org"


if PY2:
FileNotFoundError = getattr(builtins, 'IOError')


def _create_example_inventory():
"""
Create an example inventory.
Expand Down Expand Up @@ -100,10 +94,6 @@ def read_inventory(path_or_file_object=None, format=None, *args, **kwargs):
with NamedTemporaryFile(suffix=sanitize_filename(suffix)) as fh:
download_to_file(url=path_or_file_object, filename_or_buffer=fh)
return read_inventory(fh.name, format=format)
if not os.path.exists(path_or_file_object):
msg = "[Errno 2] No such file or directory: '{}'".format(
path_or_file_object)
raise FileNotFoundError(msg)
return _read_from_plugin("inventory", path_or_file_object,
format=format, *args, **kwargs)[0]

Expand Down
11 changes: 11 additions & 0 deletions obspy/core/util/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from future.builtins import * # NOQA
from future.utils import PY2

import builtins
import doctest
import inspect
import io
Expand Down Expand Up @@ -357,10 +359,19 @@ def get_dependency_version(package_name, raw_string=False):
CARTOPY_VERSION = get_dependency_version('cartopy')


if PY2:
FileNotFoundError = getattr(builtins, 'IOError')


def _read_from_plugin(plugin_type, filename, format=None, **kwargs):
"""
Reads a single file from a plug-in's readFormat function.
"""
if isinstance(filename, (str, native_str)):
if not os.path.exists(filename):
msg = "[Errno 2] No such file or directory: '{}'".format(
filename)
raise FileNotFoundError(msg)
eps = ENTRY_POINTS[plugin_type]
# get format entry point
format_ep = None
Expand Down

0 comments on commit a3934fa

Please sign in to comment.