code: def _encode_key(self, key):
          
          if isinstance(key, str) or isinstance(key, unicode):
              key = key.encode(self._keyencoding)
          elif not isinstance(key, bytes):
              raise TypeError("key must be bytes or str")
          return codecs.encode(key, 'hex_codec').decode(self._keyencoding)
docs: Encode key using *hex_codec* for constructing a cache filename.
  
          Keys are implicitly converted to :class:`bytes` if passed as
          :class:`str`.