Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2012 the V8 project authors. All rights reserved. | 1 # Copyright 2012 the V8 project authors. All rights reserved. |
| 2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
| 3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
| 4 # met: | 4 # met: |
| 5 # | 5 # |
| 6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
| 9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
| 10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 # In python 2.7.6 on windows, urlopen has a problem with redirects. | 129 # In python 2.7.6 on windows, urlopen has a problem with redirects. |
| 130 # Try using curl instead. Note, this is fixed in 2.7.8. | 130 # Try using curl instead. Note, this is fixed in 2.7.8. |
| 131 subprocess.check_call(["curl", source, '-k', '-L', '-o', destination]) | 131 subprocess.check_call(["curl", source, '-k', '-L', '-o', destination]) |
| 132 return | 132 return |
| 133 except: | 133 except: |
| 134 # If there's no curl, fall back to urlopen. | 134 # If there's no curl, fall back to urlopen. |
| 135 print "Curl is currently not installed. Falling back to python." | 135 print "Curl is currently not installed. Falling back to python." |
| 136 pass | 136 pass |
| 137 with open(destination, 'w') as f: | 137 with open(destination, 'w') as f: |
| 138 f.write(urllib2.urlopen(source).read()) | 138 f.write(urllib2.urlopen(source).read()) |
| 139 | |
| 140 | |
| 141 class FrozenDict(dict): | |
| 142 def __setitem__(self, *args, **kwargs): | |
| 143 raise Exception('Tried to mutate a fozen dict') | |
|
Jakob Kummerow
2016/08/04 14:17:12
nit: s/fozen/frozen/
| |
| 144 | |
| 145 def update(self, *args, **kwargs): | |
| 146 raise Exception('Tried to mutate a fozen dict') | |
|
Jakob Kummerow
2016/08/04 14:17:12
nit: s/fozen/frozen/
| |
| 147 | |
| 148 | |
| 149 def Freeze(obj): | |
| 150 if isinstance(obj, dict): | |
| 151 return FrozenDict((k, Freeze(v)) for k, v in obj.iteritems()) | |
| 152 elif isinstance(obj, set): | |
| 153 return frozenset(obj) | |
| 154 elif isinstance(obj, list): | |
| 155 return tuple(Freeze(item) for item in obj) | |
| 156 else: | |
| 157 # Make sure object is hashable. | |
| 158 hash(obj) | |
| 159 return obj | |
| OLD | NEW |