Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/encodings/hex_codec.py @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 """Python 'hex_codec' Codec - 2-digit hex content transfer encoding. | |
2 | |
3 This codec de/encodes from bytes to bytes. | |
4 | |
5 Written by Marc-Andre Lemburg (mal@lemburg.com). | |
6 """ | |
7 | |
8 import codecs | |
9 import binascii | |
10 | |
11 ### Codec APIs | |
12 | |
13 def hex_encode(input, errors='strict'): | |
14 assert errors == 'strict' | |
15 return (binascii.b2a_hex(input), len(input)) | |
16 | |
17 def hex_decode(input, errors='strict'): | |
18 assert errors == 'strict' | |
19 return (binascii.a2b_hex(input), len(input)) | |
20 | |
21 class Codec(codecs.Codec): | |
22 def encode(self, input, errors='strict'): | |
23 return hex_encode(input, errors) | |
24 def decode(self, input, errors='strict'): | |
25 return hex_decode(input, errors) | |
26 | |
27 class IncrementalEncoder(codecs.IncrementalEncoder): | |
28 def encode(self, input, final=False): | |
29 assert self.errors == 'strict' | |
30 return binascii.b2a_hex(input) | |
31 | |
32 class IncrementalDecoder(codecs.IncrementalDecoder): | |
33 def decode(self, input, final=False): | |
34 assert self.errors == 'strict' | |
35 return binascii.a2b_hex(input) | |
36 | |
37 class StreamWriter(Codec, codecs.StreamWriter): | |
38 charbuffertype = bytes | |
39 | |
40 class StreamReader(Codec, codecs.StreamReader): | |
41 charbuffertype = bytes | |
42 | |
43 ### encodings module API | |
44 | |
45 def getregentry(): | |
46 return codecs.CodecInfo( | |
47 name='hex', | |
48 encode=hex_encode, | |
49 decode=hex_decode, | |
50 incrementalencoder=IncrementalEncoder, | |
51 incrementaldecoder=IncrementalDecoder, | |
52 streamwriter=StreamWriter, | |
53 streamreader=StreamReader, | |
54 _is_text_encoding=False, | |
55 ) |