Show More
@@ -8,7 +8,7 b' objects imported this way starts with ``i`` to minimize collisions.' | |||
|
8 | 8 | ``ipipe`` supports "pipeline expressions", which is something resembling Unix |
|
9 | 9 | pipes. An example is:: |
|
10 | 10 | |
|
11 |
|
|
|
11 | >>> ienv | isort("key.lower()") | |
|
12 | 12 | |
|
13 | 13 | This gives a listing of all environment variables sorted by name. |
|
14 | 14 | |
@@ -49,31 +49,31 b' three extensions points (all of them optional):' | |||
|
49 | 49 | makes it possible to use dictionaries and modules in pipeline expressions, |
|
50 | 50 | for example:: |
|
51 | 51 | |
|
52 |
|
|
|
53 |
|
|
|
52 | >>> import sys | |
|
53 | >>> sys | ifilter("isinstance(value, int)") | idump | |
|
54 | 54 | key |value |
|
55 | 55 | api_version| 1012 |
|
56 | 56 | dllhandle | 503316480 |
|
57 | 57 | hexversion | 33817328 |
|
58 | 58 | maxint |2147483647 |
|
59 | 59 | maxunicode | 65535 |
|
60 |
|
|
|
60 | >>> sys.modules | ifilter("_.value is not None") | isort("_.key.lower()") | |
|
61 | 61 | ... |
|
62 | 62 | |
|
63 | 63 | Note: The expression strings passed to ``ifilter()`` and ``isort()`` can |
|
64 | 64 | refer to the object to be filtered or sorted via the variable ``_`` and to any |
|
65 | 65 | of the attributes of the object, i.e.:: |
|
66 | 66 | |
|
67 |
|
|
|
67 | >>> sys.modules | ifilter("_.value is not None") | isort("_.key.lower()") | |
|
68 | 68 | |
|
69 | 69 | does the same as:: |
|
70 | 70 | |
|
71 |
|
|
|
71 | >>> sys.modules | ifilter("value is not None") | isort("key.lower()") | |
|
72 | 72 | |
|
73 | 73 | In addition to expression strings, it's possible to pass callables (taking |
|
74 | 74 | the object as an argument) to ``ifilter()``, ``isort()`` and ``ieval()``:: |
|
75 | 75 | |
|
76 |
|
|
|
76 | >>> sys | ifilter(lambda _:isinstance(_.value, int)) \ | |
|
77 | 77 | ... | ieval(lambda _: (_.key, hex(_.value))) | idump |
|
78 | 78 | 0 |1 |
|
79 | 79 | api_version|0x3f4 |
@@ -83,6 +83,8 b' three extensions points (all of them optional):' | |||
|
83 | 83 | maxunicode |0xffff |
|
84 | 84 | """ |
|
85 | 85 | |
|
86 | skip_doctest = True # ignore top-level docstring as a doctest. | |
|
87 | ||
|
86 | 88 | import sys, os, os.path, stat, glob, new, csv, datetime, types |
|
87 | 89 | import itertools, mimetypes, StringIO |
|
88 | 90 | |
@@ -1208,9 +1210,13 b' class ils(Table):' | |||
|
1208 | 1210 | |
|
1209 | 1211 | Examples:: |
|
1210 | 1212 | |
|
1211 |
|
|
|
1212 | py> ils("/usr/local/lib/python2.4") | |
|
1213 | py> ils("~") | |
|
1213 | >>> ils | |
|
1214 | <class 'IPython.Extensions.ipipe.ils'> | |
|
1215 | >>> ils("/usr/local/lib/python2.4") | |
|
1216 | IPython.Extensions.ipipe.ils('/usr/local/lib/python2.4') | |
|
1217 | >>> ils("~") | |
|
1218 | IPython.Extensions.ipipe.ils('/home/fperez') | |
|
1219 | # all-random | |
|
1214 | 1220 | """ |
|
1215 | 1221 | def __init__(self, base=os.curdir, dirs=True, files=True): |
|
1216 | 1222 | self.base = os.path.expanduser(base) |
@@ -1246,7 +1252,8 b' class iglob(Table):' | |||
|
1246 | 1252 | |
|
1247 | 1253 | Examples:: |
|
1248 | 1254 | |
|
1249 |
|
|
|
1255 | >>> iglob("*.py") | |
|
1256 | IPython.Extensions.ipipe.iglob('*.py') | |
|
1250 | 1257 | """ |
|
1251 | 1258 | def __init__(self, glob): |
|
1252 | 1259 | self.glob = glob |
@@ -1271,9 +1278,13 b' class iwalk(Table):' | |||
|
1271 | 1278 | """ |
|
1272 | 1279 | List all files and directories in a directory and it's subdirectory:: |
|
1273 | 1280 | |
|
1274 |
|
|
|
1275 | py> iwalk("/usr/local/lib/python2.4") | |
|
1276 |
|
|
|
1281 | >>> iwalk | |
|
1282 | <class 'IPython.Extensions.ipipe.iwalk'> | |
|
1283 | >>> iwalk("/usr/lib") | |
|
1284 | IPython.Extensions.ipipe.iwalk('/usr/lib') | |
|
1285 | >>> iwalk("~") | |
|
1286 | IPython.Extensions.ipipe.iwalk('/home/fperez') # random | |
|
1287 | ||
|
1277 | 1288 | """ |
|
1278 | 1289 | def __init__(self, base=os.curdir, dirs=True, files=True): |
|
1279 | 1290 | self.base = os.path.expanduser(base) |
@@ -1376,7 +1387,9 b' class ipwd(Table):' | |||
|
1376 | 1387 | |
|
1377 | 1388 | Example:: |
|
1378 | 1389 | |
|
1379 |
|
|
|
1390 | >>> ipwd | isort("uid") | |
|
1391 | <IPython.Extensions.ipipe.isort key='uid' reverse=False at 0x849efec> | |
|
1392 | # random | |
|
1380 | 1393 | """ |
|
1381 | 1394 | def __iter__(self): |
|
1382 | 1395 | for entry in pwd.getpwall(): |
@@ -1560,7 +1573,8 b' class ienv(Table):' | |||
|
1560 | 1573 | |
|
1561 | 1574 | Example:: |
|
1562 | 1575 | |
|
1563 |
|
|
|
1576 | >>> ienv | |
|
1577 | <class 'IPython.Extensions.ipipe.ienv'> | |
|
1564 | 1578 | """ |
|
1565 | 1579 | |
|
1566 | 1580 | def __iter__(self): |
@@ -1581,8 +1595,10 b' class ihist(Table):' | |||
|
1581 | 1595 | |
|
1582 | 1596 | Example:: |
|
1583 | 1597 | |
|
1584 |
|
|
|
1585 | py> ihist(True) (raw mode) | |
|
1598 | >>> ihist | |
|
1599 | <class 'IPython.Extensions.ipipe.ihist'> | |
|
1600 | >>> ihist(True) # raw mode | |
|
1601 | <IPython.Extensions.ipipe.ihist object at 0x849602c> # random | |
|
1586 | 1602 | """ |
|
1587 | 1603 | def __init__(self, raw=True): |
|
1588 | 1604 | self.raw = raw |
@@ -1616,7 +1632,8 b' class ialias(Table):' | |||
|
1616 | 1632 | |
|
1617 | 1633 | Example:: |
|
1618 | 1634 | |
|
1619 |
|
|
|
1635 | >>> ialias | |
|
1636 | <class 'IPython.Extensions.ipipe.ialias'> | |
|
1620 | 1637 | """ |
|
1621 | 1638 | def __iter__(self): |
|
1622 | 1639 | api = ipapi.get() |
@@ -1678,8 +1695,12 b' class ix(Table):' | |||
|
1678 | 1695 | |
|
1679 | 1696 | Examples:: |
|
1680 | 1697 | |
|
1681 |
|
|
|
1682 | py> ix("find .") | ifile | |
|
1698 | >>> ix("ps x") | |
|
1699 | IPython.Extensions.ipipe.ix('ps x') | |
|
1700 | ||
|
1701 | >>> ix("find .") | ifile | |
|
1702 | <IPython.Extensions.ipipe.ieval expr=<class 'IPython.Extensions.ipipe.ifile'> at 0x8509d2c> | |
|
1703 | # random | |
|
1683 | 1704 | """ |
|
1684 | 1705 | def __init__(self, cmd): |
|
1685 | 1706 | self.cmd = cmd |
@@ -1717,9 +1738,10 b' class ifilter(Pipe):' | |||
|
1717 | 1738 | |
|
1718 | 1739 | Examples:: |
|
1719 | 1740 | |
|
1720 |
|
|
|
1721 |
|
|
|
1722 |
|
|
|
1741 | >>> ils | ifilter("_.isfile() and size>1000") | |
|
1742 | >>> igrp | ifilter("len(mem)") | |
|
1743 | >>> sys.modules | ifilter(lambda _:_.value is not None) | |
|
1744 | # all-random | |
|
1723 | 1745 | """ |
|
1724 | 1746 | |
|
1725 | 1747 | def __init__(self, expr, globals=None, errors="raiseifallfail"): |
@@ -1809,8 +1831,10 b' class ieval(Pipe):' | |||
|
1809 | 1831 | |
|
1810 | 1832 | Examples:: |
|
1811 | 1833 | |
|
1812 |
|
|
|
1813 | py> sys.path | ieval(ifile) | |
|
1834 | >>> ils | ieval("_.abspath()") | |
|
1835 | # random | |
|
1836 | >>> sys.path | ieval(ifile) | |
|
1837 | # random | |
|
1814 | 1838 | """ |
|
1815 | 1839 | |
|
1816 | 1840 | def __init__(self, expr, globals=None, errors="raiseifallfail"): |
@@ -1881,8 +1905,10 b' class ienum(Pipe):' | |||
|
1881 | 1905 | |
|
1882 | 1906 | Examples:: |
|
1883 | 1907 | |
|
1884 |
|
|
|
1908 | >>> xrange(20) | ieval("_,_*_") | ienum | ifilter("index % 2 == 0") | ieval("object") | |
|
1885 | 1909 | """ |
|
1910 | skip_doctest = True | |
|
1911 | ||
|
1886 | 1912 | def __iter__(self): |
|
1887 | 1913 | fields = ("index", "object") |
|
1888 | 1914 | for (index, object) in enumerate(xiter(self.input)): |
@@ -1895,8 +1921,11 b' class isort(Pipe):' | |||
|
1895 | 1921 | |
|
1896 | 1922 | Examples:: |
|
1897 | 1923 | |
|
1898 |
|
|
|
1899 | py> ils | isort("_.isdir(), _.lower()", reverse=True) | |
|
1924 | >>> ils | isort("size") | |
|
1925 | <IPython.Extensions.ipipe.isort key='size' reverse=False at 0x849ec2c> | |
|
1926 | >>> ils | isort("_.isdir(), _.lower()", reverse=True) | |
|
1927 | <IPython.Extensions.ipipe.isort key='_.isdir(), _.lower()' reverse=True at 0x849eacc> | |
|
1928 | # all-random | |
|
1900 | 1929 | """ |
|
1901 | 1930 | |
|
1902 | 1931 | def __init__(self, key=None, globals=None, reverse=False): |
@@ -2053,10 +2082,12 b' class icap(Table):' | |||
|
2053 | 2082 | |
|
2054 | 2083 | Examples:: |
|
2055 | 2084 | |
|
2056 |
|
|
|
2057 |
|
|
|
2085 | >>> import time | |
|
2086 | >>> icap("for i in range(10): print i, time.sleep(0.1)") | |
|
2058 | 2087 | |
|
2059 | 2088 | """ |
|
2089 | skip_doctest = True | |
|
2090 | ||
|
2060 | 2091 | def __init__(self, expr, globals=None): |
|
2061 | 2092 | self.expr = expr |
|
2062 | 2093 | self.globals = globals |
General Comments 0
You need to be logged in to leave comments.
Login now