code: def convert(data):
      
      if isinstance(data, unicode):
          return data.encode('utf-8')
      elif isinstance(data, str):
          return data
      elif isinstance(data, collections.Mapping):
          return dict(map(convert, data.iteritems()))
      elif isinstance(data, collections.Iterable):
          return type(data)(map(convert, data))
      else:
          return data
docs: convert a standalone unicode string or unicode strings in a
      mapping or iterable into byte strings.