mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
ovs.db.types: Simplify code to avoid try/except case.
Also fixes a typo that caused one version of the error message to have a hyphen and the other to have a space. Suggested-by: Reid Price <reid@nicira.com>
This commit is contained in:
@@ -30,16 +30,14 @@ class AtomicType(object):
|
|||||||
for atomic_type in ATOMIC_TYPES:
|
for atomic_type in ATOMIC_TYPES:
|
||||||
if s == atomic_type.name:
|
if s == atomic_type.name:
|
||||||
return atomic_type
|
return atomic_type
|
||||||
raise error.Error('"%s" is not an atomic type' % s)
|
raise error.Error('"%s" is not an atomic-type' % s, s)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_json(json):
|
def from_json(json):
|
||||||
if type(json) not in [str, unicode]:
|
if type(json) not in [str, unicode]:
|
||||||
raise error.Error("atomic-type expected", json)
|
raise error.Error("atomic-type expected", json)
|
||||||
try:
|
else:
|
||||||
return AtomicType.from_string(json)
|
return AtomicType.from_string(json)
|
||||||
except error.Error:
|
|
||||||
raise error.Error('"%s" is not an atomic-type' % json, json)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
Reference in New Issue
Block a user