annotate Tools/scripts/lfcr.py @ 25135:0f0016632be4 legacy-trunk

_formatparam(), set_param(): RFC 2231 encoding support by Oleg Broytmann in SF patch #600096. Specifically, the former function now encodes the triplets, while the latter adds optional charset and language arguments.
author Barry Warsaw <barry@python.org>
date Fri, 06 Sep 2002 03:55:04 +0000
parents 9876a64c181a
children 7a1ae475e0da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9099
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #! /usr/bin/env python
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 "Replace LF with CRLF in argument files. Print names of changed files."
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
11763
9876a64c181a Patch by Gerrit Holl:
Guido van Rossum <guido@python.org>
parents: 9102
diff changeset
5 import sys, re, os
9099
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 for file in sys.argv[1:]:
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 if os.path.isdir(file):
9102
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
8 print file, "Directory!"
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
9 continue
9099
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 data = open(file, "rb").read()
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 if '\0' in data:
9102
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
12 print file, "Binary!"
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
13 continue
11763
9876a64c181a Patch by Gerrit Holl:
Guido van Rossum <guido@python.org>
parents: 9102
diff changeset
14 newdata = re.sub("\r?\n", "\r\n", data)
9099
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 if newdata != data:
9102
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
16 print file
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
17 f = open(file, "wb")
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
18 f.write(newdata)
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
19 f.close()