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

View File

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

View File

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