OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 | 8 |
9 import 'package:async/async.dart' hide StreamQueue; | 9 import 'package:async/async.dart' hide StreamQueue; |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return buffer.toString(); | 156 return buffer.toString(); |
157 }).join("\n"); | 157 }).join("\n"); |
158 } | 158 } |
159 | 159 |
160 /// A regular expression matching terminal color codes. | 160 /// A regular expression matching terminal color codes. |
161 final _colorCode = new RegExp('\u001b\\[[0-9;]+m'); | 161 final _colorCode = new RegExp('\u001b\\[[0-9;]+m'); |
162 | 162 |
163 /// Returns [str] without any color codes. | 163 /// Returns [str] without any color codes. |
164 String withoutColors(String str) => str.replaceAll(_colorCode, ''); | 164 String withoutColors(String str) => str.replaceAll(_colorCode, ''); |
165 | 165 |
166 /// A regular expression matching the path to a temporary file used to start an | |
167 /// isolate. | |
168 /// | |
169 /// These paths aren't relevant and are removed from stack traces. | |
170 final _isolatePath = | |
171 new RegExp(r"/test_[A-Za-z0-9]{6}/runInIsolate\.dart$"); | |
172 | |
173 /// Returns [stackTrace] converted to a [Chain] with all irrelevant frames | 166 /// Returns [stackTrace] converted to a [Chain] with all irrelevant frames |
174 /// folded together. | 167 /// folded together. |
175 /// | 168 /// |
176 /// If [verbose] is `true`, returns the chain for [stackTrace] unmodified. | 169 /// If [verbose] is `true`, returns the chain for [stackTrace] unmodified. |
177 Chain terseChain(StackTrace stackTrace, {bool verbose: false}) { | 170 Chain terseChain(StackTrace stackTrace, {bool verbose: false}) { |
178 if (verbose) return new Chain.forTrace(stackTrace); | 171 if (verbose) return new Chain.forTrace(stackTrace); |
179 return new Chain.forTrace(stackTrace).foldFrames((frame) { | 172 return new Chain.forTrace(stackTrace).foldFrames((frame) => |
180 if (frame.package == 'test') return true; | 173 frame.package == 'test' || frame.package == 'stream_channel', |
181 if (frame.package == 'stream_channel') return true; | 174 terse: true); |
182 | |
183 // Filter out frames from our isolate bootstrap as well. | |
184 if (frame.uri.scheme != 'file') return false; | |
185 return frame.uri.path.contains(_isolatePath); | |
186 }, terse: true); | |
187 } | 175 } |
188 | 176 |
189 /// Flattens nested [Iterable]s inside an [Iterable] into a single [List] | 177 /// Flattens nested [Iterable]s inside an [Iterable] into a single [List] |
190 /// containing only non-[Iterable] elements. | 178 /// containing only non-[Iterable] elements. |
191 List flatten(Iterable nested) { | 179 List flatten(Iterable nested) { |
192 var result = []; | 180 var result = []; |
193 helper(iter) { | 181 helper(iter) { |
194 for (var element in iter) { | 182 for (var element in iter) { |
195 if (element is Iterable) { | 183 if (element is Iterable) { |
196 helper(element); | 184 helper(element); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 return BASE64.encode(data); | 424 return BASE64.encode(data); |
437 } | 425 } |
438 | 426 |
439 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. | 427 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. |
440 shelf.Middleware nestingMiddleware(String beneath) { | 428 shelf.Middleware nestingMiddleware(String beneath) { |
441 return (handler) { | 429 return (handler) { |
442 var pathHandler = new PathHandler()..add(beneath, handler); | 430 var pathHandler = new PathHandler()..add(beneath, handler); |
443 return pathHandler.handler; | 431 return pathHandler.handler; |
444 }; | 432 }; |
445 } | 433 } |
OLD | NEW |