From: Ben Pfaff Date: Tue, 23 Aug 2011 17:06:04 +0000 (-0700) Subject: ovs.db.types: Introduce DEFAULT_MIN, DEFAULT_MAX as Type class members. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71607f575e8eac278b61774faa81fc47b7f8c00b;p=openvswitch ovs.db.types: Introduce DEFAULT_MIN, DEFAULT_MAX as Type class members. Suggested-by: Reid Price --- diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py index 5f50d65e..00b9ab40 100644 --- a/python/ovs/db/types.py +++ b/python/ovs/db/types.py @@ -365,7 +365,10 @@ class BaseType(object): return '\n'.join([indent + stmt for stmt in stmts]) class Type(object): - def __init__(self, key, value=None, n_min=1, n_max=1): + DEFAULT_MIN = 1 + DEFAULT_MAX = 1 + + def __init__(self, key, value=None, n_min=DEFAULT_MIN, n_max=DEFAULT_MAX): self.key = key self.value = value self.n_min = n_min @@ -442,12 +445,12 @@ class Type(object): else: value = None - n_min = Type.__n_from_json(min_json, 1) + n_min = Type.__n_from_json(min_json, Type.DEFAULT_MIN) if max_json == 'unlimited': n_max = sys.maxint else: - n_max = Type.__n_from_json(max_json, 1) + n_max = Type.__n_from_json(max_json, Type.DEFAULT_MAX) type_ = Type(key, value, n_min, n_max) if not type_.is_valid(): @@ -461,11 +464,11 @@ class Type(object): json = {"key": self.key.to_json()} if self.value is not None: json["value"] = self.value.to_json() - if self.n_min != 1: + if self.n_min != Type.DEFAULT_MIN: json["min"] = self.n_min if self.n_max == sys.maxint: json["max"] = "unlimited" - elif self.n_max != 1: + elif self.n_max != Type.DEFAULT_MAX: json["max"] = self.n_max return json