The popular open-source contract for web designers and developers by Stuff & Nonsense
- Originally published: 23/12/2008
- Revised date: 15/12/2013
- Original post
| class DictWriter: | |
| def __init__(self, f, fieldnames, restval="", extrasaction="raise", | |
| dialect="excel", *args, **kwds): | |
| self.fieldnames = fieldnames # list of keys for the dict | |
| self.restval = restval # for writing short dicts | |
| if extrasaction.lower() not in ("raise", "ignore"): | |
| raise ValueError, \ | |
| ("extrasaction (%s) must be 'raise' or 'ignore'" % | |
| extrasaction) | |
| self.extrasaction = extrasaction |
| # For some reason, in Python 2.x True and False are both constants--meaning that | |
| # they can have new values assigned to them. | |
| # This malicious script exploits that. Upon import, will reverse | |
| # True and False for all modules in the current Python environment. | |
| # This obviously can have serious consequences. | |
| import sys | |
| # If we reverse them by still using the `bool` type, checking if type(False)==bool | |
| # won't help us catch this |