我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用codecs.latin_1_encode()。
def write(self, data): # TODO - Check bytes vs unicode if isinstance(data, str): data = codecs.latin_1_encode(data)[0] # block_size = 2**16 = 65536 data_len = len(data) if len(self._buffer) + data_len < 65536: # print("Cached %r" % data) self._buffer += data return else: # print("Got %r, writing out some data..." % data) self._buffer += data while len(self._buffer) >= 65536: self._write_block(self._buffer[:65536]) self._buffer = self._buffer[65536:]
def encode(self, input, final=False): return codecs.latin_1_encode(input,self.errors)[0]
def b(s): return codecs.latin_1_encode(s)[0]
def b(s): # BSON and socket operations deal in binary data. In # python 3 that means instances of `bytes`. In python # 2.6 and 2.7 you can create an alias for `bytes` using # the b prefix (e.g. b'foo'). # See http://python3porting.com/problems.html#nicer-solutions return codecs.latin_1_encode(s)[0]
def b(s): # BSON and socket operations deal in binary data. In # python 3 that means instances of `bytes`. In python # 2.6 and 2.7 you can create an alias for `bytes` using # the b prefix (e.g. b'foo'). Python 2.4 and 2.5 don't # provide this marker so we provide this compat function. # In python 3.x b('foo') results in b'foo'. # See http://python3porting.com/problems.html#nicer-solutions return codecs.latin_1_encode(s)[0]
def _to_bytes_impl(msg): if isinstance(msg, str): return codecs.latin_1_encode(msg, 'replace')[0] else: return msg
def _to_bytes_impl(msg): if msg is not None and isinstance(msg, str_type): return codecs.latin_1_encode(msg, 'replace')[0] else: return msg
def b(x, encoder=None): if isinstance(x, BytesType): return x else: import codecs encoder = encoder or codecs.latin_1_encode return encoder(x)[0]
def encode(x): return codecs.latin_1_encode(x)[0]
def b(x): if isinstance(x, six.binary_type): return x else: return codecs.latin_1_encode(x)[0]