~james-w/python-oops/update-readme-dependencies

« back to all changes in this revision

Viewing changes to oops/serializer_rfc822.py

  • Committer: Robert Collins
  • Date: 2011-08-15 00:34:15 UTC
  • Revision ID: robertc@robertcollins.net-20110815003415-0pn1chcviba91mrg
Permit serialization and deserialisation of much more minimal oops reports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    id = msg.getheader('oops-id')
63
63
    exc_type = msg.getheader('exception-type')
64
64
    exc_value = msg.getheader('exception-value')
65
 
    date = iso8601.parse_date(msg.getheader('date'))
 
65
    datestr = msg.getheader('date')
 
66
    if datestr is not None:
 
67
        date =iso8601.parse_date(msg.getheader('date'))
 
68
    else:
 
69
        date = None
66
70
    pageid = msg.getheader('page-id')
67
71
    username = msg.getheader('user')
68
72
    url = msg.getheader('url')
148
152
    """Returns a list of bytestrings making up the serialized oops."""
149
153
    chunks = []
150
154
    chunks.append('Oops-Id: %s\n' % _normalise_whitespace(report['id']))
151
 
    chunks.append(
152
 
        'Exception-Type: %s\n' % _normalise_whitespace(report['type']))
153
 
    chunks.append(
154
 
        'Exception-Value: %s\n' % _normalise_whitespace(report['value']))
155
 
    chunks.append('Date: %s\n' % report['time'].isoformat())
156
 
    chunks.append('Page-Id: %s\n' % _normalise_whitespace(report['pageid']))
157
 
    chunks.append('Branch: %s\n' % _safestr(report['branch_nick']))
158
 
    chunks.append('Revision: %s\n' % report['revno'])
159
 
    chunks.append('User: %s\n' % _normalise_whitespace(report['username']))
160
 
    chunks.append('URL: %s\n' % _normalise_whitespace(report['url']))
161
 
    chunks.append('Duration: %s\n' % report['duration'])
162
 
    chunks.append('Informational: %s\n' % report['informational'])
 
155
    if 'type' in report:
 
156
        chunks.append(
 
157
            'Exception-Type: %s\n' % _normalise_whitespace(report['type']))
 
158
    if 'value' in report:
 
159
        chunks.append(
 
160
            'Exception-Value: %s\n' % _normalise_whitespace(report['value']))
 
161
    if 'time' in report:
 
162
        chunks.append('Date: %s\n' % report['time'].isoformat())
 
163
    if 'pageid' in report:
 
164
        chunks.append(
 
165
                'Page-Id: %s\n' % _normalise_whitespace(report['pageid']))
 
166
    if 'branch_nick' in report:
 
167
        chunks.append('Branch: %s\n' % _safestr(report['branch_nick']))
 
168
    if 'revno' in report:
 
169
        chunks.append('Revision: %s\n' % report['revno'])
 
170
    if 'username' in report:
 
171
        chunks.append(
 
172
                'User: %s\n' % _normalise_whitespace(report['username']))
 
173
    if 'url' in report:
 
174
        chunks.append('URL: %s\n' % _normalise_whitespace(report['url']))
 
175
    if 'duration' in report:
 
176
        chunks.append('Duration: %s\n' % report['duration'])
 
177
    if 'informational' in report:
 
178
        chunks.append('Informational: %s\n' % report['informational'])
163
179
    chunks.append('\n')
164
180
    safe_chars = ';/\\?:@&+$, ()*!'
165
 
    for key, value in report['req_vars']:
166
 
        chunks.append('%s=%s\n' % (urllib.quote(key, safe_chars),
167
 
                              urllib.quote(value, safe_chars)))
168
 
    chunks.append('\n')
169
 
    for (start, end, database_id, statement) in report['db_statements']:
170
 
        chunks.append('%05d-%05d@%s %s\n' % (
171
 
            start, end, database_id, _normalise_whitespace(statement)))
172
 
    chunks.append('\n')
173
 
    chunks.append(report['tb_text'])
 
181
    if 'req_vars' in report:
 
182
        for key, value in report['req_vars']:
 
183
            chunks.append('%s=%s\n' % (urllib.quote(key, safe_chars),
 
184
                                  urllib.quote(value, safe_chars)))
 
185
        chunks.append('\n')
 
186
    if 'db_statements' in report:
 
187
        for (start, end, database_id, statement) in report['db_statements']:
 
188
            chunks.append('%05d-%05d@%s %s\n' % (
 
189
                start, end, database_id, _normalise_whitespace(statement)))
 
190
        chunks.append('\n')
 
191
    if 'tb_text' in report:
 
192
        chunks.append(report['tb_text'])
174
193
    return chunks
175
194
 
176
195