httpauth.py: Use `base64' module's built-in character twiddles.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 10 Aug 2013 12:29:41 +0000 (13:29 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 10 Aug 2013 12:29:41 +0000 (13:29 +0100)
I hadn't noticed before: `b64encode' has an optional argument which you
can use to change the `+' and `/' characters.  Use them instead of a
post-pass with `str.replace'.

httpauth.py

index ea978eb..6bb3ec8 100644 (file)
@@ -149,9 +149,7 @@ def freshsecret():
 
 def hack_octets(s):
   """Return the octet string S, in a vaguely pretty form."""
-  return BN.b64encode(s) \
-           .rstrip('=') \
-           .replace('/', '$')
+  return BN.b64encode(s, '+$').rstrip('=')
 
 def auth_tag(sec, stamp, nonce, user):
   """Compute a tag using secret SEC on `STAMP.NONCE.USER'."""