Example #1
0
    def unichr_to_code_w(space, w_unichr):
        if not space.isinstance_w(w_unichr, space.w_unicode):
            raise OperationError(space.w_TypeError, space.wrap(
                'argument 1 must be unicode'))

        if not we_are_translated() and sys.maxunicode == 0xFFFF:
            # Host CPython is narrow build, accept surrogates
            try:
                return ord_accepts_surrogate(space.unicode_w(w_unichr))
            except TypeError:
                raise OperationError(space.w_TypeError, space.wrap(
                    'need a single Unicode character as parameter'))
        else:
            if not space.len_w(w_unichr) == 1:
                raise OperationError(space.w_TypeError, space.wrap(
                    'need a single Unicode character as parameter'))
            return space.int_w(space.ord(w_unichr))
    def unichr_to_code_w(space, w_unichr):
        if not space.isinstance_w(w_unichr, space.w_unicode):
            raise oefmt(space.w_TypeError,
                        'argument 1 must be unicode, not %T', w_unichr)

        if not we_are_translated() and sys.maxunicode == 0xFFFF:
            # Host CPython is narrow build, accept surrogates
            try:
                return ord_accepts_surrogate(space.unicode_w(w_unichr))
            except TypeError:
                raise oefmt(space.w_TypeError,
                            "need a single Unicode character as parameter")
        else:
            if not space.len_w(w_unichr) == 1:
                raise oefmt(space.w_TypeError,
                            "need a single Unicode character as parameter")
            return space.int_w(space.ord(w_unichr))
Example #3
0
    def unichr_to_code_w(space, w_unichr):
        if not space.isinstance_w(w_unichr, space.w_unicode):
            raise oefmt(
                space.w_TypeError, 'argument 1 must be unicode, not %T',
                w_unichr)

        if not we_are_translated() and sys.maxunicode > 0xFFFF:
            # Host CPython is wide build, forbid surrogates
            if not space.len_w(w_unichr) == 1:
                raise oefmt(space.w_TypeError,
                            "need a single Unicode character as parameter")
            return space.int_w(space.ord(w_unichr))

        else:
            # Accept surrogates
            try:
                return ord_accepts_surrogate(space.unicode_w(w_unichr))
            except TypeError:
                raise oefmt(space.w_TypeError,
                            "need a single Unicode character as parameter")
Example #4
0
    def unichr_to_code_w(space, w_unichr):
        if not space.isinstance_w(w_unichr, space.w_unicode):
            raise OperationError(space.w_TypeError,
                                 space.wrap('argument 1 must be unicode'))

        if not we_are_translated() and sys.maxunicode > 0xFFFF:
            # Host CPython is wide build, forbid surrogates
            if not space.len_w(w_unichr) == 1:
                raise OperationError(
                    space.w_TypeError,
                    space.wrap('need a single Unicode character as parameter'))
            return space.int_w(space.ord(w_unichr))

        else:
            # Accept surrogates
            try:
                return ord_accepts_surrogate(space.unicode_w(w_unichr))
            except TypeError:
                raise OperationError(
                    space.w_TypeError,
                    space.wrap('need a single Unicode character as parameter'))