Example #1
0
def test_oounicode():
    u = ootype.oounicode(u'a', -1)
    assert isinstance(u, ootype._string)
    assert ootype.typeOf(u) is ootype.Unicode

    s = ootype.make_string('a string')
    u = ootype.oounicode(s, -1)
    assert isinstance(u, ootype._string)
    assert ootype.typeOf(u) is ootype.Unicode

    s = ootype.make_string('non-ascii string: \xe0')
    py.test.raises(UnicodeDecodeError, ootype.oounicode, s, -1)
Example #2
0
def test_oounicode():
    u = ootype.oounicode(u'a', -1)
    assert isinstance(u, ootype._string)
    assert ootype.typeOf(u) is ootype.Unicode

    s = ootype.make_string('a string')
    u = ootype.oounicode(s, -1)
    assert isinstance(u, ootype._string)
    assert ootype.typeOf(u) is ootype.Unicode

    s = ootype.make_string('non-ascii string: \xe0')
    py.test.raises(UnicodeDecodeError, ootype.oounicode, s, -1)
Example #3
0
 def make_string(self, value):
     return ootype.make_string(value)
Example #4
0
 def ll_constant(s):
     return ootype.make_string(s)
Example #5
0
 def oostr(s):
     if strtype is str:
         return ootype.make_string(s)
     else:
         return ootype.make_unicode(s)
Example #6
0
 def make_string(self, value):
     return ootype.make_string(value)
Example #7
0
 def ll_constant(s):
     return ootype.make_string(s)
Example #8
0
 def oostr(s):
     if strtype is str:
         return ootype.make_string(s)
     else:
         return ootype.make_unicode(s)
Example #9
0
def test_string_builder():
    b = ootype.new(ootype.StringBuilder)
    b.ll_append_char('a')
    b.ll_append(ootype.make_string('bcd'))
    res = b.ll_build()
    assert res._str == 'abcd'
Example #10
0
 def test_hlstr(self):
     s = ootype.make_string("abc")
     assert hlstr(s) == "abc"
Example #11
0
import sys
from pypy.rpython.ootypesystem.ootype import new, oostring, StringBuilder
from pypy.rpython.ootypesystem.ootype import make_string

def ll_int_str(repr, i):
    return ll_int2dec(i)

def ll_int2dec(i):
    return oostring(i, 10)

SPECIAL_VALUE     = -sys.maxint-1
SPECIAL_VALUE_HEX = make_string(
    '-' + hex(sys.maxint+1).replace('L', '').replace('l', ''))
SPECIAL_VALUE_OCT = make_string(
    '-' + oct(sys.maxint+1).replace('L', '').replace('l', ''))

def ll_int2hex(i, addPrefix):
    if not addPrefix:
        return oostring(i, 16)

    buf = new(StringBuilder)
    if i<0:
        if i == SPECIAL_VALUE:
            return SPECIAL_VALUE_HEX
        i = -i
        buf.ll_append_char('-')

    buf.ll_append_char('0')
    buf.ll_append_char('x')
    buf.ll_append(oostring(i, 16))
    return buf.ll_build()
Example #12
0
def test_string_builder():
    b = ootype.new(ootype.StringBuilder)
    b.ll_append_char('a')
    b.ll_append(ootype.make_string('bcd'))
    res = b.ll_build()
    assert res._str == 'abcd'
Example #13
0
 def test_hlstr(self):
     s = ootype.make_string("abc")
     assert hlstr(s) == "abc"