/usr/lib/python2.7/dist-packages/telepathy/server/debug.py is in python-telepathy 0.15.19-3.
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | # telepathy-python - Base classes defining the interfaces of the Telepathy framework
#
# Copyright (C) 2009 Collabora Limited
#
# This library 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; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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 library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from telepathy.interfaces import DEBUG
from telepathy.constants import (DEBUG_LEVEL_ERROR,
DEBUG_LEVEL_CRITICAL,
DEBUG_LEVEL_WARNING,
DEBUG_LEVEL_INFO,
DEBUG_LEVEL_DEBUG)
from telepathy._generated.Debug import Debug as _Debug
from telepathy.server.properties import DBusProperties
import dbus.service
import logging
import sys
import time
LEVELS = {
logging.ERROR: DEBUG_LEVEL_ERROR,
logging.FATAL: DEBUG_LEVEL_CRITICAL,
logging.WARNING: DEBUG_LEVEL_WARNING,
logging.INFO: DEBUG_LEVEL_INFO,
logging.DEBUG: DEBUG_LEVEL_DEBUG,
logging.NOTSET: DEBUG_LEVEL_DEBUG
}
DEBUG_MESSAGE_LIMIT = 800
class Debug(_Debug, DBusProperties, logging.Handler):
def __init__(self, conn_manager, root=''):
self.enabled = False
self._interfaces = set()
self._messages = []
object_path = '/org/freedesktop/Telepathy/debug'
_Debug.__init__(self, conn_manager._name, object_path)
DBusProperties.__init__(self)
logging.Handler.__init__(self)
self._implement_property_get(DEBUG, {'Enabled': lambda: self.enabled})
self._implement_property_set(DEBUG, {'Enabled': self._set_enabled})
logging.getLogger(root).addHandler(self)
sys.stderr = StdErrWrapper(self, sys.stderr)
def _set_enabled(self, value):
self.enabled = value
def GetMessages(self):
return self._messages
def add_message(self, timestamp, name, level, msg):
if len(self._messages) >= DEBUG_MESSAGE_LIMIT:
self._messages.pop()
self._messages.append((timestamp, name, level, msg))
if self.enabled:
self.NewDebugMessage(timestamp, name, level, msg)
# Handle logging module messages
def emit(self, record):
name = self.get_record_name(record)
level = self.get_record_level(record)
self.add_message(record.created, name, level, record.msg)
def get_record_level(self, record):
return LEVELS[record.levelno]
def get_record_name(self, record):
name = record.name
if name.contains("."):
domain, category = record.name.split('.', 1)
name = domain + "/" + category
return name
# Wrapper around stderr so the exceptions are logged
class StdErrWrapper(object):
def __init__(self, interface, stderr):
self._buffer = ""
self._interface = interface
self._stderr = stderr
def __getattr__(self, attr):
return getattr(self._stderr, attr)
def write(self, string):
self._stderr.write(string)
if '\n' not in string:
self._buffer += string
return
lines = string.split('\n')
lines[0] = self._buffer + lines[0]
self._buffer = lines[-1]
del lines[-1]
timestamp = time.time()
for line in lines:
self._interface.add_message(timestamp, "stderr", DEBUG_LEVEL_ERROR, line)
|