コード例 #1
0
    def llimpl_FormatErrorW(code):
        "Return a utf8-encoded msg and its length"
        buf = lltype.malloc(rffi.CWCHARPP.TO, 1, flavor='raw')
        buf[0] = lltype.nullptr(rffi.CWCHARP.TO)
        try:
            msglen = FormatMessageW(
                FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
                | FORMAT_MESSAGE_IGNORE_INSERTS, None, rffi.cast(DWORD, code),
                DEFAULT_LANGUAGE, rffi.cast(rffi.CWCHARP, buf), 0, None)
            buflen = intmask(msglen)

            # remove trailing cr/lf and dots
            s_buf = buf[0]
            while buflen > 0 and (ord(s_buf[buflen - 1]) <= ord(' ')
                                  or s_buf[buflen - 1] == u'.'):
                buflen -= 1

            if buflen <= 0:
                msg = 'Windows Error %d' % (code, )
                result = msg, len(msg)
            else:
                result = rffi.wcharpsize2utf8(s_buf, buflen), buflen
        finally:
            LocalFree(rffi.cast(rffi.VOIDP, buf[0]))
            lltype.free(buf, flavor='raw')

        return result
コード例 #2
0
ファイル: interp_array.py プロジェクト: eggman79/pypy
    def descr_tounicode(self, space):
        """ tounicode() -> unicode

        Convert the array to a unicode string.  The array must be
        a type 'u' array; otherwise a ValueError is raised.  Use
        array.tostring().decode() to obtain a unicode string from
        an array of some other type.
        """
        if self.typecode == 'u':
            buf = rffi.cast(UNICODE_ARRAY, self._buffer_as_unsigned())
            return space.newutf8(rffi.wcharpsize2utf8(buf, self.len), self.len)
        else:
            raise oefmt(space.w_ValueError,
                        "tounicode() may only be called on type 'u' arrays")
コード例 #3
0
def decodeex(decodebuf,
             stringdata,
             errors="strict",
             errorcb=None,
             namecb=None,
             ignore_error=0):
    inleft = len(stringdata)
    with rffi.scoped_nonmovingbuffer(stringdata) as inbuf:
        if pypy_cjk_dec_init(decodebuf, inbuf, inleft) < 0:
            raise MemoryError
        while True:
            r = pypy_cjk_dec_chunk(decodebuf)
            if r == 0 or r == ignore_error:
                break
            multibytecodec_decerror(decodebuf, r, errors, errorcb, namecb,
                                    stringdata)
        src = pypy_cjk_dec_outbuf(decodebuf)
        length = pypy_cjk_dec_outlen(decodebuf)
        return rffi.wcharpsize2utf8(src,
                                    length)  # assumes no out-of-range chars
コード例 #4
0
ファイル: interp_rawffi.py プロジェクト: eggman79/pypy
def wcharp2rawunicode(space, address, maxlength=-1):
    if maxlength == -1:
        return wcharp2unicode(space, address)
    s = rffi.wcharpsize2utf8(rffi.cast(rffi.CWCHARP, address), maxlength)
    return space.newutf8(s, maxlength)