示例#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)
示例#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)
示例#3
0
 def make_string(self, value):
     return ootype.make_string(value)
示例#4
0
 def ll_constant(s):
     return ootype.make_string(s)
示例#5
0
 def oostr(s):
     if strtype is str:
         return ootype.make_string(s)
     else:
         return ootype.make_unicode(s)
示例#6
0
文件: rstr.py 项目: xx312022850/pypy
 def make_string(self, value):
     return ootype.make_string(value)
示例#7
0
文件: rstr.py 项目: xx312022850/pypy
 def ll_constant(s):
     return ootype.make_string(s)
示例#8
0
 def oostr(s):
     if strtype is str:
         return ootype.make_string(s)
     else:
         return ootype.make_unicode(s)
示例#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'
示例#10
0
 def test_hlstr(self):
     s = ootype.make_string("abc")
     assert hlstr(s) == "abc"
示例#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()
示例#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'
示例#13
0
 def test_hlstr(self):
     s = ootype.make_string("abc")
     assert hlstr(s) == "abc"