Adding support for the six library

This change adds support for the six library, specifically for handling
portions of the code that are sensitive to differences between Python
2.* and 3.*.
This commit is contained in:
Peter Hamilton 2014-11-18 15:19:56 -05:00
parent ee52df639a
commit 34962e36af
3 changed files with 16 additions and 20 deletions

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six
import sys import sys
from struct import pack, unpack from struct import pack, unpack
@ -258,21 +259,14 @@ class LongInteger(Base):
def __validate(self): def __validate(self):
if self.value is not None: if self.value is not None:
data_type = type(self.value) data_type = type(self.value)
if sys.version < '3': if data_type not in six.integer_types:
valid_data_types = (int, long) raise errors.StateTypeError(
error_msg = '{0} or {1}'.format(int, long) LongInteger.__name__, "{0}".format(six.integer_types),
else: data_type)
valid_data_types = (int,)
error_msg = '{0}'.format(int)
if data_type not in valid_data_types:
raise errors.StateTypeError(LongInteger.__name__,
error_msg,
data_type)
num_bytes = utils.count_bytes(self.value) num_bytes = utils.count_bytes(self.value)
if num_bytes > self.length: if num_bytes > self.length:
raise errors.StateOverflowError(LongInteger.__name__, raise errors.StateOverflowError(
'value', self.length, LongInteger.__name__, 'value', self.length, num_bytes)
num_bytes)
def __repr__(self): def __repr__(self):
return '<Long Integer, %d>' % (self.value) return '<Long Integer, %d>' % (self.value)
@ -369,15 +363,15 @@ class BigInteger(Base):
def __validate(self): def __validate(self):
if self.value is not None: if self.value is not None:
data_type = type(self.value) data_type = type(self.value)
if data_type not in (int, long): if data_type not in six.integer_types:
raise errors.StateTypeError(BigInteger.__name__, raise errors.StateTypeError(
'{0} or {1}'.format(int, long), BigInteger.__name__, "{0}".format(six.integer_types),
data_type) data_type)
num_bytes = utils.count_bytes(self.length) num_bytes = utils.count_bytes(self.length)
if num_bytes > self.LENGTH_SIZE: if num_bytes > self.LENGTH_SIZE:
raise errors.StateOverflowError(BigInteger.__name__, raise errors.StateOverflowError(
'length', self.LENGTH_SIZE, BigInteger.__name__, 'length', self.LENGTH_SIZE,
num_bytes) num_bytes)
class Enumeration(Integer): class Enumeration(Integer):

View File

@ -1,3 +1,4 @@
enum34 enum34
sqlalchemy sqlalchemy
six

View File

@ -28,6 +28,7 @@ setuptools.setup(
package_data={'kmip': ['logconfig.ini']}, package_data={'kmip': ['logconfig.ini']},
install_requires=[ install_requires=[
"enum34", "enum34",
"six",
"sqlalchemy", "sqlalchemy",
], ],
classifiers=[ classifiers=[