Skip to content

Commit

Permalink
refactor raising UnsupportedVersionError
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Apr 29, 2020
1 parent e2ef4eb commit 69c969d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
13 changes: 5 additions & 8 deletions mds/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ def get(self, record_type, provider=None, **kwargs):
The non-empty payloads (e.g. payloads with data records), one for each requested page.
"""
version = Version(kwargs.pop("version", self.version))
if version.unsupported:
raise UnsupportedVersionError(version)
version.raise_if_unsupported()

if version < _V040_:
if record_type not in [STATUS_CHANGES, TRIPS]:
Expand Down Expand Up @@ -225,8 +224,7 @@ def get_status_changes(self, provider=None, **kwargs):
The non-empty payloads (e.g. payloads with data records), one for each requested page.
"""
version = Version(kwargs.get("version", self.version))
if version.unsupported:
raise UnsupportedVersionError(version)
version.raise_if_unsupported()

Client._params_check(STATUS_CHANGES, version, **kwargs)

Expand Down Expand Up @@ -285,8 +283,7 @@ def get_trips(self, provider=None, **kwargs):
The non-empty payloads (e.g. payloads with data records), one for each requested page.
"""
version = Version(kwargs.get("version", self.version))
if version.unsupported:
raise UnsupportedVersionError(version)
version.raise_if_unsupported()

Client._params_check(TRIPS, version, **kwargs)

Expand Down Expand Up @@ -321,8 +318,8 @@ def get_events(self, provider=None, **kwargs):
The non-empty payloads (e.g. payloads with data records), one for each requested page.
"""
version = Version(kwargs.get("version", self.version))
if version.unsupported:
raise UnsupportedVersionError(version)
version.raise_if_unsupported()

if version < _V040_:
print("The events endpoint is only supported in MDS Version 0.4.0 and beyond.")
raise UnsupportedVersionError(version)
Expand Down
3 changes: 1 addition & 2 deletions mds/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ def load(self, source, record_type, table, **kwargs):
self
"""
version = Version(kwargs.pop("version", self.version))
if version.unsupported:
raise UnsupportedVersionError(version)
version.raise_if_unsupported()

if "stage_first" not in kwargs:
kwargs["stage_first"] = self.stage_first
Expand Down
3 changes: 1 addition & 2 deletions mds/db/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def load(self, source, **kwargs):
engine = kwargs.pop("engine")

version = Version(kwargs.get("version", Version.mds_lower()))
if version.unsupported:
raise UnsupportedVersionError(version)
version.raise_if_unsupported()

before_load = kwargs.get("before_load")
stage_first = kwargs.get("stage_first")
Expand Down
6 changes: 2 additions & 4 deletions mds/db/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def insert_status_changes_from(source_table, dest_table=STATUS_CHANGES, **kwargs
str
"""
version = Version(kwargs.pop("version", Version.mds_lower()))
if version.unsupported:
raise UnsupportedVersionError(version)
version.raise_if_unsupported()

on_conflict_update = kwargs.pop("on_conflict_update", None)
on_conflict = on_conflict_statement(on_conflict_update)
Expand Down Expand Up @@ -134,8 +133,7 @@ def insert_trips_from(source_table, dest_table=TRIPS, **kwargs):
str
"""
version = Version(kwargs.pop("version", Version.mds_lower()))
if version.unsupported:
raise UnsupportedVersionError(version)
version.raise_if_unsupported()

on_conflict_update = kwargs.pop("on_conflict_update", None)
on_conflict = on_conflict_statement(on_conflict_update)
Expand Down
7 changes: 7 additions & 0 deletions mds/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def tuple(self):
else:
return self._version.release

def raise_if_unsupported(self):
"""
Raise an UnsupportedVersionError if this Version is not currently supported.
"""
if self.unsupported:
raise UnsupportedVersionError(self)

def __eq__(self, version2):
return self._version.__eq__(version2._version)

Expand Down

0 comments on commit 69c969d

Please sign in to comment.