# Online Python Tutor # https://github.com/pgbovine/OnlinePythonTutor/ # # Copyright (C) Philip J. Guo (philip@pgbovine.net) # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # Thanks to John DeNero for making the encoder work on both Python 2 and 3 # (circa 2012-2013) # Given an arbitrary piece of Python data, encode it in such a manner # that it can be later encoded into JSON. # http://json.org/ # # We use this function to encode run-time traces of data structures # to send to the front-end. # # Format: # Primitives: # * None, int, long, float, str, bool - unchanged # (json.dumps encodes these fine verbatim, except for inf, -inf, and nan) # # exceptions: float('inf') -> ['SPECIAL_FLOAT', 'Infinity'] # float('-inf') -> ['SPECIAL_FLOAT', '-Infinity'] # float('nan') -> ['SPECIAL_FLOAT', 'NaN'] # x == int(x) -> ['SPECIAL_FLOAT', '%.1f' % x] # (this way, 3.0 prints as '3.0' and not as 3, which looks like an int) # # If render_heap_primitives is True, then primitive values are rendered # on the heap as ['HEAP_PRIMITIVE', , ] # # (for SPECIAL_FLOAT values, is a list like ['SPECIAL_FLOAT', 'Infinity']) # # added on 2018-06-13: # ['IMPORTED_FAUX_PRIMITIVE',