code: def dump(obj, fp=None, indent=None, sort_keys=False, **kw):
      if fp:
          iterable = YAMLEncoder(indent=indent, sort_keys=sort_keys, **kw).iterencode(obj)
          for chunk in iterable:
              fp.write(chunk)
      else:
          return dumps(obj, indent=indent, sort_keys=sort_keys, **kw)