writetofile.py 895 B

123456789101112131415161718192021222324252627282930313233
  1. #-----------------------------------------------------------------------------
  2. # Copyright (C) 2012 The IPython Development Team
  3. #
  4. # Distributed under the terms of the BSD License. The full license is in
  5. # the file COPYING, distributed as part of this software.
  6. #-----------------------------------------------------------------------------
  7. """
  8. Copy data from input file to output file for testing.
  9. Command line usage:
  10. python writetofile.py INPUT OUTPUT
  11. Binary data from INPUT file is copied to OUTPUT file.
  12. If INPUT is '-', stdin is used.
  13. """
  14. if __name__ == '__main__':
  15. import sys
  16. from ipython_genutils.py3compat import PY3
  17. (inpath, outpath) = sys.argv[1:]
  18. if inpath == '-':
  19. if PY3:
  20. infile = sys.stdin.buffer
  21. else:
  22. infile = sys.stdin
  23. else:
  24. infile = open(inpath, 'rb')
  25. open(outpath, 'w+b').write(infile.read())