code: def _tidy_stacktrace(stack):
      
      django_path = os.path.realpath(os.path.dirname(django.__file__))
      django_path = os.path.normpath(os.path.join(django_path, '..'))
      socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__))
      pymongo_path = os.path.realpath(os.path.dirname(pymongo.__file__))
  
      trace = []
      for frame, path, line_no, func_name, text in (f[:5] for f in stack):
          s_path = os.path.realpath(path)
          # Support hiding of frames -- used in various utilities that provide
          # inspection.
          if '__traceback_hide__' in frame.f_locals:
              continue
          if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('HIDE_DJANGO_SQL', True) \
              and django_path in s_path and not 'django/contrib' in s_path:
              continue
          if socketserver_path in s_path:
              continue
          if pymongo_path in s_path:
              continue
          if not text:
              text = ''
          else:
              text = (''.join(text)).strip()
          trace.append((path, line_no, func_name, text))
      return trace
docs: Clean up stacktrace and remove all entries that:
      1. Are part of Django (except contrib apps)
      2. Are part of SocketServer (used by Django's dev server)
      3. Are the last entry (which is part of our stacktracing code)
  
      ``stack`` should be a list of frame tuples from ``inspect.stack()``