diff options
author | Ludwig Hähne <pankrat@tigris.org> | 2009-05-17 10:22:30 (GMT) |
---|---|---|
committer | Ludwig Hähne <pankrat@tigris.org> | 2009-05-17 10:22:30 (GMT) |
commit | 3234d7f71a124a2656bb0ad300b6969b4f0f4da2 (patch) | |
tree | a20763a234605abfde417736aeeb0a248f753e2a /src/engine/SCons/Util.py | |
parent | 2d548244bc07ab8faf2c9c1196958007c98ad4bf (diff) | |
download | SCons-3234d7f71a124a2656bb0ad300b6969b4f0f4da2.zip SCons-3234d7f71a124a2656bb0ad300b6969b4f0f4da2.tar.gz SCons-3234d7f71a124a2656bb0ad300b6969b4f0f4da2.tar.bz2 |
Issue 2415: Tolerate unicode strings when using intern()
Diffstat (limited to 'src/engine/SCons/Util.py')
-rw-r--r-- | src/engine/SCons/Util.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index ac949a0..ebdd1cd 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1569,6 +1569,27 @@ def MD5collect(signatures): +# Wrap the intern() function so it doesn't throw exceptions if ineligible +# arguments are passed. The intern() function was moved into the sys module in +# Python 3. +try: + intern +except NameError: + from sys import intern + +def silent_intern(x): + """ + Perform intern() on the passed argument and return the result. + If the input is ineligible (e.g. a unicode string) the original argument is + returned and no exception is thrown. + """ + try: + return intern(x) + except TypeError: + return x + + + # From Dinu C. Gherman, # Python Cookbook, second edition, recipe 6.17, p. 277. # Also: |