Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | r""" |
michael@0 | 2 | Using simplejson from the shell to validate and |
michael@0 | 3 | pretty-print:: |
michael@0 | 4 | |
michael@0 | 5 | $ echo '{"json":"obj"}' | python -msimplejson |
michael@0 | 6 | { |
michael@0 | 7 | "json": "obj" |
michael@0 | 8 | } |
michael@0 | 9 | $ echo '{ 1.2:3.4}' | python -msimplejson |
michael@0 | 10 | Expecting property name: line 1 column 2 (char 2) |
michael@0 | 11 | |
michael@0 | 12 | Note that the JSON produced by this module's default settings |
michael@0 | 13 | is a subset of YAML, so it may be used as a serializer for that as well. |
michael@0 | 14 | """ |
michael@0 | 15 | import simplejson |
michael@0 | 16 | |
michael@0 | 17 | # |
michael@0 | 18 | # Pretty printer: |
michael@0 | 19 | # curl http://mochikit.com/examples/ajax_tables/domains.json | python -msimplejson.tool |
michael@0 | 20 | # |
michael@0 | 21 | |
michael@0 | 22 | def main(): |
michael@0 | 23 | import sys |
michael@0 | 24 | if len(sys.argv) == 1: |
michael@0 | 25 | infile = sys.stdin |
michael@0 | 26 | outfile = sys.stdout |
michael@0 | 27 | elif len(sys.argv) == 2: |
michael@0 | 28 | infile = open(sys.argv[1], 'rb') |
michael@0 | 29 | outfile = sys.stdout |
michael@0 | 30 | elif len(sys.argv) == 3: |
michael@0 | 31 | infile = open(sys.argv[1], 'rb') |
michael@0 | 32 | outfile = open(sys.argv[2], 'wb') |
michael@0 | 33 | else: |
michael@0 | 34 | raise SystemExit("%s [infile [outfile]]" % (sys.argv[0],)) |
michael@0 | 35 | try: |
michael@0 | 36 | obj = simplejson.load(infile) |
michael@0 | 37 | except ValueError, e: |
michael@0 | 38 | raise SystemExit(e) |
michael@0 | 39 | simplejson.dump(obj, outfile, sort_keys=True, indent=4) |
michael@0 | 40 | outfile.write('\n') |
michael@0 | 41 | |
michael@0 | 42 | |
michael@0 | 43 | if __name__ == '__main__': |
michael@0 | 44 | main() |