35
35
removes = []
36
36
response_sizes = []
37
37
38
+
38
39
# Wrap helpers._unpack_response for getting response size
39
40
@functools .wraps (_original_methods ['_unpack_response' ])
40
41
def _unpack_response (response , * args , ** kwargs ):
@@ -47,6 +48,7 @@ def _unpack_response(response, *args, **kwargs):
47
48
response_sizes .append (sys .getsizeof (response ) / 1024.0 )
48
49
return result
49
50
51
+
50
52
# Wrap Cursor.insert for getting queries
51
53
@functools .wraps (_original_methods ['insert' ])
52
54
def _insert (collection_self , doc_or_docs , manipulate = True ,
@@ -61,7 +63,7 @@ def _insert(collection_self, doc_or_docs, manipulate=True,
61
63
)
62
64
total_time = (time .time () - start_time ) * 1000
63
65
64
- __traceback_hide__ = True
66
+ __traceback_hide__ = True # noqa
65
67
stack_trace , internal = _tidy_stacktrace ()
66
68
inserts .append ({
67
69
'document' : doc_or_docs ,
@@ -73,6 +75,7 @@ def _insert(collection_self, doc_or_docs, manipulate=True,
73
75
})
74
76
return result
75
77
78
+
76
79
# Wrap Cursor.update for getting queries
77
80
@functools .wraps (_original_methods ['update' ])
78
81
def _update (collection_self , spec , document , upsert = False ,
@@ -89,7 +92,7 @@ def _update(collection_self, spec, document, upsert=False,
89
92
)
90
93
total_time = (time .time () - start_time ) * 1000
91
94
92
- __traceback_hide__ = True
95
+ __traceback_hide__ = True # noqa
93
96
stack_trace , internal = _tidy_stacktrace ()
94
97
updates .append ({
95
98
'document' : document ,
@@ -104,6 +107,7 @@ def _update(collection_self, spec, document, upsert=False,
104
107
})
105
108
return result
106
109
110
+
107
111
# Wrap Cursor.remove for getting queries
108
112
@functools .wraps (_original_methods ['remove' ])
109
113
def _remove (collection_self , spec_or_id , safe = None , ** kwargs ):
@@ -116,7 +120,7 @@ def _remove(collection_self, spec_or_id, safe=None, **kwargs):
116
120
)
117
121
total_time = (time .time () - start_time ) * 1000
118
122
119
- __traceback_hide__ = True
123
+ __traceback_hide__ = True # noqa
120
124
stack_trace , internal = _tidy_stacktrace ()
121
125
removes .append ({
122
126
'spec_or_id' : spec_or_id ,
@@ -128,6 +132,7 @@ def _remove(collection_self, spec_or_id, safe=None, **kwargs):
128
132
})
129
133
return result
130
134
135
+
131
136
# Wrap Cursor._refresh for getting queries
132
137
@functools .wraps (_original_methods ['refresh' ])
133
138
def _cursor_refresh (cursor_self ):
@@ -169,11 +174,11 @@ def privar(name):
169
174
if snapshot :
170
175
query_son ["$snapshot" ] = snapshot
171
176
172
- maxScan = privar ("max_scan" )
177
+ maxScan = privar ("max_scan" ) # noqa
173
178
if maxScan :
174
179
query_son ["$maxScan" ] = maxScan
175
180
176
- __traceback_hide__ = True
181
+ __traceback_hide__ = True # noqa
177
182
stack_trace , internal = _tidy_stacktrace ()
178
183
query_data = {
179
184
'time' : total_time ,
@@ -209,6 +214,7 @@ def privar(name):
209
214
210
215
return result
211
216
217
+
212
218
def install_tracker ():
213
219
if pymongo .collection .Collection .insert != _insert :
214
220
pymongo .collection .Collection .insert = _insert
@@ -221,6 +227,7 @@ def install_tracker():
221
227
if pymongo .helpers ._unpack_response != _unpack_response :
222
228
pymongo .helpers ._unpack_response = _unpack_response
223
229
230
+
224
231
def uninstall_tracker ():
225
232
if pymongo .collection .Collection .insert == _insert :
226
233
pymongo .collection .Collection .insert = _original_methods ['insert' ]
@@ -231,7 +238,9 @@ def uninstall_tracker():
231
238
if pymongo .cursor .Cursor ._refresh == _cursor_refresh :
232
239
pymongo .cursor .Cursor ._refresh = _original_methods ['cursor_refresh' ]
233
240
if pymongo .helpers ._unpack_response == _unpack_response :
234
- pymongo .helpers ._unpack_response = _original_methods ['_unpack_response' ]
241
+ pymongo .helpers ._unpack_response = _original_methods [
242
+ '_unpack_response' ]
243
+
235
244
236
245
def reset ():
237
246
global queries , inserts , updates , removes , response_sizes
@@ -241,6 +250,7 @@ def reset():
241
250
removes = []
242
251
response_sizes = []
243
252
253
+
244
254
def _get_ordering (son ):
245
255
"""Helper function to extract formatted ordering from dict.
246
256
"""
@@ -250,11 +260,13 @@ def fmt(field, direction):
250
260
if '$orderby' in son :
251
261
return ', ' .join (fmt (f , d ) for f , d in son ['$orderby' ].items ())
252
262
263
+
253
264
def _tidy_stacktrace ():
254
265
"""
255
266
Tidy the stack_trace
256
267
"""
257
- socketserver_path = os .path .realpath (os .path .dirname (SocketServer .__file__ ))
268
+ socketserver_path = os .path .realpath (
269
+ os .path .dirname (SocketServer .__file__ ))
258
270
pymongo_path = os .path .realpath (os .path .dirname (pymongo .__file__ ))
259
271
paths = ['/site-packages/' , '/flaskext/' , socketserver_path , pymongo_path ]
260
272
internal = False
0 commit comments