Decode a quoted-printable string. Lines are separated with eol, which defaults to \\n.
(encoded, eol=NL)
| 230 | # BAW: I'm not sure if the intent was for the signature of this function to be |
| 231 | # the same as base64MIME.decode() or not... |
| 232 | def decode(encoded, eol=NL): |
| 233 | """Decode a quoted-printable string. |
| 234 | |
| 235 | Lines are separated with eol, which defaults to \\n. |
| 236 | """ |
| 237 | if not encoded: |
| 238 | return encoded |
| 239 | # BAW: see comment in encode() above. Again, we're building up the |
| 240 | # decoded string with string concatenation, which could be done much more |
| 241 | # efficiently. |
| 242 | decoded = '' |
| 243 | |
| 244 | for line in encoded.splitlines(): |
| 245 | line = line.rstrip() |
| 246 | if not line: |
| 247 | decoded += eol |
| 248 | continue |
| 249 | |
| 250 | i = 0 |
| 251 | n = len(line) |
| 252 | while i < n: |
| 253 | c = line[i] |
| 254 | if c != '=': |
| 255 | decoded += c |
| 256 | i += 1 |
| 257 | # Otherwise, c == "=". Are we at the end of the line? If so, add |
| 258 | # a soft line break. |
| 259 | elif i+1 == n: |
| 260 | i += 1 |
| 261 | continue |
| 262 | # Decode if in form =AB |
| 263 | elif i+2 < n and line[i+1] in hexdigits and line[i+2] in hexdigits: |
| 264 | decoded += unquote(line[i:i+3]) |
| 265 | i += 3 |
| 266 | # Otherwise, not in form =AB, pass literally |
| 267 | else: |
| 268 | decoded += c |
| 269 | i += 1 |
| 270 | |
| 271 | if i == n: |
| 272 | decoded += eol |
| 273 | # Special case if original string did not end with eol |
| 274 | if encoded[-1] not in '\r\n' and decoded.endswith(eol): |
| 275 | decoded = decoded[:-1] |
| 276 | return decoded |
| 277 | |
| 278 | |
| 279 | # For convenience and backwards compatibility w/ standard base64 module |
nothing calls this directly
no test coverage detected
searching dependent graphs…