File: _Debug.py

package info (click to toggle)
clientcookie 0.4.19-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 480 kB
  • ctags: 571
  • sloc: python: 4,213; makefile: 46
file content (43 lines) | stat: -rw-r--r-- 1,199 bytes parent folder | download
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
import ClientCookie

try:
    import warnings
except ImportError:
    def warn(text):
        ClientCookie.DEBUG_STREAM.write("WARNING: "+text)
else:
    def warn(text):
        print "HELLOOOOOOOO!"
        warnings.warn(text, stacklevel=2)

try:
    import logging
except:
    NOTSET = None
    INFO = 20
    DEBUG = 10
    class Logger:
        def __init__(self):
            self.level = NOTSET
        def log(self, level, text, *args):
            if args:
                text = text % args
            if self.level is not None and level < self.level:
                ClientCookie.DEBUG_STREAM.write(text+"\n")
        def debug(self, text, *args):
            apply(self.log, (DEBUG, text)+args)
        def info(self, text, *args):
            apply(self.log, (INFO, text)+args)
        def setLevel(self, lvl):
            self.level = lvl
    LOGGER = Logger()
    def getLogger(name): return LOGGER
else:
    from logging import getLogger, INFO, DEBUG, NOTSET
    getLogger("ClientCookie").addHandler(
        logging.StreamHandler(ClientCookie.DEBUG_STREAM))

## def _debug(text, *args):
##     if args:
##         text = text % args
##     ClientCookie.DEBUG_STREAM.write(text+"\n")