Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/crlf.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | f94d74c85dcb |
| children |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
42427
diff
changeset
|
1 #! /usr/bin/env python3 |
|
9100
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 "Replace CRLF with LF in argument files. Print names of changed files." |
|
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
26199
d37f1378d8b8
Tim wins a bet. Don't use re.
Guido van Rossum <guido@python.org>
parents:
11763
diff
changeset
|
4 import sys, os |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
5 |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
6 def main(): |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
7 for filename in sys.argv[1:]: |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
8 if os.path.isdir(filename): |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
33076
diff
changeset
|
9 print(filename, "Directory!") |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
10 continue |
|
69947
f94d74c85dcb
Close #12032: Fix scripts/crlf.py for Python 3
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59522
diff
changeset
|
11 with open(filename, "rb") as f: |
|
f94d74c85dcb
Close #12032: Fix scripts/crlf.py for Python 3
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59522
diff
changeset
|
12 data = f.read() |
|
f94d74c85dcb
Close #12032: Fix scripts/crlf.py for Python 3
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59522
diff
changeset
|
13 if b'\0' in data: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
33076
diff
changeset
|
14 print(filename, "Binary!") |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
15 continue |
|
69947
f94d74c85dcb
Close #12032: Fix scripts/crlf.py for Python 3
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59522
diff
changeset
|
16 newdata = data.replace(b"\r\n", b"\n") |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
17 if newdata != data: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
33076
diff
changeset
|
18 print(filename) |
|
69947
f94d74c85dcb
Close #12032: Fix scripts/crlf.py for Python 3
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59522
diff
changeset
|
19 with open(filename, "wb") as f: |
|
f94d74c85dcb
Close #12032: Fix scripts/crlf.py for Python 3
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59522
diff
changeset
|
20 f.write(newdata) |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
21 |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
22 if __name__ == '__main__': |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29099
diff
changeset
|
23 main() |
