Skip to content

Commit

Permalink
Adding an AttributePolicy system
Browse files Browse the repository at this point in the history
This change adds a policy system that will be used by the KmipEngine to
track and organize rules for individual KMIP attributes. Comparison
operators for the Integer primitive and ProtocolVersion struct are added
to support the AttributePolicy. Tests for all new changes are included.
  • Loading branch information
PeterHamilton committed Mar 21, 2016
1 parent 9e074da commit 07a63c0
Show file tree
Hide file tree
Showing 6 changed files with 1,568 additions and 2 deletions.
52 changes: 52 additions & 0 deletions kmip/core/messages/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,58 @@ def __ne__(self, other):
else:
return NotImplemented

def __lt__(self, other):
if isinstance(other, ProtocolVersion):
if self.protocol_version_major < other.protocol_version_major:
return True
elif self.protocol_version_major > other.protocol_version_major:
return False
elif self.protocol_version_minor < other.protocol_version_minor:
return True
else:
return False
else:
return NotImplemented

def __gt__(self, other):
if isinstance(other, ProtocolVersion):
if self.protocol_version_major > other.protocol_version_major:
return True
elif self.protocol_version_major < other.protocol_version_major:
return False
elif self.protocol_version_minor > other.protocol_version_minor:
return True
else:
return False
else:
return NotImplemented

def __le__(self, other):
if isinstance(other, ProtocolVersion):
if self.protocol_version_major < other.protocol_version_major:
return True
elif self.protocol_version_major > other.protocol_version_major:
return False
elif self.protocol_version_minor <= other.protocol_version_minor:
return True
else:
return False
else:
return NotImplemented

def __ge__(self, other):
if isinstance(other, ProtocolVersion):
if self.protocol_version_major > other.protocol_version_major:
return True
elif self.protocol_version_major < other.protocol_version_major:
return False
elif self.protocol_version_minor >= other.protocol_version_minor:
return True
else:
return False
else:
return NotImplemented

def __repr__(self):
major = self.protocol_version_major.value
minor = self.protocol_version_minor.value
Expand Down
28 changes: 26 additions & 2 deletions kmip/core/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ def validate(self):
raise ValueError('integer value less than accepted min')

def __repr__(self):
return "{0}(value={1})".format(type(self).__name__, repr(self.value))
return "{0}(value={1})".format(type(self).__name__, self.value)

def __str__(self):
return "{0}".format(repr(self.value))
return str(self.value)

def __eq__(self, other):
if isinstance(other, Integer):
Expand All @@ -248,6 +248,30 @@ def __ne__(self, other):
else:
return NotImplemented

def __lt__(self, other):
if isinstance(other, Integer):
return self.value < other.value
else:
return NotImplemented

def __gt__(self, other):
if isinstance(other, Integer):
return self.value > other.value
else:
return NotImplemented

def __le__(self, other):
if isinstance(other, Integer):
return self.__eq__(other) or self.__lt__(other)
else:
return NotImplemented

def __ge__(self, other):
if isinstance(other, Integer):
return self.__eq__(other) or self.__gt__(other)
else:
return NotImplemented


class LongInteger(Base):
"""
Expand Down
Loading

0 comments on commit 07a63c0

Please sign in to comment.