Esempio n. 1
0
 def __rmul__(self, other):
     value = super(newint, self).__rmul__(other)
     if isint(value):
         return newint(value)
     elif value is NotImplemented:
         return other * long(self)
     return value
Esempio n. 2
0
 def __rmul__(self, other):
     value = super(newint, self).__rmul__(other)
     if isint(value):
         return newint(value)
     elif value is NotImplemented:
         return other * long(self)
     return value
Esempio n. 3
0
 def __mul__(self, other):
     value = super(newint, self).__mul__(other)
     if isint(value):
         return newint(value)
     if value is NotImplemented:
         return long(self) * other
     return value
Esempio n. 4
0
 def __mul__(self, other):
     value = super(newint, self).__mul__(other)
     if isint(value):
         return newint(value)
     elif value is NotImplemented:
         return int(self) * other
     return value
Esempio n. 5
0
 def __xor__(self, other):
     if not isint(other):
         raise TypeError(
             "unsupported operand type(s) for ^: '%s' and '%s'"
             % (type(self).__name__, type(other).__name__)
         )
     return newint(super(newint, self).__xor__(other))
    def __new__(cls, x=0, base=10):
        """
        From the Py3 int docstring:

        |  int(x=0) -> integer
        |  int(x, base=10) -> integer
        |  
        |  Convert a number or string to an integer, or return 0 if no arguments
        |  are given.  If x is a number, return x.__int__().  For floating point
        |  numbers, this truncates towards zero.
        |  
        |  If x is not a number or if base is given, then x must be a string,
        |  bytes, or bytearray instance representing an integer literal in the
        |  given base.  The literal can be preceded by '+' or '-' and be surrounded
        |  by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
        |  Base 0 means to interpret the base from the string as an integer literal.
        |  >>> int('0b100', base=0)
        |  4

        """
        try:
            val = x.__int__()
        except AttributeError:
            val = x
        else:
            if not isint(val):
                raise TypeError('__int__ returned non-int ({0})'.format(
                    type(val)))

        if base != 10:
            # Explicit base
            if not (istext(val) or isbytes(val) or isinstance(val, bytearray)):
                raise TypeError(
                    "int() can't convert non-string with explicit base")
            try:
                return super(newint, cls).__new__(cls, val, base)
            except TypeError:
                return super(newint, cls).__new__(cls, newbytes(val), base)
        # After here, base is 10
        try:
            return super(newint, cls).__new__(cls, val)
        except TypeError:
            # Py2 long doesn't handle bytearray input with an explicit base, so
            # handle this here.
            # Py3: int(bytearray(b'10'), 2) == 2
            # Py2: int(bytearray(b'10'), 2) == 2 raises TypeError
            # Py2: long(bytearray(b'10'), 2) == 2 raises TypeError
            try:
                return super(newint, cls).__new__(cls, newbytes(val))
            except:
                raise TypeError(
                    "newint argument must be a string or a number, not '{0}'".
                    format(type(val)))
Esempio n. 7
0
    def __new__(cls, x=0, base=10):
        """
        From the Py3 int docstring:

        |  int(x=0) -> integer
        |  int(x, base=10) -> integer
        |
        |  Convert a number or string to an integer, or return 0 if no
        |  arguments are given.  If x is a number, return x.__int__().  For
        |  floating point numbers, this truncates towards zero.
        |
        |  If x is not a number or if base is given, then x must be a string,
        |  bytes, or bytearray instance representing an integer literal in the
        |  given base.  The literal can be preceded by '+' or '-' and be
        |  surrounded by whitespace.  The base defaults to 10.  Valid bases are
        |  0 and 2-36. Base 0 means to interpret the base from the string as an
        |  integer literal.
        |  >>> int('0b100', base=0)
        |  4

        """
        try:
            val = x.__int__()
        except AttributeError:
            val = x
        else:
            if not isint(val):
                raise TypeError('__int__ returned non-int ({0})'.format(
                    type(val)))

        if base != 10:
            # Explicit base
            if not (istext(val) or isbytes(val) or isinstance(val, bytearray)):
                raise TypeError(
                    "int() can't convert non-string with explicit base")
            try:
                return super(newint, cls).__new__(cls, val, base)
            except TypeError:
                return super(newint, cls).__new__(cls, newbytes(val), base)
        # After here, base is 10
        try:
            return super(newint, cls).__new__(cls, val)
        except TypeError:
            # Py2 long doesn't handle bytearray input with an explicit base, so
            # handle this here.
            # Py3: int(bytearray(b'10'), 2) == 2
            # Py2: int(bytearray(b'10'), 2) == 2 raises TypeError
            # Py2: long(bytearray(b'10'), 2) == 2 raises TypeError
            try:
                return super(newint, cls).__new__(cls, newbytes(val))
            except:
                raise TypeError("newint argument must be a string or a number,"
                                "not '{0}'".format(type(val)))
 def __rmul__(self, other):
     value = super(newint, self).__rmul__(other)
     if isint(value):
         return newint(value)
     return value
Esempio n. 9
0
 def __xor__(self, other):
     if not isint(other):
         raise TypeError(
             "unsupported operand type(s) for ^: '%s' and '%s'" %
             (type(self).__name__, type(other).__name__))
     return newint(super(newint, self).__xor__(other))
Esempio n. 10
0
 def __rmul__(self, other):
     value = super(newint, self).__rmul__(other)
     if isint(value):
         return newint(value)
     return value
Esempio n. 11
0
from future.utils import isint
data = ["02-sep-2016, blah blah, blah, 83838338",2, 4,6,1,2,"02-sep-2016, blah blah, blah, 83838338",3,0,0,"03-Aug-2000, blah, 300033","03-Aug-2000, blah, 300033"]

vals=[]
final_data = "%d,%s"
formatted_rec = []
for each_val in data:
    
    if not isint(each_val) and "-" in each_val:
        if vals:
            max_digit = max(vals)
        else:
            max_digit = 0
        vals=[]
        formatted_rec.append(final_data %(max_digit, each_val))
    else:
        vals.append(each_val)
        
for each_rec in formatted_rec:
    print each_rec    
Esempio n. 12
0
 def test_validate_int_from_bytes(self):
     ret = util.validate_int(b'100')
     self.assertTrue(isint(ret))
Esempio n. 13
0
 def test_validate_int(self):
     ret = util.validate_int(100)
     self.assertTrue(isint(ret))
Esempio n. 14
0
 def test_validate_int_from_bytes(self):
     ret = util.validate_int(b'100')
     self.assertTrue(isint(ret))
Esempio n. 15
0
 def test_validate_int(self):
     ret = util.validate_int(100)
     self.assertTrue(isint(ret))