Show More
@@ -423,6 +423,15 b' class Style(object):' | |||||
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | def __init__(self, fg, bg, attrs=0): |
|
425 | def __init__(self, fg, bg, attrs=0): | |
|
426 | """ | |||
|
427 | Create a ``Style`` object with ``fg`` as the foreground color, | |||
|
428 | ``bg`` as the background color and ``attrs`` as the attributes. | |||
|
429 | ||||
|
430 | Examples: | |||
|
431 | ||||
|
432 | >>> Style(COLOR_RED, COLOR_BLACK) | |||
|
433 | >>> Style(COLOR_YELLOW, COLOR_BLUE, A_BOLD|A_UNDERLINE) | |||
|
434 | """ | |||
426 | self.fg = fg |
|
435 | self.fg = fg | |
427 | self.bg = bg |
|
436 | self.bg = bg | |
428 | self.attrs = attrs |
|
437 | self.attrs = attrs | |
@@ -537,15 +546,15 b' class Text(list):' | |||||
537 | items will be ``(style, string)`` tuples. |
|
546 | items will be ``(style, string)`` tuples. | |
538 | """ |
|
547 | """ | |
539 |
|
548 | |||
|
549 | def __init__(self, *args): | |||
|
550 | list.__init__(self) | |||
|
551 | self.append(*args) | |||
|
552 | ||||
540 | def __repr__(self): |
|
553 | def __repr__(self): | |
541 | return "%s.%s(%s)" % ( |
|
554 | return "%s.%s(%s)" % ( | |
542 | self.__class__.__module__, self.__class__.__name__, |
|
555 | self.__class__.__module__, self.__class__.__name__, | |
543 | list.__repr__(self)[1:-1]) |
|
556 | list.__repr__(self)[1:-1]) | |
544 |
|
557 | |||
545 | def __init__(self, *args): |
|
|||
546 | list.__init__(self) |
|
|||
547 | self.append(*args) |
|
|||
548 |
|
||||
549 | def append(self, *args): |
|
558 | def append(self, *args): | |
550 | for arg in args: |
|
559 | for arg in args: | |
551 | if isinstance(arg, Text): |
|
560 | if isinstance(arg, Text): | |
@@ -595,7 +604,8 b' class Text(list):' | |||||
595 |
|
604 | |||
596 | def string(self, styled=True): |
|
605 | def string(self, styled=True): | |
597 | """ |
|
606 | """ | |
598 |
Return the resulting string (with escape sequences, if ``styled`` |
|
607 | Return the resulting string (with escape sequences, if ``styled`` | |
|
608 | is true). | |||
599 | """ |
|
609 | """ | |
600 | return "".join(self.format(styled)) |
|
610 | return "".join(self.format(styled)) | |
601 |
|
611 | |||
@@ -1158,7 +1168,13 b' class iparentdir(ifile):' | |||||
1158 |
|
1168 | |||
1159 | class ils(Table): |
|
1169 | class ils(Table): | |
1160 | """ |
|
1170 | """ | |
1161 | This ``Table`` lists a directory. |
|
1171 | List the current (or a specific) directory. | |
|
1172 | ||||
|
1173 | Examples: | |||
|
1174 | ||||
|
1175 | >>> ils | |||
|
1176 | >>> ils("/usr/local/lib/python2.4") | |||
|
1177 | >>> ils("~") | |||
1162 | """ |
|
1178 | """ | |
1163 | def __init__(self, base=os.curdir): |
|
1179 | def __init__(self, base=os.curdir): | |
1164 | self.base = os.path.expanduser(base) |
|
1180 | self.base = os.path.expanduser(base) | |
@@ -1176,8 +1192,12 b' class ils(Table):' | |||||
1176 |
|
1192 | |||
1177 | class iglob(Table): |
|
1193 | class iglob(Table): | |
1178 | """ |
|
1194 | """ | |
1179 |
|
|
1195 | List all files and directories matching a specified pattern. | |
1180 | (See ``glob.glob()`` for more info.) |
|
1196 | (See ``glob.glob()`` for more info.). | |
|
1197 | ||||
|
1198 | Examples: | |||
|
1199 | ||||
|
1200 | >>> iglob("*.py") | |||
1181 | """ |
|
1201 | """ | |
1182 | def __init__(self, glob): |
|
1202 | def __init__(self, glob): | |
1183 | self.glob = glob |
|
1203 | self.glob = glob | |
@@ -1200,8 +1220,11 b' class iglob(Table):' | |||||
1200 |
|
1220 | |||
1201 | class iwalk(Table): |
|
1221 | class iwalk(Table): | |
1202 | """ |
|
1222 | """ | |
1203 |
|
|
1223 | List all files and directories in a directory and it's subdirectory. | |
1204 | subdirectory. |
|
1224 | ||
|
1225 | >>> iwalk | |||
|
1226 | >>> iwalk("/usr/local/lib/python2.4") | |||
|
1227 | >>> iwalk("~") | |||
1205 | """ |
|
1228 | """ | |
1206 | def __init__(self, base=os.curdir, dirs=True, files=True): |
|
1229 | def __init__(self, base=os.curdir, dirs=True, files=True): | |
1207 | self.base = os.path.expanduser(base) |
|
1230 | self.base = os.path.expanduser(base) | |
@@ -1294,8 +1317,11 b' class ipwdentry(object):' | |||||
1294 |
|
1317 | |||
1295 | class ipwd(Table): |
|
1318 | class ipwd(Table): | |
1296 | """ |
|
1319 | """ | |
1297 |
|
|
1320 | List all entries in the Unix user account and password database. | |
1298 | database. |
|
1321 | ||
|
1322 | Example: | |||
|
1323 | ||||
|
1324 | >>> ipwd | isort("uid") | |||
1299 | """ |
|
1325 | """ | |
1300 | def __iter__(self): |
|
1326 | def __iter__(self): | |
1301 | for entry in pwd.getpwall(): |
|
1327 | for entry in pwd.getpwall(): | |
@@ -1475,7 +1501,11 b' class List(list):' | |||||
1475 |
|
1501 | |||
1476 | class ienv(Table): |
|
1502 | class ienv(Table): | |
1477 | """ |
|
1503 | """ | |
1478 |
|
|
1504 | List environment variables. | |
|
1505 | ||||
|
1506 | Example: | |||
|
1507 | ||||
|
1508 | >>> ienv | |||
1479 | """ |
|
1509 | """ | |
1480 |
|
1510 | |||
1481 | def __xiter__(self, mode): |
|
1511 | def __xiter__(self, mode): | |
@@ -1539,8 +1569,13 b' class icsv(Pipe):' | |||||
1539 |
|
1569 | |||
1540 | class ix(Table): |
|
1570 | class ix(Table): | |
1541 | """ |
|
1571 | """ | |
1542 |
|
|
1572 | Execute a system command and list its output as lines | |
1543 | (similar to ``os.popen()``). |
|
1573 | (similar to ``os.popen()``). | |
|
1574 | ||||
|
1575 | Examples: | |||
|
1576 | ||||
|
1577 | >>> ix("ps x") | |||
|
1578 | >>> ix("find .") | ifile | |||
1544 | """ |
|
1579 | """ | |
1545 | def __init__(self, cmd): |
|
1580 | def __init__(self, cmd): | |
1546 | self.cmd = cmd |
|
1581 | self.cmd = cmd | |
@@ -1572,8 +1607,14 b' class ix(Table):' | |||||
1572 |
|
1607 | |||
1573 | class ifilter(Pipe): |
|
1608 | class ifilter(Pipe): | |
1574 | """ |
|
1609 | """ | |
1575 |
|
|
1610 | Filter an input pipe. Only objects where an expression evaluates to true | |
1576 |
|
|
1611 | (and doesn't raise an exception) are listed. | |
|
1612 | ||||
|
1613 | Examples: | |||
|
1614 | ||||
|
1615 | >>> ils | ifilter("_.isfile() and size>1000") | |||
|
1616 | >>> igrp | ifilter("len(mem)") | |||
|
1617 | >>> sys.modules | ifilter(lambda _:_.value is not None) | |||
1577 | """ |
|
1618 | """ | |
1578 |
|
1619 | |||
1579 | def __init__(self, expr, errors="raiseifallfail"): |
|
1620 | def __init__(self, expr, errors="raiseifallfail"): | |
@@ -1651,7 +1692,12 b' class ifilter(Pipe):' | |||||
1651 |
|
1692 | |||
1652 | class ieval(Pipe): |
|
1693 | class ieval(Pipe): | |
1653 | """ |
|
1694 | """ | |
1654 |
|
|
1695 | Evaluate an expression for each object in the input pipe. | |
|
1696 | ||||
|
1697 | Examples: | |||
|
1698 | ||||
|
1699 | >>> ils | ieval("_.abspath()") | |||
|
1700 | >>> sys.path | ieval(ifile) | |||
1655 | """ |
|
1701 | """ | |
1656 |
|
1702 | |||
1657 | def __init__(self, expr, errors="raiseifallfail"): |
|
1703 | def __init__(self, expr, errors="raiseifallfail"): | |
@@ -1714,6 +1760,14 b' class ieval(Pipe):' | |||||
1714 |
|
1760 | |||
1715 |
|
1761 | |||
1716 | class ienum(Pipe): |
|
1762 | class ienum(Pipe): | |
|
1763 | """ | |||
|
1764 | Enumerate the input pipe (i.e. wrap each input object in an object | |||
|
1765 | with ``index`` and ``object`` attributes). | |||
|
1766 | ||||
|
1767 | Examples: | |||
|
1768 | ||||
|
1769 | >>> xrange(20) | ieval("_,_*_") | ienum | ifilter("index % 2 == 0") | ieval("object") | |||
|
1770 | """ | |||
1717 | def __xiter__(self, mode): |
|
1771 | def __xiter__(self, mode): | |
1718 | fields = ("index", "object") |
|
1772 | fields = ("index", "object") | |
1719 | for (index, object) in enumerate(xiter(self.input, mode)): |
|
1773 | for (index, object) in enumerate(xiter(self.input, mode)): | |
@@ -1722,7 +1776,12 b' class ienum(Pipe):' | |||||
1722 |
|
1776 | |||
1723 | class isort(Pipe): |
|
1777 | class isort(Pipe): | |
1724 | """ |
|
1778 | """ | |
1725 |
|
|
1779 | Sorts the input pipe. | |
|
1780 | ||||
|
1781 | Examples: | |||
|
1782 | ||||
|
1783 | >>> ils | isort("size") | |||
|
1784 | >>> ils | isort("_.isdir(), _.lower()", reverse=True) | |||
1726 | """ |
|
1785 | """ | |
1727 |
|
1786 | |||
1728 | def __init__(self, key, reverse=False): |
|
1787 | def __init__(self, key, reverse=False): |
General Comments 0
You need to be logged in to leave comments.
Login now