Exemplo n.º 1
0
 def test_from_numberstring_parser_no_implicit_octal(self):
     from rpython.rlib.rstring import NumberStringParser, ParseStringError
     s = "077777777777777777777777777777"
     parser = NumberStringParser(s, s, 0, "long", no_implicit_octal=True)
     with pytest.raises(ParseStringError):
         rbigint._from_numberstring_parser(parser)
     parser = NumberStringParser("000",
                                 "000",
                                 0,
                                 "long",
                                 no_implicit_octal=True)
     assert rbigint._from_numberstring_parser(parser).tolong() == 0
Exemplo n.º 2
0
def _retry_to_w_long(space, parser, w_source):
    parser.rewind()
    try:
        bigint = rbigint._from_numberstring_parser(parser)
    except ParseStringError as e:
        raise wrap_parsestringerror(space, e, w_source)
    return space.newlong_from_rbigint(bigint)
Exemplo n.º 3
0
def _retry_to_w_long(space, parser, w_source):
    parser.rewind()
    try:
        bigint = rbigint._from_numberstring_parser(parser)
    except ParseStringError as e:
        raise wrap_parsestringerror(space, e, w_source)
    return space.newlong_from_rbigint(bigint)
Exemplo n.º 4
0
def retry_to_w_long(space, parser):
    parser.rewind()
    try:
        bigint = rbigint._from_numberstring_parser(parser)
    except ParseStringError, e:
        raise OperationError(space.w_ValueError,
                             space.wrap(e.msg))
Exemplo n.º 5
0
def _retry_to_w_long(space, parser, w_inttype, w_source):
    from pypy.objspace.std.longobject import newbigint
    parser.rewind()
    try:
        bigint = rbigint._from_numberstring_parser(parser)
    except ParseStringError as e:
        raise wrap_parsestringerror(space, e, w_source)
    return newbigint(space, w_inttype, bigint)
Exemplo n.º 6
0
def parse_integer(string, base=10):
    if base > 36:
        raise ValueError("Not enough digits to base")
    if base < 0:
        raise ValueError("Negative base")
    literal = string
    parser = NumberStringParser(string, literal, base, 'long')
    return Integer(rbigint._from_numberstring_parser(parser))
Exemplo n.º 7
0
def _retry_to_w_long(space, parser, w_inttype, w_source):
    from pypy.objspace.std.longobject import newbigint

    parser.rewind()
    try:
        bigint = rbigint._from_numberstring_parser(parser)
    except ParseStringError as e:
        raise wrap_parsestringerror(space, e, w_source)
    return newbigint(space, w_inttype, bigint)
Exemplo n.º 8
0
 def test_from_numberstring_parser(self):
     from rpython.rlib.rstring import NumberStringParser
     parser = NumberStringParser("1231231241", "1231231241", 10, "long")
     assert rbigint._from_numberstring_parser(parser).tolong() == 1231231241
Exemplo n.º 9
0
def retry_to_w_long(space, parser):
    parser.rewind()
    try:
        bigint = rbigint._from_numberstring_parser(parser)
    except ParseStringError, e:
        raise OperationError(space.w_ValueError, space.wrap(e.msg))