~statik/+junk/django_bookmarks

« back to all changes in this revision

Viewing changes to dbgp/common.py

  • Committer: Elliot Murphy
  • Date: 2008-05-05 19:56:33 UTC
  • Revision ID: elliot@elliotmurphy.com-20080505195633-2lchy07vdf8jp8k5
don't want the komodo plat-specific debugger module in bzr
added empty __init__.py so django_bookmarks is a valid module.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# Copyright (c) 2003-2006 ActiveState Software Inc.
3
 
#
4
 
# The MIT License
5
 
#
6
 
# Permission is hereby granted, free of charge, to any person obtaining
7
 
# a copy of this software and associated documentation files
8
 
# (the "Software"), to deal in the Software without restriction,
9
 
# including without limitation the rights to use, copy, modify,
10
 
# merge, publish, distribute, sublicense, and/or sell copies of the
11
 
# Software, and to permit persons to whom the Software is furnished
12
 
# to do so, subject to the following conditions:
13
 
#
14
 
# The above copyright notice and this permission notice shall be included
15
 
# in all copies or substantial portions of the Software.
16
 
#
17
 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18
 
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
 
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
 
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
 
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
 
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
 
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 
#
25
 
#
26
 
# Authors:
27
 
#    Shane Caraveo <ShaneC@ActiveState.com>
28
 
#    Trent Mick <TrentM@ActiveState.com>
29
 
 
30
 
import sys, os
31
 
try:
32
 
    import logging
33
 
except ImportError:
34
 
    from dbgp import _logging as logging
35
 
 
36
 
# insert a frame flag for ourselves.  This flag is used to drop frames from
37
 
# the stack that we wouldn't want to normally see.  See
38
 
# dbgpClient.get_stack
39
 
DBGPHide = 1
40
 
DBGPFullTraceback = 0
41
 
 
42
 
# hide children gets set when writing stdout.  This prevents deeper stack levels
43
 
# that stdout uses from showing up in the stack frame and causing breaks in weird
44
 
# places
45
 
DBGPHideChildren = 0
46
 
 
47
 
# if set allows stepping into parts of this file.
48
 
#  0 - dont allow (default)
49
 
#  1 - allow, but not the io streams
50
 
#  2 - allow plus the io streams
51
 
DBGPDebugDebugger = 0
52
 
 
53
 
 
54
 
# error codes
55
 
ERROR_OK                        = 0
56
 
ERROR_COMMAND_PARSE             = 1
57
 
ERROR_DUPLICATE_ARGS            = 2
58
 
ERROR_INVALID_ARGS              = 3
59
 
ERROR_COMMAND_NOT_SUPPORTED     = 4
60
 
ERROR_COMMAND_NOT_AVAILABLE     = 5
61
 
ERROR_FILE_ACCESS               = 100
62
 
ERROR_STREAM_REDIRECT_FAILED    = 101
63
 
ERROR_BREAKPOINT_INVALID        = 200
64
 
ERROR_BREAKPOINT_TYPE           = 201
65
 
ERROR_BREAKPOINT_INVALID_LINE   = 202
66
 
ERROR_BREAKPOINT_NOT_REACHABLE  = 203
67
 
ERROR_BREAKPOINT_STATE          = 204
68
 
ERROR_BREAKPOINT_DOES_NOT_EXIST = 205
69
 
ERROR_EVAL_FAILED               = 206
70
 
ERROR_INVALID_EXPRESSION        = 207
71
 
ERROR_PROPERTY_DOES_NOT_EXIST   = 300
72
 
ERROR_STACK_DEPTH               = 301
73
 
ERROR_CONTEXT_INVALID           = 302
74
 
ERROR_ENCODING                  = 900
75
 
ERROR_EXCEPTION                 = 998
76
 
ERROR_UNKNOWN                   = 999
77
 
 
78
 
 
79
 
DBGP_VERSION = '1.0'
80
 
 
81
 
MAX_CHILDREN = 10
82
 
MAX_DATA     = 256
83
 
MAX_DEPTH    = 1
84
 
SHOW_HIDDEN  = 0
85
 
 
86
 
 
87
 
# status types
88
 
STATUS_STARTING    = 0
89
 
STATUS_STOPPING    = 1
90
 
STATUS_STOPPED     = 2
91
 
STATUS_RUNNING     = 3
92
 
STATUS_BREAK       = 4
93
 
STATUS_INTERACTIVE = 5
94
 
 
95
 
status_names = ['starting', 'stopping', 'stopped', 'running', 'break', 'interactive']
96
 
 
97
 
# status reason types
98
 
REASON_OK        = 0
99
 
REASON_ERROR     = 1
100
 
REASON_ABORTED   = 2
101
 
REASON_EXCEPTION = 3
102
 
 
103
 
reason_names = ['ok' , 'error', 'aborted', 'exception']
104
 
 
105
 
RESUME_STOP = 0 # session terminated.
106
 
RESUME_STEP_IN = 1 # step into things.
107
 
RESUME_STEP_OVER = 2 # step over current thing
108
 
RESUME_STEP_OUT = 3 # step out of current thing.
109
 
RESUME_GO = 4 # go for it.
110
 
RESUME_INTERACTIVE = 5 # go for it.
111
 
 
112
 
resume_command_names = ['stop', 'step_into', 'step_over', 'step_out', 'run', 'interact']
113
 
 
114
 
def getenv(key, default=None):
115
 
    try:
116
 
        if not hasattr(os, 'getenv'):
117
 
            # on Symbian, getenv doesn't exist! (AttributeError)
118
 
            return default
119
 
        retval = os.getenv(key)
120
 
        if retval is None:
121
 
            return default
122
 
    except KeyError:
123
 
        # on Jython, one gets an exception instead of None back
124
 
        return default
125
 
    return retval
126
 
 
127
 
class DBGPError(Exception):
128
 
    pass
129
 
 
130
 
class DBGPQuit(Exception):
131
 
    """DBGPQuit
132
 
    
133
 
    an exception thrown to quit debugging
134
 
    """
135
 
 
136
 
__log_configured = 0
137
 
def configureLogging(log, level = logging.INFO):
138
 
    global __log_configured
139
 
    if __log_configured:
140
 
        return
141
 
    __log_configured = 1
142
 
    
143
 
    class DBGPFormatter(logging.Formatter):
144
 
        """Logging formatter to prefix log level name to all log output
145
 
        *except* normal INFO level logs.
146
 
        """
147
 
        def format(self, record):
148
 
            s = logging.Formatter.format(self, record)
149
 
            #if record.levelno != logging.INFO:
150
 
            s = "%s: %s: %s" % (record.levelname, record.name, s)
151
 
            return s
152
 
 
153
 
    hdlr = logging.StreamHandler()
154
 
    fmtr = DBGPFormatter()
155
 
    hdlr.setFormatter(fmtr)
156
 
    log.addHandler(hdlr)
157
 
    log.setLevel(level)