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)
def make_string(self, value): return ootype.make_string(value)
def ll_constant(s): return ootype.make_string(s)
def oostr(s): if strtype is str: return ootype.make_string(s) else: return ootype.make_unicode(s)
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'
def test_hlstr(self): s = ootype.make_string("abc") assert hlstr(s) == "abc"
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()