def parse_troubleshooting(troubleshooting_json):
    """Normalizes the troubleshooting data from `question`.

    Returns a normalized version, or `None` if something was wrong.
    This does not try very hard to fix bad data.
    """
    if not troubleshooting_json:
        return None
    try:
        parsed = json.loads(troubleshooting_json)
    except __HOLE__:
        return None

    # This is a spec of what is expected to be in the parsed
    # troubleshooting data. The format here is a list of tuples. The
    # first item in the tuple is a list of keys to access to get to the
    # item in question. The second item in the tuple is the type the
    # referenced item should be. For example, this line
    #
    #   (('application', 'name'), basestring),
    #
    # means that parse['application']['name'] must be a basestring.
    #
    # An empty path means the parsed json.
    spec = (
        ((), dict),
        (('accessibility', ), dict),
        (('accessibility', 'isActive'), bool),
        (('application', ), dict),
        (('application', 'name'), basestring),
        (('application', 'supportURL'), basestring),
        (('application', 'userAgent'), basestring),
        (('application', 'version'), basestring),
        (('extensions', ), list),
        (('graphics', ), dict),
        (('javaScript', ), dict),
        (('modifiedPreferences', ), dict),
        (('userJS', ), dict),
        (('userJS', 'exists'), bool),
    )

    for path, type_ in spec:
        item = parsed
        for piece in path:
            item = item.get(piece)
            if item is None:
                return None

        if not isinstance(item, type_):
            return None

    # The data has been inspected, and should be in the right format.
    # Now remove all the printing preferences, because they are noisy.
    # TODO: If the UI for this gets better, we can include these prefs
    # and just make them collapsible.

    parsed['modifiedPreferences'] = dict(
        (key, val) for (key, val) in parsed['modifiedPreferences'].items()
        if not key.startswith('print'))

    return parsed
dataset/ETHPy150Open mozilla/kitsune/kitsune/questions/views.py/parse_troubleshooting