Return Base64 web safe encoding of s. Suppress padding characters (=). Uses URL-safe alphabet: - replaces +, _ replaces /. Will convert s of type unicode to string type first. @param s: string to encode as Base64 @type s: string @return: Base64 representation of s. @r
(s)
| 439 | |
| 440 | |
| 441 | def Base64WSEncode(s): |
| 442 | """ |
| 443 | Return Base64 web safe encoding of s. Suppress padding characters (=). |
| 444 | |
| 445 | Uses URL-safe alphabet: - replaces +, _ replaces /. Will convert s of type |
| 446 | unicode to string type first. |
| 447 | |
| 448 | @param s: string to encode as Base64 |
| 449 | @type s: string |
| 450 | |
| 451 | @return: Base64 representation of s. |
| 452 | @rtype: string |
| 453 | |
| 454 | NOTE: Taken from keyczar (Apache 2.0 license) |
| 455 | """ |
| 456 | if isinstance(s, six.text_type): |
| 457 | # Make sure input string is always converted to bytes (if not already) |
| 458 | s = s.encode("utf-8") |
| 459 | |
| 460 | return base64.urlsafe_b64encode(s).decode("utf-8").replace("=", "") |
| 461 | |
| 462 | |
| 463 | def Base64WSDecode(s): |