Andriy Kornatskyy avatar Andriy Kornatskyy committed 53fd5d4

Updated key encoding doctests with use of unicode string.

Comments (0)

Files changed (1)

src/wheezy/caching/encoding.py

 def base64_encode(key):
     """ Encodes ``key`` with base64 encoding.
 
-        >>> result = base64_encode('my key')
+        >>> result = base64_encode(string_type('my key'))
         >>> result == 'bXkga2V5'.encode('latin1')
         True
     """
-    key = string_encode(key)
+    if isinstance(key, string_type):
+        key = key.encode('UTF-8')
     return b64encode(key, BASE64_ALTCHARS)
 
 
         >>> try:
         ...     from hashlib import sha1
         ...     key_encode = hash_encode(sha1)
-        ...     r = base64_encode(key_encode('my key'))
+        ...     r = base64_encode(key_encode(string_type('my key')))
         ...     assert r == 'RigVwkWdSuGyFu7au08PzUMloU8='.encode('latin1')
         ... except ImportError:  # Python2.4
         ...     pass
 
     def key_encode(key):
         h = hash_factory()
-        h.update(string_encode(key))
+        if isinstance(key, string_type):
+            key = key.encode('UTF-8')
+        h.update(key)
         return h.digest()
     return key_encode
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.