mirror of
				https://github.com/OpenKMIP/PyKMIP.git
				synced 2025-11-03 21:16:30 +01:00 
			
		
		
		
	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:
		
							parent
							
								
									ee52df639a
								
							
						
					
					
						commit
						34962e36af
					
				@ -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):
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,4 @@
 | 
				
			|||||||
enum34
 | 
					enum34
 | 
				
			||||||
sqlalchemy
 | 
					sqlalchemy
 | 
				
			||||||
 | 
					six
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user