/usr/lib/python2.7/dist-packages/oops_datedir_repo/serializer_bson.py is in python-oops-datedir-repo 0.0.17-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | # Copyright (c) 2011, Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, version 3 only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# GNU Lesser General Public License version 3 (see the file LICENSE).
"""Read / Write an OOPS dict as a bson dict.
This style of OOPS format is very extensible and maintains compatability with
older rfc822 oops code: the previously mandatory keys are populated on read.
Use of bson serializing is recommended.
The reports this serializer handles always have the following variables (See
the python-oops api docs for more information about these variables):
* id: The name of this error report.
* type: The type of the exception that occurred.
* value: The value of the exception that occurred.
* time: The time at which the exception occurred.
* reporter: The reporting program.
* topic: The identifier for the template/script that oopsed.
* branch_nick: The branch nickname.
* revno: The revision number of the branch.
* tb_text: A text version of the traceback.
* username: The user associated with the request.
* url: The URL for the failed request.
* req_vars: The request variables. Either a list of 2-tuples or a dict.
* branch_nick: A name for the branch of code that was running when the report
was triggered.
* revno: The revision that the branch was at.
"""
__all__ = [
'dumps',
'read',
'write',
]
__metaclass__ = type
import anybson as bson
def read(fp):
"""Deserialize an OOPS from a bson message."""
report = bson.loads(fp.read())
for key in (
'branch_nick', 'revno', 'type', 'value', 'time', 'topic',
'username', 'url'):
report.setdefault(key, None)
report.setdefault('duration', -1)
report.setdefault('req_vars', {})
report.setdefault('tb_text', '')
report.setdefault('timeline', [])
return report
def dumps(report):
"""Return a binary string representing report."""
return bson.dumps(report)
def write(report, fp):
"""Write report to fp."""
return fp.write(dumps(report))
|