# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Breakpad for Python.

Sends a notification when a process stops on an exception."""

import atexit
import getpass
import urllib
import traceback
import socket
import sys


def SendStack(stack, url='http://chromium-status.appspot.com/breakpad'):
  print 'Sending crash report ...'
  try:
    params = {
        'args': sys.argv,
        'stack': stack,
        'user': getpass.getuser(),
    }
    request = urllib.urlopen(url, urllib.urlencode(params))
    print request.read()
    request.close()
  except IOError:
    print('There was a failure while trying to send the stack trace. Too bad.')


def CheckForException():
  last_tb = getattr(sys, 'last_traceback', None)
  if last_tb and sys.last_type is not KeyboardInterrupt:
    SendStack(''.join(traceback.format_tb(last_tb)))


if (not 'test' in sys.modules['__main__'].__file__ and
    socket.gethostname().endswith('.google.com')):
  # Skip unit tests and we don't want anything from non-googler.
  atexit.register(CheckForException)

@@ -338,34 +338,48 @@
 ys%0A%0A
-%0Adef SendStack(stack, url=
+# Configure these values.%0ADEFAULT_URL = 
 'htt
@@ -419,18 +419,94 @@
 reakpad'
-):
+%0A%0Adef SendStack(last_tb, stack, url=None):%0A  if not url:%0A    url = DEFAULT_URL
 %0A  print
@@ -640,16 +640,46 @@
 user(),%0A
+        'exception': last_tb,%0A
     %7D%0A  
@@ -913,18 +913,21 @@
 %0A  last_
-tb
+value
  = getat
@@ -940,25 +940,21 @@
 , 'last_
-traceback
+value
 ', None)
@@ -968,35 +968,44 @@
 ast_
-tb and sys.last_type is not
+value and not isinstance(last_value,
  Key
@@ -1022,24 +1022,112 @@
 rupt
+)
 :%0A    
-SendStack(
+last_tb = getattr(sys, 'last_traceback', None)%0A    if last_tb:%0A      SendStack(repr(last_value), 
 ''.j

Fix KeyboardInterrupt exception filtering. Add exception information and not just the stack trace. Make the url easier to change at runtime.