diff options
author | Georg Brandl <georg@python.org> | 2012-02-20 21:31:46 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2012-02-20 21:31:46 +0100 |
commit | c046a714e1f2152c7f45bc90d6f3829c34e7029f (patch) | |
tree | 4ad97aaf7ffcf9e49750a59179ef736b8e62e6e1 /Tools/scripts/suff.py | |
parent | 5af1ccb2a86c32b4a7ed302bd75dd824606fc222 (diff) | |
parent | 9edd5e108cf2736595d6bb117e1a2a45b4403e85 (diff) | |
download | cpython-c046a714e1f2152c7f45bc90d6f3829c34e7029f.tar.gz |
Merge from 3.1: Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
in order to make algorithmic complexity attacks on (e.g.) web apps much more complicated.
The environment variable PYTHONHASHSEED and the new command line flag -R control this
behavior.
Diffstat (limited to 'Tools/scripts/suff.py')
-rwxr-xr-x | Tools/scripts/suff.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/Tools/scripts/suff.py b/Tools/scripts/suff.py index 462ec32183..0eea0d7548 100755 --- a/Tools/scripts/suff.py +++ b/Tools/scripts/suff.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # suff # @@ -6,24 +6,21 @@ import sys + def main(): files = sys.argv[1:] suffixes = {} for filename in files: suff = getsuffix(filename) - if suff not in suffixes: - suffixes[suff] = [] - suffixes[suff].append(filename) - keys = sorted(suffixes.keys()) - for suff in keys: - print(repr(suff), len(suffixes[suff])) + suffixes.setdefault(suff, []).append(filename) + for suff, filenames in sorted(suffixes.items()): + print(repr(suff), len(filenames)) + def getsuffix(filename): - suff = '' - for i in range(len(filename)): - if filename[i] == '.': - suff = filename[i:] - return suff + name, sep, suff = filename.rpartition('.') + return sep + suff if sep else '' + if __name__ == '__main__': main() |