18
18
19
19
import functools
20
20
21
- from newrelic .api .function_trace import (FunctionTrace , FunctionTraceWrapper ,
22
- wrap_function_trace )
21
+ from newrelic .api .function_trace import (
22
+ FunctionTrace ,
23
+ FunctionTraceWrapper ,
24
+ wrap_function_trace ,
25
+ )
23
26
from newrelic .api .transaction import current_transaction
24
27
from newrelic .api .wsgi_application import wrap_wsgi_application
25
28
from newrelic .common .object_names import callable_name
26
- from newrelic .common .object_wrapper import (wrap_out_function ,
27
- function_wrapper , ObjectProxy , wrap_object_attribute ,
28
- wrap_function_wrapper )
29
+ from newrelic .common .object_wrapper import (
30
+ ObjectProxy ,
31
+ function_wrapper ,
32
+ wrap_function_wrapper ,
33
+ wrap_object_attribute ,
34
+ wrap_out_function ,
35
+ )
29
36
30
37
module_bottle = None
31
38
@@ -34,17 +41,17 @@ def status_code(exc, value, tb):
34
41
# The HTTPError class derives from HTTPResponse and so we do not
35
42
# need to check for it seperately as isinstance() will pick it up.
36
43
37
- if isinstance (value , module_bottle .HTTPResponse ):
38
- if hasattr (value , ' status_code' ):
44
+ if isinstance (value , module_bottle .HTTPResponse ): # pragma: no cover
45
+ if hasattr (value , " status_code" ):
39
46
return value .status_code
40
- elif hasattr (value , ' status' ):
47
+ elif hasattr (value , " status" ):
41
48
return value .status
42
- elif hasattr (value , ' http_status_code' ):
49
+ elif hasattr (value , " http_status_code" ):
43
50
return value .http_status_code
44
51
45
52
46
53
def should_ignore (exc , value , tb ):
47
- if hasattr (module_bottle , ' RouteReset' ):
54
+ if hasattr (module_bottle , " RouteReset" ):
48
55
if isinstance (value , module_bottle .RouteReset ):
49
56
return True
50
57
@@ -113,8 +120,7 @@ def get(self, status, default=None):
113
120
transaction .set_transaction_name (name , priority = 1 )
114
121
handler = FunctionTraceWrapper (handler , name = name )
115
122
else :
116
- transaction .set_transaction_name (str (status ),
117
- group = 'StatusCode' , priority = 1 )
123
+ transaction .set_transaction_name (str (status ), group = "StatusCode" , priority = 1 )
118
124
119
125
return handler or default
120
126
@@ -140,43 +146,39 @@ def instrument_bottle(module):
140
146
global module_bottle
141
147
module_bottle = module
142
148
143
- framework_details = ('Bottle' , getattr (module , '__version__' ))
144
-
145
- if hasattr (module .Bottle , 'wsgi' ): # version >= 0.9
146
- wrap_wsgi_application (module , 'Bottle.wsgi' ,
147
- framework = framework_details )
148
- elif hasattr (module .Bottle , '__call__' ): # version < 0.9
149
- wrap_wsgi_application (module , 'Bottle.__call__' ,
150
- framework = framework_details )
151
-
152
- if (hasattr (module , 'Route' ) and
153
- hasattr (module .Route , '_make_callback' )): # version >= 0.10
154
- wrap_out_function (module , 'Route._make_callback' ,
155
- output_wrapper_Route_make_callback )
156
- elif hasattr (module .Bottle , '_match' ): # version >= 0.9
157
- wrap_out_function (module , 'Bottle._match' ,
158
- output_wrapper_Bottle_match )
159
- elif hasattr (module .Bottle , 'match_url' ): # version < 0.9
160
- wrap_out_function (module , 'Bottle.match_url' ,
161
- output_wrapper_Bottle_match )
162
-
163
- wrap_object_attribute (module , 'Bottle.error_handler' ,
164
- proxy_Bottle_error_handler )
165
-
166
- if hasattr (module , 'auth_basic' ):
167
- wrap_function_wrapper (module , 'auth_basic' , wrapper_auth_basic )
168
-
169
- if hasattr (module , 'SimpleTemplate' ):
170
- wrap_function_trace (module , 'SimpleTemplate.render' )
171
-
172
- if hasattr (module , 'MakoTemplate' ):
173
- wrap_function_trace (module , 'MakoTemplate.render' )
174
-
175
- if hasattr (module , 'CheetahTemplate' ):
176
- wrap_function_trace (module , 'CheetahTemplate.render' )
177
-
178
- if hasattr (module , 'Jinja2Template' ):
179
- wrap_function_trace (module , 'Jinja2Template.render' )
180
-
181
- if hasattr (module , 'SimpleTALTemplate' ):
182
- wrap_function_trace (module , 'SimpleTALTemplate.render' )
149
+ framework_details = ("Bottle" , getattr (module , "__version__" ))
150
+ # version >= 0.9
151
+ if hasattr (module .Bottle , "wsgi" ): # pragma: no cover
152
+ wrap_wsgi_application (module , "Bottle.wsgi" , framework = framework_details )
153
+ # version < 0.9
154
+ elif hasattr (module .Bottle , "__call__" ): # pragma: no cover
155
+ wrap_wsgi_application (module , "Bottle.__call__" , framework = framework_details )
156
+ # version >= 0.10
157
+ if hasattr (module , "Route" ) and hasattr (module .Route , "_make_callback" ): # pragma: no cover
158
+ wrap_out_function (module , "Route._make_callback" , output_wrapper_Route_make_callback )
159
+ # version >= 0.9
160
+ elif hasattr (module .Bottle , "_match" ): # pragma: no cover
161
+ wrap_out_function (module , "Bottle._match" , output_wrapper_Bottle_match )
162
+ # version < 0.9
163
+ elif hasattr (module .Bottle , "match_url" ): # pragma: no cover
164
+ wrap_out_function (module , "Bottle.match_url" , output_wrapper_Bottle_match )
165
+
166
+ wrap_object_attribute (module , "Bottle.error_handler" , proxy_Bottle_error_handler )
167
+
168
+ if hasattr (module , "auth_basic" ):
169
+ wrap_function_wrapper (module , "auth_basic" , wrapper_auth_basic )
170
+
171
+ if hasattr (module , "SimpleTemplate" ):
172
+ wrap_function_trace (module , "SimpleTemplate.render" )
173
+
174
+ if hasattr (module , "MakoTemplate" ):
175
+ wrap_function_trace (module , "MakoTemplate.render" )
176
+
177
+ if hasattr (module , "CheetahTemplate" ):
178
+ wrap_function_trace (module , "CheetahTemplate.render" )
179
+
180
+ if hasattr (module , "Jinja2Template" ):
181
+ wrap_function_trace (module , "Jinja2Template.render" )
182
+
183
+ if hasattr (module , "SimpleTALTemplate" ): # pragma: no cover
184
+ wrap_function_trace (module , "SimpleTALTemplate.render" )
0 commit comments