我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用codecs.unicode_escape_encode()。
def indicator(self, i): if not i: self._indicator = None return if PYVERSION == 2: try: i = codecs.unicode_escape_encode(i.decode('utf-8'))[0] except Exception: i = codecs.unicode_escape_encode(i.encode('utf-8', 'ignore').decode('utf-8'))[0] i = i.lower() self.itype = resolve_itype(i) self._indicator = i if self.itype == 'url': u = urlparse(self._indicator) self._indicator = u.geturl().rstrip('/').lower() if self.itype == 'ipv4': self._indicator = ipv4_normalize(self._indicator) if self.mask and (self.itype in ['ipv4', 'ipv6']): self._indicator = '{}/{}'.format(self._indicator, int(self.mask)) self.mask = None
def encode(self, input, final=False): return codecs.unicode_escape_encode(input, self.errors)[0]
def test_empty(self): self.assertEqual(codecs.unicode_escape_encode(u""), ("", 0)) self.assertEqual(codecs.unicode_escape_decode(""), (u"", 0))
def test_raw_encode(self): encode = codecs.unicode_escape_encode for b in range(32, 127): if b != ord('\\'): self.assertEqual(encode(unichr(b)), (chr(b), 1))
def test_escape_encode(self): encode = codecs.unicode_escape_encode check = coding_checker(self, encode) check(u'\t', r'\t') check(u'\n', r'\n') check(u'\r', r'\r') check(u'\\', r'\\') for b in range(32): if chr(b) not in '\t\n\r': check(unichr(b), '\\x%02x' % b) for b in range(127, 256): check(unichr(b), '\\x%02x' % b) check(u'\u20ac', r'\u20ac') check(u'\U0001d120', r'\U0001d120')
def test_empty(self): self.assertEqual(codecs.unicode_escape_encode(""), (b"", 0)) self.assertEqual(codecs.unicode_escape_decode(b""), ("", 0))
def test_raw_encode(self): encode = codecs.unicode_escape_encode for b in range(32, 127): if b != b'\\'[0]: self.assertEqual(encode(chr(b)), (bytes([b]), 1))
def test_escape_encode(self): encode = codecs.unicode_escape_encode check = coding_checker(self, encode) check('\t', br'\t') check('\n', br'\n') check('\r', br'\r') check('\\', br'\\') for b in range(32): if chr(b) not in '\t\n\r': check(chr(b), ('\\x%02x' % b).encode()) for b in range(127, 256): check(chr(b), ('\\x%02x' % b).encode()) check('\u20ac', br'\u20ac') check('\U0001d120', br'\U0001d120')