Beispiel #1
0
 def encode_w(self, space, w_object, final=False):
     utf8data, length = space.utf8_len_w(w_object)
     space = self.space
     state = space.fromcache(CodecState)
     if len(self.pending) > 0:
         utf8data = self.pending + utf8data
         length += self.pending_len
     try:
         output = c_codecs.encodeex(self.encodebuf, utf8data, length,
                                    self.errors, state.encode_error_handler,
                                    self.name, get_ignore_error(final))
     except c_codecs.EncodeDecodeError as e:
         raise wrap_unicodeencodeerror(space, e, utf8data, length,
                                       self.name)
     except RuntimeError:
         raise wrap_runtimeerror(space)
     pos = c_codecs.pypy_cjk_enc_inbuf_consumed(self.encodebuf)
     assert 0 <= pos <= length
     # scan the utf8 string until we hit pos
     i = 0
     stop = length - pos
     self.pending_len = stop
     if stop > 0:
         while pos > 0:
             i = rutf8.next_codepoint_pos(utf8data, i)
             pos -= 1
         self.pending = utf8data[i:]
     else:
         self.pending = ""
     return space.newbytes(output)
Beispiel #2
0
 def encode_w(self, object, final=False):
     space = self.space
     state = space.fromcache(CodecState)
     if len(self.pending) > 0:
         object = self.pending + object
     try:
         output = c_codecs.encodeex(self.encodebuf, object, self.errors,
                                    state.encode_error_handler, self.name,
                                    get_ignore_error(final))
     except c_codecs.EncodeDecodeError, e:
         raise wrap_unicodeencodeerror(space, e, object, self.name)
Beispiel #3
0
 def encode_w(self, object, final=False):
     space = self.space
     state = space.fromcache(CodecState)
     if len(self.pending) > 0:
         object = self.pending + object
     try:
         output = c_codecs.encodeex(self.encodebuf, object, self.errors,
                                    state.encode_error_handler, self.name,
                                    get_ignore_error(final))
     except c_codecs.EncodeDecodeError, e:
         raise wrap_unicodeencodeerror(space, e, object, self.name)
Beispiel #4
0
 def encode_w(self, object, final=False):
     space = self.space
     state = space.fromcache(CodecState)
     if len(self.pending) > 0:
         object = self.pending + object
     try:
         output = c_codecs.encodeex(self.encodebuf, object, self.errors,
                                    state.encode_error_handler, self.name,
                                    get_ignore_error(final))
     except c_codecs.EncodeDecodeError as e:
         raise wrap_unicodeencodeerror(space, e, object, self.name)
     except RuntimeError:
         raise wrap_runtimeerror(space)
     pos = c_codecs.pypy_cjk_enc_inbuf_consumed(self.encodebuf)
     assert 0 <= pos <= len(object)
     self.pending = object[pos:]
     return space.newbytes(output)
Beispiel #5
0
 def encode_w(self, object, final=False):
     space = self.space
     state = space.fromcache(CodecState)
     if len(self.pending) > 0:
         object = self.pending + object
     try:
         output = c_codecs.encodeex(self.encodebuf, object, self.errors,
                                    state.encode_error_handler, self.name,
                                    get_ignore_error(final))
     except c_codecs.EncodeDecodeError as e:
         raise wrap_unicodeencodeerror(space, e, object, self.name)
     except RuntimeError:
         raise wrap_runtimeerror(space)
     pos = c_codecs.pypy_cjk_enc_inbuf_consumed(self.encodebuf)
     assert 0 <= pos <= len(object)
     self.pending = object[pos:]
     return space.newbytes(output)