def deep_encode(e, encoding='ascii'):
  """
  Encodes all strings using encoding, default ascii.
  """
  if isinstance(e, dict):
    return dict((i, deep_encode(j, encoding)) for (i, j) in e.items())
  elif isinstance(e, list):
    return [deep_encode(i, encoding) for i in e]
  elif isinstance(e, str):
    e = e.encode(encoding)
  return e