launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04589
[Merge] lp:~lifeless/python-oops/extraction into lp:python-oops
Robert Collins has proposed merging lp:~lifeless/python-oops/extraction into lp:python-oops.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~lifeless/python-oops/extraction/+merge/71507
0.0.3 - support really simple oops reports on serialisation and reading. For now, fill in all the expected keys to aid migration (long term missing should not be present in the resulting oops dict).
--
https://code.launchpad.net/~lifeless/python-oops/extraction/+merge/71507
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/python-oops/extraction into lp:python-oops.
=== modified file 'oops/__init__.py'
--- oops/__init__.py 2011-08-10 08:22:19 +0000
+++ oops/__init__.py 2011-08-15 04:50:23 +0000
@@ -25,7 +25,7 @@
# established at this point, and setup.py will use a version of next-$(revno).
# If the releaselevel is 'final', then the tarball will be major.minor.micro.
# Otherwise it is major.minor.micro~$(revno).
-__version__ = (0, 0, 2, 'beta', 0)
+__version__ = (0, 0, 3, 'beta', 0)
__all__ = [
]
=== modified file 'oops/serializer_rfc822.py'
--- oops/serializer_rfc822.py 2011-08-11 02:55:14 +0000
+++ oops/serializer_rfc822.py 2011-08-15 04:50:23 +0000
@@ -62,7 +62,11 @@
id = msg.getheader('oops-id')
exc_type = msg.getheader('exception-type')
exc_value = msg.getheader('exception-value')
- date = iso8601.parse_date(msg.getheader('date'))
+ datestr = msg.getheader('date')
+ if datestr is not None:
+ date =iso8601.parse_date(msg.getheader('date'))
+ else:
+ date = None
pageid = msg.getheader('page-id')
username = msg.getheader('user')
url = msg.getheader('url')
@@ -148,29 +152,44 @@
"""Returns a list of bytestrings making up the serialized oops."""
chunks = []
chunks.append('Oops-Id: %s\n' % _normalise_whitespace(report['id']))
- chunks.append(
- 'Exception-Type: %s\n' % _normalise_whitespace(report['type']))
- chunks.append(
- 'Exception-Value: %s\n' % _normalise_whitespace(report['value']))
- chunks.append('Date: %s\n' % report['time'].isoformat())
- chunks.append('Page-Id: %s\n' % _normalise_whitespace(report['pageid']))
- chunks.append('Branch: %s\n' % _safestr(report['branch_nick']))
- chunks.append('Revision: %s\n' % report['revno'])
- chunks.append('User: %s\n' % _normalise_whitespace(report['username']))
- chunks.append('URL: %s\n' % _normalise_whitespace(report['url']))
- chunks.append('Duration: %s\n' % report['duration'])
- chunks.append('Informational: %s\n' % report['informational'])
+ if 'type' in report:
+ chunks.append(
+ 'Exception-Type: %s\n' % _normalise_whitespace(report['type']))
+ if 'value' in report:
+ chunks.append(
+ 'Exception-Value: %s\n' % _normalise_whitespace(report['value']))
+ if 'time' in report:
+ chunks.append('Date: %s\n' % report['time'].isoformat())
+ if 'pageid' in report:
+ chunks.append(
+ 'Page-Id: %s\n' % _normalise_whitespace(report['pageid']))
+ if 'branch_nick' in report:
+ chunks.append('Branch: %s\n' % _safestr(report['branch_nick']))
+ if 'revno' in report:
+ chunks.append('Revision: %s\n' % report['revno'])
+ if 'username' in report:
+ chunks.append(
+ 'User: %s\n' % _normalise_whitespace(report['username']))
+ if 'url' in report:
+ chunks.append('URL: %s\n' % _normalise_whitespace(report['url']))
+ if 'duration' in report:
+ chunks.append('Duration: %s\n' % report['duration'])
+ if 'informational' in report:
+ chunks.append('Informational: %s\n' % report['informational'])
chunks.append('\n')
safe_chars = ';/\\?:@&+$, ()*!'
- for key, value in report['req_vars']:
- chunks.append('%s=%s\n' % (urllib.quote(key, safe_chars),
- urllib.quote(value, safe_chars)))
- chunks.append('\n')
- for (start, end, database_id, statement) in report['db_statements']:
- chunks.append('%05d-%05d@%s %s\n' % (
- start, end, database_id, _normalise_whitespace(statement)))
- chunks.append('\n')
- chunks.append(report['tb_text'])
+ if 'req_vars' in report:
+ for key, value in report['req_vars']:
+ chunks.append('%s=%s\n' % (urllib.quote(key, safe_chars),
+ urllib.quote(value, safe_chars)))
+ chunks.append('\n')
+ if 'db_statements' in report:
+ for (start, end, database_id, statement) in report['db_statements']:
+ chunks.append('%05d-%05d@%s %s\n' % (
+ start, end, database_id, _normalise_whitespace(statement)))
+ chunks.append('\n')
+ if 'tb_text' in report:
+ chunks.append(report['tb_text'])
return chunks
=== modified file 'oops/tests/test_serializer_rfc822.py'
--- oops/tests/test_serializer_rfc822.py 2011-08-11 02:55:14 +0000
+++ oops/tests/test_serializer_rfc822.py 2011-08-15 04:50:23 +0000
@@ -147,6 +147,29 @@
self.assertEqual(report['branch_nick'], 'mybranch')
self.assertEqual(report['revno'], '45')
+ def test_minimal_oops(self):
+ # If we get a crazy-small oops, we can read it sensibly. Because there
+ # is existing legacy code, all keys are filled in with None, [] rather
+ # than being empty.
+ fp = StringIO.StringIO(dedent("""\
+ Oops-Id: OOPS-A0001
+ """))
+ report = read(fp)
+ self.assertEqual(report['id'], 'OOPS-A0001')
+ self.assertEqual(report['type'], None)
+ self.assertEqual(report['value'], None)
+ self.assertEqual(report['time'], None)
+ self.assertEqual(report['pageid'], None)
+ self.assertEqual(report['tb_text'], '')
+ self.assertEqual(report['username'], None)
+ self.assertEqual(report['url'], None)
+ self.assertEqual(report['duration'], -1)
+ self.assertEqual(len(report['req_vars']), 0)
+ self.assertEqual(len(report['db_statements']), 0)
+ self.assertFalse(report['informational'])
+ self.assertEqual(report['branch_nick'], None)
+ self.assertEqual(report['revno'], None)
+
class TestSerializing(testtools.TestCase):
@@ -237,3 +260,12 @@
"traceback-text",
],
to_chunks(report))
+
+ def test_minimal_oops(self):
+ # An oops with just an id, though arguably crazy, is written
+ # sensibly.
+ report = {'id': 'OOPS-1234'}
+ self.assertEqual([
+ "Oops-Id: OOPS-1234\n",
+ "\n"
+ ], to_chunks(report))
=== modified file 'setup.py'
--- setup.py 2011-08-10 08:22:19 +0000
+++ setup.py 2011-08-15 04:50:23 +0000
@@ -22,7 +22,7 @@
description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
setup(name="oops",
- version="0.0.2",
+ version="0.0.3",
description="OOPS report model and default allocation/[de]serialization.",
long_description=description,
maintainer="Launchpad Developers",