# -*- coding: UTF-8 -*- """UU Codec - UU content encoding, relying on the native uu package. This codec: - en/decodes strings from str to str - en/decodes strings from bytes to bytes - decodes file content to str (read) - encodes file content from str to bytes (write) """ from binascii import a2b_uu as _dec, b2a_uu as _enc from ..__common__ import * __examples__ = { 'enc(uu|uu_codec)': {'this is a test': "begin 666 -\n.=&AI 0 and lines[-1].strip(b" \t\r\n\f") in [b"", b"`"]: lines = lines[:-1] r = b"" for l in lines: r += _dec(l.strip(b" \t\r\n\f")) return r, len(text) add("uu", uu_encode, uu_decode, pattern=r"^uu(?:[-_]?encode|[-_]codec)?$", bonus_func=lambda o, *a: re.match(b"^begin [1-7]{3} .*\n.*\nend$", b(o.text).strip(b"\n"), re.M))