| 35 | return (outfile.getvalue(), len(input)) |
| 36 | |
| 37 | def uu_decode(input, errors='strict'): |
| 38 | assert errors == 'strict' |
| 39 | infile = BytesIO(input) |
| 40 | outfile = BytesIO() |
| 41 | readline = infile.readline |
| 42 | write = outfile.write |
| 43 | |
| 44 | # Find start of encoded data |
| 45 | while 1: |
| 46 | s = readline() |
| 47 | if not s: |
| 48 | raise ValueError('Missing "begin" line in input data') |
| 49 | if s[:5] == b'begin': |
| 50 | break |
| 51 | |
| 52 | # Decode |
| 53 | while True: |
| 54 | s = readline() |
| 55 | if not s or s == b'end\n': |
| 56 | break |
| 57 | try: |
| 58 | data = binascii.a2b_uu(s) |
| 59 | except binascii.Error: |
| 60 | # Workaround for broken uuencoders by /Fredrik Lundh |
| 61 | nbytes = (((s[0]-32) & 63) * 4 + 5) // 3 |
| 62 | data = binascii.a2b_uu(s[:nbytes]) |
| 63 | #sys.stderr.write("Warning: %s\n" % str(v)) |
| 64 | write(data) |
| 65 | if not s: |
| 66 | raise ValueError('Truncated input data') |
| 67 | |
| 68 | return (outfile.getvalue(), len(input)) |
| 69 | |
| 70 | class Codec(codecs.Codec): |
| 71 | def encode(self, input, errors='strict'): |