/usr/share/pyshared/cyclone/util.py is in python-cyclone 1.1-1.
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 | # coding: utf-8
#
# Copyright 2010 Alexandre Fiori
# based on the original Tornado by Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from twisted.python import log
def _emit(self, eventDict):
text = log.textFromEventDict(eventDict)
if not text:
return
#print "hello? '%s'" % repr(text)
timeStr = self.formatTime(eventDict['time'])
#fmtDict = {'system': eventDict['system'],
# 'text': text.replace("\n", "\n\t")}
#msgStr = log._safeFormat("[%(system)s] %(text)s\n", fmtDict)
log.util.untilConcludes(self.write, "%s %s\n" % (timeStr,
text.replace("\n", "\n\t")))
log.util.untilConcludes(self.flush) # Hoorj!
# monkey patch, sorry
log.FileLogObserver.emit = _emit
class ObjectDict(dict):
"""Makes a dictionary behave like an object."""
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
def __setattr__(self, name, value):
self[name] = value
def import_object(name):
"""Imports an object by name.
import_object('x.y.z') is equivalent to 'from x.y import z'.
>>> import cyclone.escape
>>> import_object('cyclone.escape') is cyclone.escape
True
>>> import_object('cyclone.escape.utf8') is cyclone.escape.utf8
True
"""
parts = name.split('.')
obj = __import__('.'.join(parts[:-1]), None, None, [parts[-1]], 0)
method = getattr(obj, parts[-1], None)
if method:
return method
else:
raise ImportError("No method named %s" % parts[-1])
# Fake byte literal support: In python 2.6+, you can say b"foo" to get
# a byte literal (str in 2.x, bytes in 3.x). There's no way to do this
# in a way that supports 2.5, though, so we need a function wrapper
# to convert our string literals. b() should only be applied to literal
# latin1 strings. Once we drop support for 2.5, we can remove this function
# and just use byte literals.
#def b(s):
# return s
#
#def u(s):
# return s.decode('unicode_escape')
bytes_type = str
unicode_type = unicode
basestring_type = basestring
def doctests():
import doctest
return doctest.DocTestSuite()
|