Пример #1
0
def unicode_to_decimal_w(space, w_unistr):
    if not isinstance(w_unistr, W_UnicodeObject):
        raise OperationError(space.w_TypeError,
                             space.wrap("expected unicode"))
    unistr = w_unistr._value
    result = ['\0'] * len(unistr)
    digits = [ '0', '1', '2', '3', '4',
               '5', '6', '7', '8', '9']
    for i in xrange(len(unistr)):
        uchr = ord(unistr[i])
        if unicodedb.isspace(uchr):
            result[i] = ' '
            continue
        try:
            result[i] = digits[unicodedb.decimal(uchr)]
        except KeyError:
            if 0 < uchr < 256:
                result[i] = chr(uchr)
            else:
                w_encoding = space.wrap('decimal')
                w_start = space.wrap(i)
                w_end = space.wrap(i+1)
                w_reason = space.wrap('invalid decimal Unicode string')
                raise OperationError(space.w_UnicodeEncodeError,space.newtuple ([w_encoding, w_unistr, w_start, w_end, w_reason]))
    return ''.join(result)
Пример #2
0
def unicode_to_decimal_w(space, w_unistr):
    if not isinstance(w_unistr, W_UnicodeObject):
        raise OperationError(space.w_TypeError, space.wrap("expected unicode"))
    unistr = w_unistr._value
    result = ['\0'] * len(unistr)
    digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    for i in xrange(len(unistr)):
        uchr = ord(unistr[i])
        if unicodedb.isspace(uchr):
            result[i] = ' '
            continue
        try:
            result[i] = digits[unicodedb.decimal(uchr)]
        except KeyError:
            if 0 < uchr < 256:
                result[i] = chr(uchr)
            else:
                w_encoding = space.wrap('decimal')
                w_start = space.wrap(i)
                w_end = space.wrap(i + 1)
                w_reason = space.wrap('invalid decimal Unicode string')
                raise OperationError(
                    space.w_UnicodeEncodeError,
                    space.newtuple(
                        [w_encoding, w_unistr, w_start, w_end, w_reason]))
    return ''.join(result)
Пример #3
0
def unicode_isspace__Unicode(space, w_unicode):
    if len(w_unicode._value) == 0:
        return space.w_False
    for uchar in w_unicode._value:
        if not unicodedb.isspace(ord(uchar)):
            return space.w_False
    return space.w_True
Пример #4
0
def unicode_to_decimal_w(space, w_unistr):
    if not isinstance(w_unistr, W_RopeUnicodeObject):
        raise OperationError(space.w_TypeError, space.wrap("expected unicode"))
    unistr = w_unistr._node
    length = unistr.length()
    result = ["\0"] * length
    digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
    iter = rope.ItemIterator(unistr)
    for i in range(length):
        uchr = iter.nextint()
        if unicodedb.isspace(uchr):
            result[i] = " "
            continue
        try:
            result[i] = digits[unicodedb.decimal(uchr)]
        except KeyError:
            if 0 < uchr < 256:
                result[i] = chr(uchr)
            else:
                w_encoding = space.wrap("decimal")
                w_start = space.wrap(i)
                w_end = space.wrap(i + 1)
                w_reason = space.wrap("invalid decimal Unicode string")
                raise OperationError(
                    space.w_UnicodeEncodeError, space.newtuple([w_encoding, w_unistr, w_start, w_end, w_reason])
                )
    return "".join(result)
Пример #5
0
def _isspace(uchar):
    return unicodedb.isspace(ord(uchar))
Пример #6
0
def _isspace(uchar):
    return unicodedb.isspace(ord(uchar))
Пример #7
0
def _isspace(uchar_ord):
    return unicodedb.isspace(uchar_ord)