Show More
@@ -437,9 +437,12 b' style_url = Style(COLOR_GREEN, COLOR_BLACK)' | |||||
437 | # Style for ellipsis (when an output has been shortened |
|
437 | # Style for ellipsis (when an output has been shortened | |
438 | style_ellisis = Style(COLOR_RED, COLOR_BLACK) |
|
438 | style_ellisis = Style(COLOR_RED, COLOR_BLACK) | |
439 |
|
439 | |||
440 |
# Style for displaying e |
|
440 | # Style for displaying exceptions | |
441 | style_error = Style(COLOR_RED, COLOR_BLACK) |
|
441 | style_error = Style(COLOR_RED, COLOR_BLACK) | |
442 |
|
442 | |||
|
443 | # Style for displaying non-existing attributes | |||
|
444 | style_nodata = Style(COLOR_RED, COLOR_BLACK) | |||
|
445 | ||||
443 |
|
446 | |||
444 | def xrepr(item, mode): |
|
447 | def xrepr(item, mode): | |
445 | try: |
|
448 | try: | |
@@ -1342,32 +1345,57 b' class ifilter(Pipe):' | |||||
1342 | evaluates to true (and doesn't raise an exception) are listed. |
|
1345 | evaluates to true (and doesn't raise an exception) are listed. | |
1343 | """ |
|
1346 | """ | |
1344 |
|
1347 | |||
1345 | def __init__(self, expr): |
|
1348 | def __init__(self, expr, errors="raiseifallfail"): | |
1346 | """ |
|
1349 | """ | |
1347 | Create an ``ifilter`` object. ``expr`` can be a callable or a string |
|
1350 | Create an ``ifilter`` object. ``expr`` can be a callable or a string | |
1348 | containing an expression. |
|
1351 | containing an expression. ``errors`` specifies how exception during | |
|
1352 | evaluation of ``expr`` are handled: | |||
|
1353 | ||||
|
1354 | * ``drop``: drop all items that have errors; | |||
|
1355 | ||||
|
1356 | * ``keep``: keep all items that have errors; | |||
|
1357 | ||||
|
1358 | * ``keeperror``: keep the exception of all items that have errors; | |||
|
1359 | ||||
|
1360 | * ``raise``: raise the exception; | |||
|
1361 | ||||
|
1362 | * ``raiseifallfail``: raise the first exception if all items have errors; | |||
|
1363 | otherwise drop those with errors (this is the default). | |||
1349 | """ |
|
1364 | """ | |
1350 | self.expr = expr |
|
1365 | self.expr = expr | |
|
1366 | self.errors = errors | |||
1351 |
|
1367 | |||
1352 | def __xiter__(self, mode): |
|
1368 | def __xiter__(self, mode): | |
1353 | if callable(self.expr): |
|
1369 | if callable(self.expr): | |
1354 | for item in xiter(self.input, mode): |
|
1370 | def test(item): | |
1355 |
|
|
1371 | return self.expr(item) | |
1356 | if self.expr(item): |
|
|||
1357 | yield item |
|
|||
1358 | except (KeyboardInterrupt, SystemExit): |
|
|||
1359 | raise |
|
|||
1360 | except Exception: |
|
|||
1361 | pass # Ignore errors |
|
|||
1362 | else: |
|
1372 | else: | |
1363 | for item in xiter(self.input, mode): |
|
1373 | def test(item): | |
1364 | try: |
|
1374 | return eval(self.expr, globals(), _AttrNamespace(item)) | |
1365 | if eval(self.expr, globals(), _AttrNamespace(item)): |
|
1375 | ||
1366 | yield item |
|
1376 | ok = 0 | |
1367 | except (KeyboardInterrupt, SystemExit): |
|
1377 | exc_info = None | |
1368 | raise |
|
1378 | for item in xiter(self.input, mode): | |
1369 | except Exception: |
|
1379 | try: | |
|
1380 | if test(item): | |||
|
1381 | yield item | |||
|
1382 | ok += 1 | |||
|
1383 | except (KeyboardInterrupt, SystemExit): | |||
|
1384 | raise | |||
|
1385 | except Exception, exc: | |||
|
1386 | if self.errors == "drop": | |||
1370 | pass # Ignore errors |
|
1387 | pass # Ignore errors | |
|
1388 | elif self.errors == "keep": | |||
|
1389 | yield item | |||
|
1390 | elif self.errors == "keeperror": | |||
|
1391 | yield exc | |||
|
1392 | elif self.errors == "raise": | |||
|
1393 | raise | |||
|
1394 | elif self.errors == "raiseifallfail": | |||
|
1395 | if exc_info is None: | |||
|
1396 | exc_info = sys.exc_info() | |||
|
1397 | if not ok and exc_info is not None: | |||
|
1398 | raise exc_info[0], exc_info[1], exc_info[2] | |||
1371 |
|
1399 | |||
1372 | def __xrepr__(self, mode): |
|
1400 | def __xrepr__(self, mode): | |
1373 | yield (-1, True) |
|
1401 | yield (-1, True) | |
@@ -1395,30 +1423,43 b' class ieval(Pipe):' | |||||
1395 | This ``Pipe`` evaluates an expression for each object in the input pipe. |
|
1423 | This ``Pipe`` evaluates an expression for each object in the input pipe. | |
1396 | """ |
|
1424 | """ | |
1397 |
|
1425 | |||
1398 | def __init__(self, expr): |
|
1426 | def __init__(self, expr, errors="raiseifallfail"): | |
1399 | """ |
|
1427 | """ | |
1400 | Create an ``ieval`` object. ``expr`` can be a callable or a string |
|
1428 | Create an ``ieval`` object. ``expr`` can be a callable or a string | |
1401 | containing an expression. |
|
1429 | containing an expression. For the meaning of ``errors`` see ``ifilter``. | |
1402 | """ |
|
1430 | """ | |
1403 | self.expr = expr |
|
1431 | self.expr = expr | |
|
1432 | self.errors = errors | |||
1404 |
|
1433 | |||
1405 | def __xiter__(self, mode): |
|
1434 | def __xiter__(self, mode): | |
1406 | if callable(self.expr): |
|
1435 | if callable(self.expr): | |
1407 | for item in xiter(self.input, mode): |
|
1436 | def do(item): | |
1408 |
|
|
1437 | return self.expr(item) | |
1409 | yield self.expr(item) |
|
|||
1410 | except (KeyboardInterrupt, SystemExit): |
|
|||
1411 | raise |
|
|||
1412 | except Exception: |
|
|||
1413 | pass # Ignore errors |
|
|||
1414 | else: |
|
1438 | else: | |
1415 | for item in xiter(self.input, mode): |
|
1439 | def do(item): | |
1416 | try: |
|
1440 | return eval(self.expr, globals(), _AttrNamespace(item)) | |
1417 | yield eval(self.expr, globals(), _AttrNamespace(item)) |
|
1441 | ||
1418 | except (KeyboardInterrupt, SystemExit): |
|
1442 | ok = 0 | |
1419 | raise |
|
1443 | exc_info = None | |
1420 | except Exception: |
|
1444 | for item in xiter(self.input, mode): | |
|
1445 | try: | |||
|
1446 | yield do(item) | |||
|
1447 | except (KeyboardInterrupt, SystemExit): | |||
|
1448 | raise | |||
|
1449 | except Exception, exc: | |||
|
1450 | if self.errors == "drop": | |||
1421 | pass # Ignore errors |
|
1451 | pass # Ignore errors | |
|
1452 | elif self.errors == "keep": | |||
|
1453 | yield item | |||
|
1454 | elif self.errors == "keeperror": | |||
|
1455 | yield exc | |||
|
1456 | elif self.errors == "raise": | |||
|
1457 | raise | |||
|
1458 | elif self.errors == "raiseifallfail": | |||
|
1459 | if exc_info is None: | |||
|
1460 | exc_info = sys.exc_info() | |||
|
1461 | if not ok and exc_info is not None: | |||
|
1462 | raise exc_info[0], exc_info[1], exc_info[2] | |||
1422 |
|
1463 | |||
1423 | def __xrepr__(self, mode): |
|
1464 | def __xrepr__(self, mode): | |
1424 | yield (-1, True) |
|
1465 | yield (-1, True) | |
@@ -2225,7 +2266,6 b' if curses is not None:' | |||||
2225 | style_data = Style(COLOR_WHITE, COLOR_BLACK) |
|
2266 | style_data = Style(COLOR_WHITE, COLOR_BLACK) | |
2226 | style_datapad = Style(COLOR_BLUE, COLOR_BLACK, A_BOLD) |
|
2267 | style_datapad = Style(COLOR_BLUE, COLOR_BLACK, A_BOLD) | |
2227 | style_footer = Style(COLOR_BLACK, COLOR_WHITE) |
|
2268 | style_footer = Style(COLOR_BLACK, COLOR_WHITE) | |
2228 | style_noattr = Style(COLOR_RED, COLOR_BLACK) |
|
|||
2229 | style_report = Style(COLOR_WHITE, COLOR_BLACK) |
|
2269 | style_report = Style(COLOR_WHITE, COLOR_BLACK) | |
2230 |
|
2270 | |||
2231 | # Column separator in header |
|
2271 | # Column separator in header | |
@@ -2887,6 +2927,7 b' if curses is not None:' | |||||
2887 | (align, length, parts) = level.displayrows[i-level.datastarty][attrname] |
|
2927 | (align, length, parts) = level.displayrows[i-level.datastarty][attrname] | |
2888 | except KeyError: |
|
2928 | except KeyError: | |
2889 | align = 2 |
|
2929 | align = 2 | |
|
2930 | style = style_nodata | |||
2890 | padstyle = self.style_datapad |
|
2931 | padstyle = self.style_datapad | |
2891 | sepstyle = self.style_sep |
|
2932 | sepstyle = self.style_sep | |
2892 | if i == level.cury: |
|
2933 | if i == level.cury: |
General Comments 0
You need to be logged in to leave comments.
Login now