##// END OF EJS Templates
Add recipe to log to with timestamps....
Add recipe to log to with timestamps. Original patch by Gökhan Sever, minor formatting fixes.

File last commit:

r1892:51835448
r2471:1b44dbf7
Show More
ipipe.py
2327 lines | 70.0 KiB | text/x-python | PythonLexer
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 # -*- coding: iso-8859-1 -*-
"""
``ipipe`` provides classes to be used in an interactive Python session. Doing a
``from ipipe import *`` is the preferred way to do this. The name of all
objects imported this way starts with ``i`` to minimize collisions.
``ipipe`` supports "pipeline expressions", which is something resembling Unix
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 pipes. An example is::
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
Fernando Perez
Fix all doctests.
r1433 >>> ienv | isort("key.lower()")
vivainio
Walter's ipipe patch:...
r214
This gives a listing of all environment variables sorted by name.
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
There are three types of objects in a pipeline expression:
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 * ``Table``s: These objects produce items. Examples are ``ils`` (listing the
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 current directory, ``ienv`` (listing environment variables), ``ipwd`` (listing
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 user accounts) and ``igrp`` (listing user groups). A ``Table`` must be the
vivainio
Walter's ipipe.py patch:...
r209 first object in a pipe expression.
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
vivainio
Walter's ipipe.py patch:...
r209 * ``Pipe``s: These objects sit in the middle of a pipe expression. They
transform the input in some way (e.g. filtering or sorting it). Examples are:
``ifilter`` (which filters the input pipe), ``isort`` (which sorts the input
pipe) and ``ieval`` (which evaluates a function or expression for each object
in the input pipe).
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
* ``Display``s: These objects can be put as the last object in a pipeline
expression. There are responsible for displaying the result of the pipeline
expression. If a pipeline expression doesn't end in a display object a default
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 display objects will be used. One example is ``ibrowse`` which is a ``curses``
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 based browser.
vivainio
Walter's ipipe patch:...
r214
Adding support for pipeline expressions to your own objects can be done through
three extensions points (all of them optional):
* An object that will be displayed as a row by a ``Display`` object should
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 implement the method ``__xattrs__(self, mode)`` method or register an
implementation of the generic function ``xattrs``. For more info see ``xattrs``.
* When an object ``foo`` is displayed by a ``Display`` object, the generic
function ``xrepr`` is used.
* Objects that can be iterated by ``Pipe``s must iterable. For special cases,
where iteration for display is different than the normal iteration a special
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 implementation can be registered with the generic function ``xiter``. This
makes it possible to use dictionaries and modules in pipeline expressions,
for example::
vivainio
Walter's ipipe patch:...
r214
Fernando Perez
Fix all doctests.
r1433 >>> import sys
>>> sys | ifilter("isinstance(value, int)") | idump
vivainio
Walter's ipipe patch:...
r214 key |value
api_version| 1012
dllhandle | 503316480
hexversion | 33817328
maxint |2147483647
maxunicode | 65535
Fernando Perez
Fix all doctests.
r1433 >>> sys.modules | ifilter("_.value is not None") | isort("_.key.lower()")
vivainio
Walter's ipipe patch:...
r214 ...
Note: The expression strings passed to ``ifilter()`` and ``isort()`` can
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 refer to the object to be filtered or sorted via the variable ``_`` and to any
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 of the attributes of the object, i.e.::
vivainio
Walter's ipipe patch:...
r214
Fernando Perez
Fix all doctests.
r1433 >>> sys.modules | ifilter("_.value is not None") | isort("_.key.lower()")
vivainio
Walter's ipipe patch:...
r214
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 does the same as::
vivainio
Walter's ipipe patch:...
r214
Fernando Perez
Fix all doctests.
r1433 >>> sys.modules | ifilter("value is not None") | isort("key.lower()")
vivainio
Walter's ipipe patch:...
r214
In addition to expression strings, it's possible to pass callables (taking
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 the object as an argument) to ``ifilter()``, ``isort()`` and ``ieval()``::
vivainio
Walter's ipipe patch:...
r214
Fernando Perez
Fix all doctests.
r1433 >>> sys | ifilter(lambda _:isinstance(_.value, int)) \
vivainio
Walter's ipipe patch:...
r214 ... | ieval(lambda _: (_.key, hex(_.value))) | idump
0 |1
api_version|0x3f4
dllhandle |0x1e000000
hexversion |0x20402f0
maxint |0x7fffffff
maxunicode |0xffff
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 """
Fernando Perez
Fix all doctests.
r1433 skip_doctest = True # ignore top-level docstring as a doctest.
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 import sys, os, os.path, stat, glob, new, csv, datetime, types
walter.doerwald
Added a new table icap, which executes a Python string...
r711 import itertools, mimetypes, StringIO
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
try: # Python 2.3 compatibility
import collections
except ImportError:
deque = list
else:
deque = collections.deque
try: # Python 2.3 compatibility
set
except NameError:
import sets
set = sets.Set
try: # Python 2.3 compatibility
sorted
except NameError:
def sorted(iterator, key=None, reverse=False):
items = list(iterator)
if key is not None:
items.sort(lambda i1, i2: cmp(key(i1), key(i2)))
else:
items.sort()
if reverse:
items.reverse()
return items
Walter Doerwald
Fix warnings about ignored GeneratorExit exceptions under Python 2.5+ in ipipe.xrepr()....
r1892 try: # Python 2.4 compatibility
GeneratorExit
except NameError:
GeneratorExit = SystemExit
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 try:
import pwd
except ImportError:
pwd = None
try:
import grp
except ImportError:
grp = None
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 from IPython.external import simplegeneric
Fernando Perez
Fixes to testing....
r1376 from IPython.external import path
walter.doerwald
Add missing import.
r959
vivainio
Walter's ipipe patch for colored idump output on windows
r247 try:
walter.doerwald
Register ipipe's displayhooks via the generic function...
r958 from IPython import genutils, generics
vivainio
Walter's ipipe patch for colored idump output on windows
r247 except ImportError:
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 genutils = None
walter.doerwald
Register ipipe's displayhooks via the generic function...
r958 generics = None
vivainio
Walter's ipipe patch #8:...
r237
walter.doerwald
Add missing import.
r959 from IPython import ipapi
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
__all__ = [
"ifile", "ils", "iglob", "iwalk", "ipwdentry", "ipwd", "igrpentry", "igrp",
walter.doerwald
IPython/Extensions/ipipe.py: Added a Table ihist that can be used to...
r683 "icsv", "ix", "ichain", "isort", "ifilter", "ieval", "ienum",
walter.doerwald
A new ipipe table has been added: ialias produces all entries from IPython's...
r974 "ienv", "ihist", "ialias", "icap", "idump", "iless"
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 ]
os.stat_float_times(True) # enable microseconds
walter.doerwald
Move ibrowse into a separate module.
r272 class AttrNamespace(object):
vivainio
Walter's ipipe patch:...
r214 """
walter.doerwald
Move ibrowse into a separate module.
r272 Helper class that is used for providing a namespace for evaluating
expressions containing attribute names of an object.
vivainio
Walter's ipipe patch:...
r214 """
def __init__(self, wrapped):
self.wrapped = wrapped
def __getitem__(self, name):
if name == "_":
return self.wrapped
try:
return getattr(self.wrapped, name)
except AttributeError:
raise KeyError(name)
# Python 2.3 compatibility
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 # use eval workaround to find out which names are used in the
# eval string and put them into the locals. This works for most
# normal uses case, bizarre ones like accessing the locals()
# will fail
vivainio
Walter's ipipe patch:...
r214 try:
walter.doerwald
Move ibrowse into a separate module.
r272 eval("_", None, AttrNamespace(None))
vivainio
Walter's ipipe patch:...
r214 except TypeError:
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 real_eval = eval
def eval(codestring, _globals, _locals):
"""
eval(source[, globals[, locals]]) -> value
Evaluate the source in the context of globals and locals.
The source may be a string representing a Python expression
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mappping.
This function is a workaround for the shortcomings of
Python 2.3's eval.
"""
walter.doerwald
Compile expression strings into code objects. This should speed...
r349 if isinstance(codestring, basestring):
code = compile(codestring, "_eval", "eval")
else:
code = codestring
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 newlocals = {}
for name in code.co_names:
try:
newlocals[name] = _locals[name]
except KeyError:
pass
return real_eval(code, _globals, newlocals)
vivainio
Walter's ipipe patch:...
r214
walter.doerwald
Rename ipipe._default to ipipe.noitem (which makes...
r274 noitem = object()
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
Add an xrepr implementation for the noitem object.
r519
walter.doerwald
Rename ipipe._default to ipipe.noitem (which makes...
r274 def item(iterator, index, default=noitem):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 """
Return the ``index``th item from the iterator ``iterator``.
``index`` must be an integer (negative integers are relative to the
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 end (i.e. the last items produced by the iterator)).
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
If ``default`` is given, this will be the default value when
the iterator doesn't contain an item at this position. Otherwise an
``IndexError`` will be raised.
Note that using this function will partially or totally exhaust the
iterator.
"""
i = index
if i>=0:
for item in iterator:
if not i:
return item
i -= 1
else:
i = -index
cache = deque()
for item in iterator:
cache.append(item)
if len(cache)>i:
cache.popleft()
if len(cache)==i:
return cache.popleft()
walter.doerwald
Rename ipipe._default to ipipe.noitem (which makes...
r274 if default is noitem:
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 raise IndexError(index)
else:
return default
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 def getglobals(g):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Return the global namespace that is used for expression strings in
``ifilter`` and others. This is ``g`` or (if ``g`` is ``None``) IPython's
user namespace.
"""
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 if g is None:
if ipapi is not None:
walter.doerwald
Fix getglobals() if we're not running under IPython.
r354 api = ipapi.get()
if api is not None:
return api.user_ns
return globals()
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 return g
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 class Descriptor(object):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
A ``Descriptor`` object is used for describing the attributes of objects.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __hash__(self):
return hash(self.__class__) ^ hash(self.key())
def __eq__(self, other):
return self.__class__ is other.__class__ and self.key() == other.key()
def __ne__(self, other):
return self.__class__ is not other.__class__ or self.key() != other.key()
def key(self):
pass
def name(self):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Return the name of this attribute for display by a ``Display`` object
(e.g. as a column title).
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 key = self.key()
if key is None:
return "_"
return str(key)
def attrtype(self, obj):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Return the type of this attribute (i.e. something like "attribute" or
"method").
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355
def valuetype(self, obj):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Return the type of this attribute value of the object ``obj``.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355
def value(self, obj):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Return the value of this attribute of the object ``obj``.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355
def doc(self, obj):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Return the documentation for this attribute.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355
def shortdoc(self, obj):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Return a short documentation for this attribute (defaulting to the
first line).
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 doc = self.doc(obj)
if doc is not None:
doc = doc.strip().splitlines()[0].strip()
return doc
def iter(self, obj):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Return an iterator for this attribute of the object ``obj``.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 return xiter(self.value(obj))
class SelfDescriptor(Descriptor):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
A ``SelfDescriptor`` describes the object itself.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def key(self):
return None
def attrtype(self, obj):
return "self"
def valuetype(self, obj):
return type(obj)
def value(self, obj):
return obj
def __repr__(self):
return "Self"
selfdescriptor = SelfDescriptor() # there's no need for more than one
class AttributeDescriptor(Descriptor):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
An ``AttributeDescriptor`` describes a simple attribute of an object.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 __slots__ = ("_name", "_doc")
def __init__(self, name, doc=None):
self._name = name
self._doc = doc
def key(self):
return self._name
def doc(self, obj):
return self._doc
def attrtype(self, obj):
return "attr"
def valuetype(self, obj):
return type(getattr(obj, self._name))
def value(self, obj):
return getattr(obj, self._name)
def __repr__(self):
if self._doc is None:
return "Attribute(%r)" % self._name
else:
return "Attribute(%r, %r)" % (self._name, self._doc)
class IndexDescriptor(Descriptor):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
An ``IndexDescriptor`` describes an "attribute" of an object that is fetched
via ``__getitem__``.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 __slots__ = ("_index",)
def __init__(self, index):
self._index = index
def key(self):
return self._index
def attrtype(self, obj):
return "item"
def valuetype(self, obj):
return type(obj[self._index])
def value(self, obj):
return obj[self._index]
def __repr__(self):
return "Index(%r)" % self._index
class MethodDescriptor(Descriptor):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
A ``MethodDescriptor`` describes a method of an object that can be called
without argument. Note that this method shouldn't change the object.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 __slots__ = ("_name", "_doc")
def __init__(self, name, doc=None):
self._name = name
self._doc = doc
def key(self):
return self._name
def doc(self, obj):
if self._doc is None:
return getattr(obj, self._name).__doc__
return self._doc
def attrtype(self, obj):
return "method"
def valuetype(self, obj):
return type(self.value(obj))
def value(self, obj):
return getattr(obj, self._name)()
def __repr__(self):
if self._doc is None:
return "Method(%r)" % self._name
else:
return "Method(%r, %r)" % (self._name, self._doc)
class IterAttributeDescriptor(Descriptor):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
An ``IterAttributeDescriptor`` works like an ``AttributeDescriptor`` but
doesn't return an attribute values (because this value might be e.g. a large
list).
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 __slots__ = ("_name", "_doc")
def __init__(self, name, doc=None):
self._name = name
self._doc = doc
def key(self):
return self._name
def doc(self, obj):
return self._doc
def attrtype(self, obj):
return "iter"
def valuetype(self, obj):
return noitem
def value(self, obj):
return noitem
def iter(self, obj):
return xiter(getattr(obj, self._name))
def __repr__(self):
if self._doc is None:
return "IterAttribute(%r)" % self._name
else:
return "IterAttribute(%r, %r)" % (self._name, self._doc)
class IterMethodDescriptor(Descriptor):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
An ``IterMethodDescriptor`` works like an ``MethodDescriptor`` but doesn't
return an attribute values (because this value might be e.g. a large list).
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 __slots__ = ("_name", "_doc")
def __init__(self, name, doc=None):
self._name = name
self._doc = doc
def key(self):
return self._name
def doc(self, obj):
if self._doc is None:
return getattr(obj, self._name).__doc__
return self._doc
def attrtype(self, obj):
return "itermethod"
def valuetype(self, obj):
return noitem
def value(self, obj):
return noitem
def iter(self, obj):
return xiter(getattr(obj, self._name)())
def __repr__(self):
if self._doc is None:
return "IterMethod(%r)" % self._name
else:
return "IterMethod(%r, %r)" % (self._name, self._doc)
class FunctionDescriptor(Descriptor):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
A ``FunctionDescriptor`` turns a function into a descriptor. The function
will be called with the object to get the type and value of the attribute.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 __slots__ = ("_function", "_name", "_doc")
def __init__(self, function, name=None, doc=None):
self._function = function
self._name = name
self._doc = doc
def key(self):
return self._function
def name(self):
if self._name is not None:
return self._name
return getattr(self._function, "__xname__", self._function.__name__)
def doc(self, obj):
if self._doc is None:
return self._function.__doc__
return self._doc
def attrtype(self, obj):
return "function"
def valuetype(self, obj):
return type(self._function(obj))
def value(self, obj):
return self._function(obj)
def __repr__(self):
if self._doc is None:
return "Function(%r)" % self._name
else:
return "Function(%r, %r)" % (self._name, self._doc)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 class Table(object):
"""
A ``Table`` is an object that produces items (just like a normal Python
iterator/generator does) and can be used as the first object in a pipeline
expression. The displayhook will open the default browser for such an object
(instead of simply printing the ``repr()`` result).
"""
vivainio
Walter's ipipe patch:...
r214
# We want to support ``foo`` and ``foo()`` in pipeline expression:
# So we implement the required operators (``|`` and ``+``) in the metaclass,
# instantiate the class and forward the operator to the instance
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 class __metaclass__(type):
def __iter__(self):
return iter(self())
def __or__(self, other):
return self() | other
def __add__(self, other):
return self() + other
def __radd__(self, other):
return other + self()
def __getitem__(self, index):
return self()[index]
def __getitem__(self, index):
return item(self, index)
def __contains__(self, item):
for haveitem in self:
if item == haveitem:
return True
return False
def __or__(self, other):
vivainio
Walter's ipipe patch:...
r214 # autoinstantiate right hand side
vivainio
Walter's ipipe.py patch:...
r209 if isinstance(other, type) and issubclass(other, (Table, Display)):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 other = other()
vivainio
Walter's ipipe patch:...
r214 # treat simple strings and functions as ``ieval`` instances
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 elif not isinstance(other, Display) and not isinstance(other, Table):
other = ieval(other)
vivainio
Walter's ipipe patch:...
r214 # forward operations to the right hand side
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 return other.__ror__(self)
def __add__(self, other):
vivainio
Walter's ipipe patch:...
r214 # autoinstantiate right hand side
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if isinstance(other, type) and issubclass(other, Table):
other = other()
return ichain(self, other)
def __radd__(self, other):
vivainio
Walter's ipipe patch:...
r214 # autoinstantiate left hand side
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if isinstance(other, type) and issubclass(other, Table):
other = other()
return ichain(other, self)
class Pipe(Table):
"""
vivainio
Walter's ipipe.py patch:...
r209 A ``Pipe`` is an object that can be used in a pipeline expression. It
processes the objects it gets from its input ``Table``/``Pipe``. Note that
a ``Pipe`` object can't be used as the first object in a pipeline
expression, as it doesn't produces items itself.
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 """
class __metaclass__(Table.__metaclass__):
def __ror__(self, input):
return input | self()
def __ror__(self, input):
vivainio
Walter's ipipe patch:...
r214 # autoinstantiate left hand side
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if isinstance(input, type) and issubclass(input, Table):
input = input()
self.input = input
return self
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def xrepr(item, mode="default"):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Generic function that adds color output and different display modes to ``repr``.
The result of an ``xrepr`` call is iterable and consists of ``(style, string)``
tuples. The ``style`` in this tuple must be a ``Style`` object from the
``astring`` module. To reconfigure the output the first yielded tuple can be
a ``(aligment, full)`` tuple instead of a ``(style, string)`` tuple.
``alignment`` can be -1 for left aligned, 0 for centered and 1 for right
aligned (the default is left alignment). ``full`` is a boolean that specifies
whether the complete output must be displayed or the ``Display`` object is
allowed to stop output after enough text has been produced (e.g. a syntax
highlighted text line would use ``True``, but for a large data structure
(i.e. a nested list, tuple or dictionary) ``False`` would be used).
The default is full output.
There are four different possible values for ``mode`` depending on where
the ``Display`` object will display ``item``:
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 ``"header"``
``item`` will be displayed in a header line (this is used by ``ibrowse``).
``"footer"``
``item`` will be displayed in a footer line (this is used by ``ibrowse``).
``"cell"``
``item`` will be displayed in a table cell/list.
``"default"``
default mode. If an ``xrepr`` implementation recursively outputs objects,
``"default"`` must be passed in the recursive calls to ``xrepr``.
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415
If no implementation is registered for ``item``, ``xrepr`` will try the
``__xrepr__`` method on ``item``. If ``item`` doesn't have an ``__xrepr__``
method it falls back to ``repr``/``__repr__`` for all modes.
"""
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 try:
func = item.__xrepr__
vivainio
Walter's ipipe patch:...
r214 except AttributeError:
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 yield (astyle.style_default, repr(item))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 else:
vivainio
Walter's ipipe patch:...
r231 try:
for x in func(mode):
yield x
Walter Doerwald
Fix warnings about ignored GeneratorExit exceptions under Python 2.5+ in ipipe.xrepr()....
r1892 except (KeyboardInterrupt, SystemExit, GeneratorExit):
vivainio
Walter's ipipe patch:...
r231 raise
except Exception:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(item))
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 xrepr = simplegeneric.generic(xrepr)
def xrepr_none(self, mode="default"):
yield (astyle.style_type_none, repr(self))
xrepr.when_object(None)(xrepr_none)
walter.doerwald
Add an xrepr implementation for the noitem object.
r519 def xrepr_noitem(self, mode="default"):
yield (2, True)
yield (astyle.style_nodata, "<?>")
xrepr.when_object(noitem)(xrepr_noitem)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def xrepr_bool(self, mode="default"):
yield (astyle.style_type_bool, repr(self))
xrepr.when_type(bool)(xrepr_bool)
def xrepr_str(self, mode="default"):
if mode == "cell":
yield (astyle.style_default, repr(self.expandtabs(tab))[1:-1])
else:
yield (astyle.style_default, repr(self))
xrepr.when_type(str)(xrepr_str)
def xrepr_unicode(self, mode="default"):
if mode == "cell":
yield (astyle.style_default, repr(self.expandtabs(tab))[2:-1])
else:
yield (astyle.style_default, repr(self))
xrepr.when_type(unicode)(xrepr_unicode)
def xrepr_number(self, mode="default"):
yield (1, True)
yield (astyle.style_type_number, repr(self))
xrepr.when_type(int)(xrepr_number)
xrepr.when_type(long)(xrepr_number)
xrepr.when_type(float)(xrepr_number)
def xrepr_complex(self, mode="default"):
yield (astyle.style_type_number, repr(self))
xrepr.when_type(complex)(xrepr_number)
def xrepr_datetime(self, mode="default"):
if mode == "cell":
# Don't use strftime() here, as this requires year >= 1900
yield (astyle.style_type_datetime,
"%04d-%02d-%02d %02d:%02d:%02d.%06d" % \
(self.year, self.month, self.day,
self.hour, self.minute, self.second,
self.microsecond),
)
else:
yield (astyle.style_type_datetime, repr(self))
xrepr.when_type(datetime.datetime)(xrepr_datetime)
def xrepr_date(self, mode="default"):
if mode == "cell":
yield (astyle.style_type_datetime,
"%04d-%02d-%02d" % (self.year, self.month, self.day))
else:
yield (astyle.style_type_datetime, repr(self))
xrepr.when_type(datetime.date)(xrepr_date)
def xrepr_time(self, mode="default"):
if mode == "cell":
yield (astyle.style_type_datetime,
"%02d:%02d:%02d.%06d" % \
(self.hour, self.minute, self.second, self.microsecond))
else:
yield (astyle.style_type_datetime, repr(self))
xrepr.when_type(datetime.time)(xrepr_time)
def xrepr_timedelta(self, mode="default"):
yield (astyle.style_type_datetime, repr(self))
xrepr.when_type(datetime.timedelta)(xrepr_timedelta)
def xrepr_type(self, mode="default"):
if self.__module__ == "__builtin__":
yield (astyle.style_type_type, self.__name__)
else:
yield (astyle.style_type_type, "%s.%s" % (self.__module__, self.__name__))
xrepr.when_type(type)(xrepr_type)
def xrepr_exception(self, mode="default"):
if self.__class__.__module__ == "exceptions":
classname = self.__class__.__name__
else:
classname = "%s.%s" % \
(self.__class__.__module__, self.__class__.__name__)
if mode == "header" or mode == "footer":
yield (astyle.style_error, "%s: %s" % (classname, self))
else:
yield (astyle.style_error, classname)
xrepr.when_type(Exception)(xrepr_exception)
def xrepr_listtuple(self, mode="default"):
if mode == "header" or mode == "footer":
if self.__class__.__module__ == "__builtin__":
classname = self.__class__.__name__
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Fix exception formatting.
r262 classname = "%s.%s" % \
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 (self.__class__.__module__,self.__class__.__name__)
yield (astyle.style_default,
"<%s object with %d items at 0x%x>" % \
(classname, len(self), id(self)))
else:
yield (-1, False)
if isinstance(self, list):
yield (astyle.style_default, "[")
end = "]"
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 yield (astyle.style_default, "(")
end = ")"
for (i, subself) in enumerate(self):
if i:
yield (astyle.style_default, ", ")
for part in xrepr(subself, "default"):
yield part
yield (astyle.style_default, end)
xrepr.when_type(list)(xrepr_listtuple)
xrepr.when_type(tuple)(xrepr_listtuple)
def xrepr_dict(self, mode="default"):
if mode == "header" or mode == "footer":
if self.__class__.__module__ == "__builtin__":
classname = self.__class__.__name__
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 classname = "%s.%s" % \
(self.__class__.__module__,self.__class__.__name__)
yield (astyle.style_default,
"<%s object with %d items at 0x%x>" % \
(classname, len(self), id(self)))
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 yield (-1, False)
if isinstance(self, dict):
yield (astyle.style_default, "{")
end = "}"
else:
yield (astyle.style_default, "dictproxy((")
end = "})"
for (i, (key, value)) in enumerate(self.iteritems()):
if i:
yield (astyle.style_default, ", ")
for part in xrepr(key, "default"):
yield part
yield (astyle.style_default, ": ")
for part in xrepr(value, "default"):
yield part
yield (astyle.style_default, end)
xrepr.when_type(dict)(xrepr_dict)
xrepr.when_type(types.DictProxyType)(xrepr_dict)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def upgradexattr(attr):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Convert an attribute descriptor string to a real descriptor object.
Walter Doerwald
Fix warnings about ignored GeneratorExit exceptions under Python 2.5+ in ipipe.xrepr()....
r1892 If attr already is a descriptor object return it unmodified. A
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 ``SelfDescriptor`` will be returned if ``attr`` is ``None``. ``"foo"``
returns an ``AttributeDescriptor`` for the attribute named ``"foo"``.
``"foo()"`` returns a ``MethodDescriptor`` for the method named ``"foo"``.
``"-foo"`` will return an ``IterAttributeDescriptor`` for the attribute
named ``"foo"`` and ``"-foo()"`` will return an ``IterMethodDescriptor``
Walter Doerwald
Fix warnings about ignored GeneratorExit exceptions under Python 2.5+ in ipipe.xrepr()....
r1892 for the method named ``"foo"``. Furthermore integers will return the appropriate
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 ``IndexDescriptor`` and callables will return a ``FunctionDescriptor``.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 if attr is None:
return selfdescriptor
elif isinstance(attr, Descriptor):
return attr
Walter Doerwald
Fix warnings about ignored GeneratorExit exceptions under Python 2.5+ in ipipe.xrepr()....
r1892 elif isinstance(attr, basestring):
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 if attr.endswith("()"):
if attr.startswith("-"):
return IterMethodDescriptor(attr[1:-2])
else:
return MethodDescriptor(attr[:-2])
else:
if attr.startswith("-"):
return IterAttributeDescriptor(attr[1:])
else:
return AttributeDescriptor(attr)
elif isinstance(attr, (int, long)):
return IndexDescriptor(attr)
elif callable(attr):
return FunctionDescriptor(attr)
else:
raise TypeError("can't handle descriptor %r" % attr)
def xattrs(item, mode="default"):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 """
Generic function that returns an iterable of attribute descriptors
to be used for displaying the attributes ob the object ``item`` in display
mode ``mode``.
There are two possible modes:
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 ``"detail"``
The ``Display`` object wants to display a detailed list of the object
attributes.
``"default"``
The ``Display`` object wants to display the object in a list view.
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415
If no implementation is registered for the object ``item`` ``xattrs`` falls
back to trying the ``__xattrs__`` method of the object. If this doesn't
exist either, ``dir(item)`` is used for ``"detail"`` mode and ``(None,)``
for ``"default"`` mode.
walter.doerwald
Fix typos in xattrs() docstring.
r966 The implementation must yield attribute descriptors (see the class
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 ``Descriptor`` for more info). The ``__xattrs__`` method may also return
walter.doerwald
Fix typos in xattrs() docstring.
r966 attribute descriptor strings (and ``None``) which will be converted to real
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 descriptors by ``upgradexattr()``.
"""
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 try:
func = item.__xattrs__
except AttributeError:
vivainio
walter's ipipe patch:...
r252 if mode == "detail":
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 for attrname in dir(item):
yield AttributeDescriptor(attrname)
vivainio
walter's ipipe patch:...
r252 else:
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 yield selfdescriptor
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 else:
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 for attr in func(mode):
yield upgradexattr(attr)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 xattrs = simplegeneric.generic(xattrs)
def xattrs_complex(self, mode="default"):
if mode == "detail":
return (AttributeDescriptor("real"), AttributeDescriptor("imag"))
return (selfdescriptor,)
xattrs.when_type(complex)(xattrs_complex)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def _isdict(item):
try:
itermeth = item.__class__.__iter__
except (AttributeError, TypeError):
return False
return itermeth is dict.__iter__ or itermeth is types.DictProxyType.__iter__
def _isstr(item):
if not isinstance(item, basestring):
return False
try:
itermeth = item.__class__.__iter__
except AttributeError:
return True
return False # ``__iter__`` has been redefined
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def xiter(item):
"""
Generic function that implements iteration for pipeline expression. If no
implementation is registered for ``item`` ``xiter`` falls back to ``iter``.
"""
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 try:
func = item.__xiter__
except AttributeError:
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 if _isdict(item):
vivainio
ipipe patch
r210 def items(item):
fields = ("key", "value")
for (key, value) in item.iteritems():
yield Fields(fields, key=key, value=value)
return items(item)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 elif isinstance(item, new.module):
def items(item):
vivainio
ipipe patch
r210 fields = ("key", "value")
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 for key in sorted(item.__dict__):
vivainio
Walter's ipipe patch:...
r214 yield Fields(fields, key=key, value=getattr(item, key))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 return items(item)
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 elif _isstr(item):
if not item:
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 raise ValueError("can't enter empty string")
walter.doerwald
IPython/Extensions/ipipe.py (xiter): Make sure that iterating...
r513 lines = item.splitlines()
if len(lines) == 1:
def iterone(item):
yield item
return iterone(item)
else:
return iter(lines)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 return iter(item)
else:
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 return iter(func()) # iter() just to be safe
xiter = simplegeneric.generic(xiter)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class ichain(Pipe):
"""
Chains multiple ``Table``s into one.
"""
def __init__(self, *iters):
self.iters = iters
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 return itertools.chain(*self.iters)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if mode == "header" or mode == "footer":
vivainio
Walter's ipipe patch #6:...
r230 for (i, item) in enumerate(self.iters):
if i:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, "+")
vivainio
Walter's ipipe patch #6:...
r230 if isinstance(item, Pipe):
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, "(")
vivainio
Walter's ipipe patch #6:...
r230 for part in xrepr(item, mode):
yield part
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if isinstance(item, Pipe):
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ")")
vivainio
Walter's ipipe patch #6:...
r230 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 args = ", ".join([repr(it) for it in self.iters])
return "%s.%s(%s)" % \
(self.__class__.__module__, self.__class__.__name__, args)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
vivainio
Walter's ipipe patch #8:...
r237 class ifile(path.path):
vivainio
More docstrings....
r215 """
file (or directory) object.
"""
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def getmode(self):
vivainio
Walter's ipipe patch #8:...
r237 return self.stat().st_mode
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 mode = property(getmode, None, None, "Access mode")
def gettype(self):
data = [
(stat.S_ISREG, "file"),
(stat.S_ISDIR, "dir"),
(stat.S_ISCHR, "chardev"),
(stat.S_ISBLK, "blockdev"),
(stat.S_ISFIFO, "fifo"),
(stat.S_ISLNK, "symlink"),
(stat.S_ISSOCK,"socket"),
]
vivainio
Walter's ipipe patch #8:...
r237 lstat = self.lstat()
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if lstat is not None:
types = set([text for (func, text) in data if func(lstat.st_mode)])
else:
types = set()
m = self.mode
types.update([text for (func, text) in data if func(m)])
return ", ".join(types)
vivainio
Walter's ipipe patch #8:...
r237 type = property(gettype, None, None, "file type (file, directory, link, etc.)")
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
vivainio
Walter's ipipe patch #8:...
r237 def getmodestr(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 m = self.mode
data = [
(stat.S_IRUSR, "-r"),
(stat.S_IWUSR, "-w"),
(stat.S_IXUSR, "-x"),
(stat.S_IRGRP, "-r"),
(stat.S_IWGRP, "-w"),
(stat.S_IXGRP, "-x"),
(stat.S_IROTH, "-r"),
(stat.S_IWOTH, "-w"),
(stat.S_IXOTH, "-x"),
]
return "".join([text[bool(m&bit)] for (bit, text) in data])
vivainio
Walter's ipipe patch #8:...
r237 modestr = property(getmodestr, None, None, "Access mode as string")
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def getblocks(self):
vivainio
Walter's ipipe patch #8:...
r237 return self.stat().st_blocks
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 blocks = property(getblocks, None, None, "File size in blocks")
def getblksize(self):
vivainio
Walter's ipipe patch #8:...
r237 return self.stat().st_blksize
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 blksize = property(getblksize, None, None, "Filesystem block size")
def getdev(self):
vivainio
Walter's ipipe patch #8:...
r237 return self.stat().st_dev
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 dev = property(getdev)
def getnlink(self):
vivainio
Walter's ipipe patch #8:...
r237 return self.stat().st_nlink
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 nlink = property(getnlink, None, None, "Number of links")
def getuid(self):
vivainio
Walter's ipipe patch #8:...
r237 return self.stat().st_uid
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 uid = property(getuid, None, None, "User id of file owner")
def getgid(self):
vivainio
Walter's ipipe patch #8:...
r237 return self.stat().st_gid
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 gid = property(getgid, None, None, "Group id of file owner")
def getowner(self):
vivainio
Walter's ipipe patch #8:...
r237 stat = self.stat()
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 try:
vivainio
Walter's ipipe patch #8:...
r237 return pwd.getpwuid(stat.st_uid).pw_name
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 except KeyError:
vivainio
Walter's ipipe patch #8:...
r237 return stat.st_uid
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 owner = property(getowner, None, None, "Owner name (or id)")
def getgroup(self):
vivainio
Walter's ipipe patch #8:...
r237 stat = self.stat()
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 try:
vivainio
Walter's ipipe patch #8:...
r237 return grp.getgrgid(stat.st_gid).gr_name
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 except KeyError:
vivainio
Walter's ipipe patch #8:...
r237 return stat.st_gid
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 group = property(getgroup, None, None, "Group name (or id)")
def getadate(self):
return datetime.datetime.utcfromtimestamp(self.atime)
adate = property(getadate, None, None, "Access date")
def getcdate(self):
return datetime.datetime.utcfromtimestamp(self.ctime)
cdate = property(getcdate, None, None, "Creation date")
def getmdate(self):
return datetime.datetime.utcfromtimestamp(self.mtime)
mdate = property(getmdate, None, None, "Modification date")
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def mimetype(self):
"""
Return MIME type guessed from the extension.
"""
vivainio
Walter's ipipe patch #8:...
r237 return mimetypes.guess_type(self.basename())[0]
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def encoding(self):
"""
Return guessed compression (like "compress" or "gzip").
"""
vivainio
Walter's ipipe patch #8:...
r237 return mimetypes.guess_type(self.basename())[1]
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
vivainio
Walter's ipipe patch #8:...
r237 def __repr__(self):
return "ifile(%s)" % path._base.__repr__(self)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
If we're running on Windows don't show owner and group...
r423 if sys.platform == "win32":
defaultattrs = (None, "type", "size", "modestr", "mdate")
else:
defaultattrs = (None, "type", "size", "modestr", "owner", "group", "mdate")
walter.doerwald
Readd ifile.defaultattrs.
r356
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xattrs__(self, mode="default"):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if mode == "detail":
vivainio
Walter's ipipe.py patch:...
r209 return (
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 "name",
"basename()",
"abspath()",
"realpath()",
"type",
"mode",
"modestr",
"stat()",
"lstat()",
"uid",
"gid",
"owner",
"group",
"dev",
"nlink",
"ctime",
"mtime",
"atime",
"cdate",
"mdate",
"adate",
"size",
"blocks",
"blksize",
"isdir()",
"islink()",
"mimetype()",
"encoding()",
"-listdir()",
"-dirs()",
"-files()",
"-walk()",
"-walkdirs()",
"-walkfiles()",
vivainio
Walter's ipipe.py patch:...
r209 )
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 else:
walter.doerwald
Readd ifile.defaultattrs.
r356 return self.defaultattrs
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def xiter_ifile(self):
if self.isdir():
yield (self / os.pardir).abspath()
for child in sorted(self.listdir()):
yield child
else:
f = self.open("rb")
for line in f:
yield line
f.close()
xiter.when_type(ifile)(xiter_ifile)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 # We need to implement ``xrepr`` for ``ifile`` as a generic function, because
# otherwise ``xrepr_str`` would kick in.
def xrepr_ifile(self, mode="default"):
try:
if self.isdir():
name = "idir"
style = astyle.style_dir
else:
name = "ifile"
style = astyle.style_file
except IOError:
name = "ifile"
style = astyle.style_default
walter.doerwald
Fix xrepr for ifiles (Bug detected by Paul Mueller).
r661 if mode in ("cell", "header", "footer"):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 abspath = repr(path._base(self.normpath()))
if abspath.startswith("u"):
abspath = abspath[2:-1]
else:
abspath = abspath[1:-1]
vivainio
Walter's ipipe patch #8:...
r237 if mode == "cell":
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 yield (style, abspath)
vivainio
Walter's ipipe patch #8:...
r237 else:
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 yield (style, "%s(%s)" % (name, abspath))
else:
yield (style, repr(self))
xrepr.when_type(ifile)(xrepr_ifile)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class ils(Table):
vivainio
More docstrings....
r215 """
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 List the current (or a specified) directory.
walter.doerwald
Add examples to docstrings....
r261
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Examples::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> ils
<class 'IPython.Extensions.ipipe.ils'>
>>> ils("/usr/local/lib/python2.4")
IPython.Extensions.ipipe.ils('/usr/local/lib/python2.4')
>>> ils("~")
IPython.Extensions.ipipe.ils('/home/fperez')
# all-random
vivainio
More docstrings....
r215 """
walter.doerwald
Add arguments dirs and files to the ils() constructor....
r365 def __init__(self, base=os.curdir, dirs=True, files=True):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 self.base = os.path.expanduser(base)
walter.doerwald
Add arguments dirs and files to the ils() constructor....
r365 self.dirs = dirs
self.files = files
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 base = ifile(self.base)
yield (base / os.pardir).abspath()
walter.doerwald
Sort directoy listings (case sensitive with files and dirs mixed).
r600 for child in sorted(base.listdir()):
walter.doerwald
Add arguments dirs and files to the ils() constructor....
r365 if self.dirs:
if self.files:
yield child
else:
if child.isdir():
yield child
elif self.files:
if not child.isdir():
yield child
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
walter.doerwald
IPython/Extensions/astyle.py: Do a relative import of ipipe, so that...
r443 return xrepr(ifile(self.base), mode)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "%s.%s(%r)" % \
(self.__class__.__module__, self.__class__.__name__, self.base)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class iglob(Table):
vivainio
More docstrings....
r215 """
walter.doerwald
Add examples to docstrings....
r261 List all files and directories matching a specified pattern.
(See ``glob.glob()`` for more info.).
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Examples::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> iglob("*.py")
IPython.Extensions.ipipe.iglob('*.py')
vivainio
More docstrings....
r215 """
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def __init__(self, glob):
self.glob = glob
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 for name in glob.glob(self.glob):
yield ifile(name)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 if mode == "header" or mode == "footer" or mode == "cell":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default,
"%s(%r)" % (self.__class__.__name__, self.glob))
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "%s.%s(%r)" % \
(self.__class__.__module__, self.__class__.__name__, self.glob)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class iwalk(Table):
vivainio
More docstrings....
r215 """
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 List all files and directories in a directory and it's subdirectory::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> iwalk
<class 'IPython.Extensions.ipipe.iwalk'>
>>> iwalk("/usr/lib")
IPython.Extensions.ipipe.iwalk('/usr/lib')
>>> iwalk("~")
IPython.Extensions.ipipe.iwalk('/home/fperez') # random
vivainio
More docstrings....
r215 """
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def __init__(self, base=os.curdir, dirs=True, files=True):
self.base = os.path.expanduser(base)
self.dirs = dirs
self.files = files
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 for (dirpath, dirnames, filenames) in os.walk(self.base):
if self.dirs:
for name in sorted(dirnames):
yield ifile(os.path.join(dirpath, name))
if self.files:
for name in sorted(filenames):
yield ifile(os.path.join(dirpath, name))
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 if mode == "header" or mode == "footer" or mode == "cell":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default,
"%s(%r)" % (self.__class__.__name__, self.base))
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "%s.%s(%r)" % \
(self.__class__.__module__, self.__class__.__name__, self.base)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class ipwdentry(object):
vivainio
More docstrings....
r215 """
``ipwdentry`` objects encapsulate entries in the Unix user account and
password database.
"""
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def __init__(self, id):
self._id = id
self._entry = None
walter.doerwald
Make igrpentry and ipwdentry comparable.
r472 def __eq__(self, other):
return self.__class__ is other.__class__ and self._id == other._id
def __ne__(self, other):
return self.__class__ is not other.__class__ or self._id != other._id
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def _getentry(self):
if self._entry is None:
if isinstance(self._id, basestring):
self._entry = pwd.getpwnam(self._id)
else:
self._entry = pwd.getpwuid(self._id)
return self._entry
def getname(self):
if isinstance(self._id, basestring):
return self._id
else:
return self._getentry().pw_name
name = property(getname, None, None, "User name")
def getpasswd(self):
return self._getentry().pw_passwd
passwd = property(getpasswd, None, None, "Password")
def getuid(self):
if isinstance(self._id, basestring):
return self._getentry().pw_uid
else:
return self._id
uid = property(getuid, None, None, "User id")
def getgid(self):
return self._getentry().pw_gid
gid = property(getgid, None, None, "Primary group id")
def getgroup(self):
return igrpentry(self.gid)
group = property(getgroup, None, None, "Group")
def getgecos(self):
return self._getentry().pw_gecos
gecos = property(getgecos, None, None, "Information (e.g. full user name)")
def getdir(self):
return self._getentry().pw_dir
dir = property(getdir, None, None, "$HOME directory")
def getshell(self):
return self._getentry().pw_shell
shell = property(getshell, None, None, "Login shell")
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xattrs__(self, mode="default"):
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 return ("name", "passwd", "uid", "gid", "gecos", "dir", "shell")
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "%s.%s(%r)" % \
(self.__class__.__module__, self.__class__.__name__, self._id)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class ipwd(Table):
vivainio
More docstrings....
r215 """
walter.doerwald
Add examples to docstrings....
r261 List all entries in the Unix user account and password database.
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Example::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> ipwd | isort("uid")
<IPython.Extensions.ipipe.isort key='uid' reverse=False at 0x849efec>
# random
vivainio
More docstrings....
r215 """
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def __iter__(self):
for entry in pwd.getpwall():
yield ipwdentry(entry.pw_name)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 if mode == "header" or mode == "footer" or mode == "cell":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, "%s()" % self.__class__.__name__)
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class igrpentry(object):
vivainio
More docstrings....
r215 """
``igrpentry`` objects encapsulate entries in the Unix group database.
"""
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def __init__(self, id):
self._id = id
self._entry = None
walter.doerwald
Make igrpentry and ipwdentry comparable.
r472 def __eq__(self, other):
return self.__class__ is other.__class__ and self._id == other._id
def __ne__(self, other):
return self.__class__ is not other.__class__ or self._id != other._id
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def _getentry(self):
if self._entry is None:
if isinstance(self._id, basestring):
self._entry = grp.getgrnam(self._id)
else:
self._entry = grp.getgrgid(self._id)
return self._entry
def getname(self):
if isinstance(self._id, basestring):
return self._id
else:
return self._getentry().gr_name
name = property(getname, None, None, "Group name")
def getpasswd(self):
return self._getentry().gr_passwd
passwd = property(getpasswd, None, None, "Password")
def getgid(self):
if isinstance(self._id, basestring):
return self._getentry().gr_gid
else:
return self._id
gid = property(getgid, None, None, "Group id")
def getmem(self):
return self._getentry().gr_mem
mem = property(getmem, None, None, "Members")
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xattrs__(self, mode="default"):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 return ("name", "passwd", "gid", "mem")
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 if mode == "header" or mode == "footer" or mode == "cell":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, "group ")
vivainio
Walter's ipipe patch #6:...
r230 try:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, self.name)
vivainio
Walter's ipipe patch #6:...
r230 except KeyError:
if isinstance(self._id, basestring):
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, self.name_id)
vivainio
Walter's ipipe patch #6:...
r230 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_type_number, str(self._id))
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 for member in self.mem:
yield ipwdentry(member)
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "%s.%s(%r)" % \
(self.__class__.__module__, self.__class__.__name__, self._id)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class igrp(Table):
vivainio
More docstrings....
r215 """
This ``Table`` lists all entries in the Unix group database.
"""
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 for entry in grp.getgrall():
yield igrpentry(entry.gr_name)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if mode == "header" or mode == "footer":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, "%s()" % self.__class__.__name__)
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
vivainio
Walter's ipipe.py patch:...
r209 class Fields(object):
def __init__(self, fieldnames, **fields):
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 self.__fieldnames = [upgradexattr(fieldname) for fieldname in fieldnames]
vivainio
Walter's ipipe.py patch:...
r209 for (key, value) in fields.iteritems():
setattr(self, key, value)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xattrs__(self, mode="default"):
vivainio
Walter's ipipe.py patch:...
r209 return self.__fieldnames
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 yield (-1, False)
if mode == "header" or mode == "cell":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, self.__class__.__name__)
yield (astyle.style_default, "(")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for (i, f) in enumerate(self.__fieldnames):
if i:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ", ")
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 yield (astyle.style_default, f.name())
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, "=")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(getattr(self, f), "default"):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ")")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 elif mode == "footer":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, self.__class__.__name__)
yield (astyle.style_default, "(")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for (i, f) in enumerate(self.__fieldnames):
if i:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ", ")
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 yield (astyle.style_default, f.name())
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ")")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
vivainio
Walter's ipipe.py patch:...
r209 class FieldTable(Table, list):
def __init__(self, *fields):
vivainio
correct minotr glitch in ipipe.FieldTable ctor
r220 Table.__init__(self)
vivainio
Walter's ipipe.py patch:...
r209 list.__init__(self)
self.fields = fields
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
vivainio
Walter's ipipe.py patch:...
r209 def add(self, **fields):
vivainio
ipipe: FieldTable adds Fields correctly now
r221 self.append(Fields(self.fields, **fields))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 yield (-1, False)
vivainio
Walter's ipipe.py patch:...
r209 if mode == "header" or mode == "footer":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, self.__class__.__name__)
yield (astyle.style_default, "(")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for (i, f) in enumerate(self.__fieldnames):
if i:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ", ")
yield (astyle.style_default, f)
yield (astyle.style_default, ")")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Walter's ipipe.py patch:...
r209
def __repr__(self):
return "<%s.%s object with fields=%r at 0x%x>" % \
(self.__class__.__module__, self.__class__.__name__,
", ".join(map(repr, self.fields)), id(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 class List(list):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xattrs__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 return xrange(len(self))
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 yield (-1, False)
if mode == "header" or mode == "cell" or mode == "footer" or mode == "default":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, self.__class__.__name__)
yield (astyle.style_default, "(")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for (i, item) in enumerate(self):
if i:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ", ")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(item, "default"):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ")")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 class ienv(Table):
vivainio
More docstrings....
r215 """
walter.doerwald
Add examples to docstrings....
r261 List environment variables.
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Example::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> ienv
<class 'IPython.Extensions.ipipe.ienv'>
vivainio
More docstrings....
r215 """
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Walter's ipipe.py patch:...
r209 fields = ("key", "value")
for (key, value) in os.environ.iteritems():
yield Fields(fields, key=key, value=value)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 if mode == "header" or mode == "cell":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, "%s()" % self.__class__.__name__)
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: Added a Table ihist that can be used to...
r683 class ihist(Table):
"""
IPython input history
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Example::
walter.doerwald
IPython/Extensions/ipipe.py: Added a Table ihist that can be used to...
r683
Fernando Perez
Fix all doctests.
r1433 >>> ihist
<class 'IPython.Extensions.ipipe.ihist'>
>>> ihist(True) # raw mode
<IPython.Extensions.ipipe.ihist object at 0x849602c> # random
walter.doerwald
IPython/Extensions/ipipe.py: Added a Table ihist that can be used to...
r683 """
walter.doerwald
Make raw mode the default.
r684 def __init__(self, raw=True):
walter.doerwald
IPython/Extensions/ipipe.py: Added a Table ihist that can be used to...
r683 self.raw = raw
def __iter__(self):
api = ipapi.get()
if self.raw:
for line in api.IP.input_hist_raw:
yield line.rstrip("\n")
else:
for line in api.IP.input_hist:
yield line.rstrip("\n")
walter.doerwald
A new ipipe table has been added: ialias produces all entries from IPython's...
r974 class Alias(object):
"""
Entry in the alias table
"""
def __init__(self, name, args, command):
self.name = name
self.args = args
self.command = command
def __xattrs__(self, mode="default"):
return ("name", "args", "command")
class ialias(Table):
"""
IPython alias list
Example::
Fernando Perez
Fix all doctests.
r1433 >>> ialias
<class 'IPython.Extensions.ipipe.ialias'>
walter.doerwald
A new ipipe table has been added: ialias produces all entries from IPython's...
r974 """
def __iter__(self):
api = ipapi.get()
for (name, (args, command)) in api.IP.alias_table.iteritems():
yield Alias(name, args, command)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 class icsv(Pipe):
vivainio
More docstrings....
r215 """
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 This ``Pipe`` turns the input (with must be a pipe outputting lines
vivainio
More docstrings....
r215 or an ``ifile``) into lines of CVS columns.
"""
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def __init__(self, **csvargs):
vivainio
More docstrings....
r215 """
Create an ``icsv`` object. ``cvsargs`` will be passed through as
keyword arguments to ``cvs.reader()``.
"""
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 self.csvargs = csvargs
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 input = self.input
if isinstance(input, ifile):
input = input.open("rb")
reader = csv.reader(input, **self.csvargs)
for line in reader:
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 yield List(line)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 yield (-1, False)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if mode == "header" or mode == "footer":
input = getattr(self, "input", None)
if input is not None:
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(input, mode):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, " | ")
yield (astyle.style_default, "%s(" % self.__class__.__name__)
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for (i, (name, value)) in enumerate(self.csvargs.iteritems()):
if i:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ", ")
yield (astyle.style_default, name)
yield (astyle.style_default, "=")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(value, "default"):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ")")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 args = ", ".join(["%s=%r" % item for item in self.csvargs.iteritems()])
return "<%s.%s %s at 0x%x>" % \
(self.__class__.__module__, self.__class__.__name__, args, id(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class ix(Table):
vivainio
More docstrings....
r215 """
walter.doerwald
Add examples to docstrings....
r261 Execute a system command and list its output as lines
vivainio
More docstrings....
r215 (similar to ``os.popen()``).
walter.doerwald
Add examples to docstrings....
r261
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Examples::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> ix("ps x")
IPython.Extensions.ipipe.ix('ps x')
>>> ix("find .") | ifile
<IPython.Extensions.ipipe.ieval expr=<class 'IPython.Extensions.ipipe.ifile'> at 0x8509d2c>
# random
vivainio
More docstrings....
r215 """
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def __init__(self, cmd):
self.cmd = cmd
walter.doerwald
Use os.popen4() so that the error output of the running...
r351 self._pipeout = None
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
walter.doerwald
Use os.popen4() so that the error output of the running...
r351 (_pipein, self._pipeout) = os.popen4(self.cmd)
_pipein.close()
for l in self._pipeout:
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 yield l.rstrip("\r\n")
walter.doerwald
Use os.popen4() so that the error output of the running...
r351 self._pipeout.close()
self._pipeout = None
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __del__(self):
walter.doerwald
Use os.popen4() so that the error output of the running...
r351 if self._pipeout is not None and not self._pipeout.closed:
self._pipeout.close()
self._pipeout = None
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if mode == "header" or mode == "footer":
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default,
"%s(%r)" % (self.__class__.__name__, self.cmd))
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "%s.%s(%r)" % \
(self.__class__.__module__, self.__class__.__name__, self.cmd)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class ifilter(Pipe):
vivainio
More docstrings....
r215 """
walter.doerwald
Add examples to docstrings....
r261 Filter an input pipe. Only objects where an expression evaluates to true
(and doesn't raise an exception) are listed.
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Examples::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> ils | ifilter("_.isfile() and size>1000")
>>> igrp | ifilter("len(mem)")
>>> sys.modules | ifilter(lambda _:_.value is not None)
# all-random
vivainio
More docstrings....
r215 """
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 def __init__(self, expr, globals=None, errors="raiseifallfail"):
vivainio
More docstrings....
r215 """
Create an ``ifilter`` object. ``expr`` can be a callable or a string
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 containing an expression. ``globals`` will be used as the global
namespace for calling string expressions (defaulting to IPython's
user namespace). ``errors`` specifies how exception during evaluation
of ``expr`` are handled:
vivainio
ipipe patch #7:...
r232
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 ``"drop"``
drop all items that have errors;
vivainio
ipipe patch #7:...
r232
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 ``"keep"``
keep all items that have errors;
vivainio
ipipe patch #7:...
r232
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 ``"keeperror"``
keep the exception of all items that have errors;
vivainio
ipipe patch #7:...
r232
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 ``"raise"``
raise the exception;
vivainio
ipipe patch #7:...
r232
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 ``"raiseifallfail"``
raise the first exception if all items have errors; otherwise drop
those with errors (this is the default).
vivainio
More docstrings....
r215 """
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 self.expr = expr
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 self.globals = globals
vivainio
ipipe patch #7:...
r232 self.errors = errors
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if callable(self.expr):
walter.doerwald
Compile expression strings into code objects. This should speed...
r349 test = self.expr
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 else:
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 g = getglobals(self.globals)
walter.doerwald
Compile expression strings into code objects. This should speed...
r349 expr = compile(self.expr, "ipipe-expression", "eval")
vivainio
ipipe patch #7:...
r232 def test(item):
walter.doerwald
Compile expression strings into code objects. This should speed...
r349 return eval(expr, g, AttrNamespace(item))
vivainio
ipipe patch #7:...
r232
ok = 0
exc_info = None
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 for item in xiter(self.input):
vivainio
ipipe patch #7:...
r232 try:
if test(item):
yield item
ok += 1
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
if self.errors == "drop":
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 pass # Ignore errors
vivainio
ipipe patch #7:...
r232 elif self.errors == "keep":
yield item
elif self.errors == "keeperror":
yield exc
elif self.errors == "raise":
raise
elif self.errors == "raiseifallfail":
if exc_info is None:
exc_info = sys.exc_info()
if not ok and exc_info is not None:
raise exc_info[0], exc_info[1], exc_info[2]
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if mode == "header" or mode == "footer":
input = getattr(self, "input", None)
if input is not None:
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(input, mode):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, " | ")
yield (astyle.style_default, "%s(" % self.__class__.__name__)
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(self.expr, "default"):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ")")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "<%s.%s expr=%r at 0x%x>" % \
(self.__class__.__module__, self.__class__.__name__,
self.expr, id(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class ieval(Pipe):
vivainio
More docstrings....
r215 """
walter.doerwald
Add examples to docstrings....
r261 Evaluate an expression for each object in the input pipe.
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Examples::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> ils | ieval("_.abspath()")
# random
>>> sys.path | ieval(ifile)
# random
vivainio
More docstrings....
r215 """
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 def __init__(self, expr, globals=None, errors="raiseifallfail"):
vivainio
More docstrings....
r215 """
Create an ``ieval`` object. ``expr`` can be a callable or a string
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 containing an expression. For the meaning of ``globals`` and
``errors`` see ``ifilter``.
vivainio
More docstrings....
r215 """
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 self.expr = expr
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 self.globals = globals
vivainio
ipipe patch #7:...
r232 self.errors = errors
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if callable(self.expr):
walter.doerwald
Compile expression strings into code objects. This should speed...
r349 do = self.expr
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 else:
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 g = getglobals(self.globals)
walter.doerwald
Compile expression strings into code objects. This should speed...
r349 expr = compile(self.expr, "ipipe-expression", "eval")
vivainio
ipipe patch #7:...
r232 def do(item):
walter.doerwald
Compile expression strings into code objects. This should speed...
r349 return eval(expr, g, AttrNamespace(item))
vivainio
ipipe patch #7:...
r232
ok = 0
exc_info = None
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 for item in xiter(self.input):
vivainio
ipipe patch #7:...
r232 try:
yield do(item)
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
if self.errors == "drop":
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 pass # Ignore errors
vivainio
ipipe patch #7:...
r232 elif self.errors == "keep":
yield item
elif self.errors == "keeperror":
yield exc
elif self.errors == "raise":
raise
elif self.errors == "raiseifallfail":
if exc_info is None:
exc_info = sys.exc_info()
if not ok and exc_info is not None:
raise exc_info[0], exc_info[1], exc_info[2]
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if mode == "header" or mode == "footer":
input = getattr(self, "input", None)
if input is not None:
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(input, mode):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, " | ")
yield (astyle.style_default, "%s(" % self.__class__.__name__)
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(self.expr, "default"):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ")")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "<%s.%s expr=%r at 0x%x>" % \
(self.__class__.__module__, self.__class__.__name__,
self.expr, id(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class ienum(Pipe):
walter.doerwald
Add examples to docstrings....
r261 """
Enumerate the input pipe (i.e. wrap each input object in an object
with ``index`` and ``object`` attributes).
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Examples::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> xrange(20) | ieval("_,_*_") | ienum | ifilter("index % 2 == 0") | ieval("object")
walter.doerwald
Add examples to docstrings....
r261 """
Fernando Perez
Fix all doctests.
r1433 skip_doctest = True
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
vivainio
Walter's ipipe.py patch:...
r209 fields = ("index", "object")
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 for (index, object) in enumerate(xiter(self.input)):
vivainio
Walter's ipipe.py patch:...
r209 yield Fields(fields, index=index, object=object)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
class isort(Pipe):
vivainio
More docstrings....
r215 """
walter.doerwald
Add examples to docstrings....
r261 Sorts the input pipe.
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Examples::
walter.doerwald
Add examples to docstrings....
r261
Fernando Perez
Fix all doctests.
r1433 >>> ils | isort("size")
<IPython.Extensions.ipipe.isort key='size' reverse=False at 0x849ec2c>
>>> ils | isort("_.isdir(), _.lower()", reverse=True)
<IPython.Extensions.ipipe.isort key='_.isdir(), _.lower()' reverse=True at 0x849eacc>
# all-random
vivainio
More docstrings....
r215 """
walter.doerwald
Make isort usable without a key argument....
r350 def __init__(self, key=None, globals=None, reverse=False):
vivainio
More docstrings....
r215 """
Create an ``isort`` object. ``key`` can be a callable or a string
walter.doerwald
Make isort usable without a key argument....
r350 containing an expression (or ``None`` in which case the items
themselves will be sorted). If ``reverse`` is true the sort order
will be reversed. For the meaning of ``globals`` see ``ifilter``.
vivainio
More docstrings....
r215 """
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 self.key = key
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 self.globals = globals
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 self.reverse = reverse
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
walter.doerwald
Make isort usable without a key argument....
r350 if self.key is None:
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 items = sorted(xiter(self.input), reverse=self.reverse)
walter.doerwald
Make isort usable without a key argument....
r350 elif callable(self.key):
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 items = sorted(xiter(self.input), key=self.key, reverse=self.reverse)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 else:
walter.doerwald
Use IPython's user namespace for the global namespace...
r276 g = getglobals(self.globals)
walter.doerwald
Compile expression strings into code objects. This should speed...
r349 key = compile(self.key, "ipipe-expression", "eval")
def realkey(item):
return eval(key, g, AttrNamespace(item))
walter.doerwald
Fix isort.__iter__() which was still using the mode...
r358 items = sorted(xiter(self.input), key=realkey, reverse=self.reverse)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 for item in items:
yield item
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if mode == "header" or mode == "footer":
input = getattr(self, "input", None)
if input is not None:
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(input, mode):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, " | ")
yield (astyle.style_default, "%s(" % self.__class__.__name__)
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(self.key, "default"):
yield part
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if self.reverse:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ", ")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 for part in xrepr(True, "default"):
yield part
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, ")")
vivainio
ipipe patch 5 from Walter Doerwald, featuring:...
r225 else:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 yield (astyle.style_default, repr(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
def __repr__(self):
vivainio
Walter's ipipe.py patch:...
r209 return "<%s.%s key=%r reverse=%r at 0x%x>" % \
(self.__class__.__module__, self.__class__.__name__,
self.key, self.reverse, id(self))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
tab = 3 # for expandtabs()
def _format(field):
if isinstance(field, str):
text = repr(field.expandtabs(tab))[1:-1]
elif isinstance(field, unicode):
text = repr(field.expandtabs(tab))[2:-1]
elif isinstance(field, datetime.datetime):
# Don't use strftime() here, as this requires year >= 1900
vivainio
Walter's ipipe.py patch:...
r209 text = "%04d-%02d-%02d %02d:%02d:%02d.%06d" % \
(field.year, field.month, field.day,
field.hour, field.minute, field.second, field.microsecond)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 elif isinstance(field, datetime.date):
text = "%04d-%02d-%02d" % (field.year, field.month, field.day)
else:
text = repr(field)
return text
class Display(object):
class __metaclass__(type):
def __ror__(self, input):
return input | self()
walter.doerwald
Add an input argument to *all* Display constructors....
r953 def __init__(self, input=None):
self.input = input
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 def __ror__(self, input):
self.input = input
return self
def display(self):
pass
class iless(Display):
cmd = "less --quit-if-one-screen --LONG-PROMPT --LINE-NUMBERS --chop-long-lines --shift=8 --RAW-CONTROL-CHARS"
def display(self):
try:
pager = os.popen(self.cmd, "w")
try:
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 for item in xiter(self.input):
first = False
for attr in xattrs(item, "default"):
if first:
first = False
else:
pager.write(" ")
attr = upgradexattr(attr)
if not isinstance(attr, SelfDescriptor):
pager.write(attr.name())
pager.write("=")
pager.write(str(attr.value(item)))
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 pager.write("\n")
finally:
pager.close()
except Exception, exc:
print "%s: %s" % (exc.__class__.__name__, str(exc))
walter.doerwald
Added a new table icap, which executes a Python string...
r711 class _RedirectIO(object):
def __init__(self,*args,**kwargs):
"""
Map the system output streams to self.
"""
self.stream = StringIO.StringIO()
self.stdout = sys.stdout
sys.stdout = self
self.stderr = sys.stderr
sys.stderr = self
def write(self, text):
"""
Write both to screen and to self.
"""
self.stream.write(text)
self.stdout.write(text)
if "\n" in text:
self.stdout.flush()
def writelines(self, lines):
"""
Write lines both to screen and to self.
"""
self.stream.writelines(lines)
self.stdout.writelines(lines)
self.stdout.flush()
def restore(self):
"""
Restore the default system streams.
"""
self.stdout.flush()
self.stderr.flush()
sys.stdout = self.stdout
sys.stderr = self.stderr
class icap(Table):
"""
Execute a python string and capture any output to stderr/stdout.
walter.doerwald
Use "::" to get proper literal blocks in the docstrings....
r973 Examples::
walter.doerwald
Added a new table icap, which executes a Python string...
r711
Fernando Perez
Fix all doctests.
r1433 >>> import time
>>> icap("for i in range(10): print i, time.sleep(0.1)")
walter.doerwald
Added a new table icap, which executes a Python string...
r711
"""
Fernando Perez
Fix all doctests.
r1433 skip_doctest = True
walter.doerwald
Added a new table icap, which executes a Python string...
r711 def __init__(self, expr, globals=None):
self.expr = expr
self.globals = globals
log = _RedirectIO()
try:
exec(expr, getglobals(globals))
finally:
log.restore()
self.stream = log.stream
def __iter__(self):
self.stream.seek(0)
for line in self.stream:
yield line.rstrip("\r\n")
def __xrepr__(self, mode="default"):
if mode == "header" or mode == "footer":
yield (astyle.style_default,
"%s(%r)" % (self.__class__.__name__, self.expr))
else:
yield (astyle.style_default, repr(self))
def __repr__(self):
return "%s.%s(%r)" % \
(self.__class__.__module__, self.__class__.__name__, self.expr)
vivainio
Walter's ipipe patch for colored idump output on windows
r247 def xformat(value, mode, maxlength):
align = None
walter.doerwald
Make left alignment and full output the default...
r279 full = True
vivainio
Walter's ipipe patch for colored idump output on windows
r247 width = 0
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 text = astyle.Text()
walter.doerwald
Only use alignment specification if it's the first...
r282 for (style, part) in xrepr(value, mode):
# only consider the first result
if align is None:
if isinstance(style, int):
# (style, text) really is (alignment, stop)
align = style
full = part
continue
else:
align = -1
full = True
if not isinstance(style, int):
text.append((style, part))
width += len(part)
vivainio
Walter's ipipe patch for colored idump output on windows
r247 if width >= maxlength and not full:
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 text.append((astyle.style_ellisis, "..."))
vivainio
Walter's ipipe patch for colored idump output on windows
r247 width += 3
break
if align is None: # default to left alignment
align = -1
return (align, width, text)
walter.doerwald
Add an input argument to *all* Display constructors....
r953
import astyle
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 class idump(Display):
vivainio
Walter's ipipe patch for colored idump output on windows
r247 # The approximate maximum length of a column entry
maxattrlength = 200
# Style for column names
walter.doerwald
Move Style and related stuff to a separate module astyle.py....
r269 style_header = astyle.Style.fromstr("white:black:bold")
vivainio
Walter's ipipe patch for colored idump output on windows
r247
walter.doerwald
Add an input argument to *all* Display constructors....
r953 def __init__(self, input=None, *attrs):
Display.__init__(self, input)
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 self.attrs = [upgradexattr(attr) for attr in attrs]
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 self.headerpadchar = " "
self.headersepchar = "|"
self.datapadchar = " "
self.datasepchar = "|"
def display(self):
vivainio
Walter's ipipe patch for colored idump output on windows
r247 stream = genutils.Term.cout
allattrs = []
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 attrset = set()
vivainio
Walter's ipipe patch for colored idump output on windows
r247 colwidths = {}
rows = []
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 for item in xiter(self.input):
vivainio
Walter's ipipe patch for colored idump output on windows
r247 row = {}
vivainio
Jorgen's cache size & overflow warning patch...
r250 attrs = self.attrs
if not attrs:
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 attrs = xattrs(item, "default")
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 for attr in attrs:
if attr not in attrset:
allattrs.append(attr)
attrset.add(attr)
colwidths[attr] = len(attr.name())
walter.doerwald
Make idump robust against exceptions during _getattr().
r255 try:
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 value = attr.value(item)
walter.doerwald
Make idump robust against exceptions during _getattr().
r255 except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
value = exc
vivainio
Walter's ipipe patch for colored idump output on windows
r247 (align, width, text) = xformat(value, "cell", self.maxattrlength)
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 colwidths[attr] = max(colwidths[attr], width)
vivainio
Walter's ipipe patch for colored idump output on windows
r247 # remember alignment, length and colored parts
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 row[attr] = (align, width, text)
vivainio
Walter's ipipe patch for colored idump output on windows
r247 rows.append(row)
stream.write("\n")
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 for (i, attr) in enumerate(allattrs):
attrname = attr.name()
self.style_header(attrname).write(stream)
spc = colwidths[attr] - len(attrname)
vivainio
Walter's ipipe patch for colored idump output on windows
r247 if i < len(colwidths)-1:
stream.write(self.headerpadchar*spc)
stream.write(self.headersepchar)
stream.write("\n")
for row in rows:
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 for (i, attr) in enumerate(allattrs):
(align, width, text) = row[attr]
spc = colwidths[attr] - width
vivainio
Walter's ipipe patch for colored idump output on windows
r247 if align == -1:
text.write(stream)
if i < len(colwidths)-1:
stream.write(self.datapadchar*spc)
elif align == 0:
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 spc = colwidths[attr] - width
vivainio
Walter's ipipe patch for colored idump output on windows
r247 spc1 = spc//2
spc2 = spc-spc1
stream.write(self.datapadchar*spc1)
text.write(stream)
if i < len(colwidths)-1:
stream.write(self.datapadchar*spc2)
else:
stream.write(self.datapadchar*spc)
text.write(stream)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if i < len(colwidths)-1:
vivainio
Walter's ipipe patch for colored idump output on windows
r247 stream.write(self.datasepchar)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 stream.write("\n")
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 class AttributeDetail(Table):
vivainio
Walter's ipipe patch:...
r214 """
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 ``AttributeDetail`` objects are use for displaying a detailed list of object
attributes.
vivainio
Walter's ipipe patch:...
r214 """
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __init__(self, object, descriptor):
self.object = object
self.descriptor = descriptor
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def __iter__(self):
return self.descriptor.iter(self.object)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 def name(self):
return self.descriptor.name()
def attrtype(self):
return self.descriptor.attrtype(self.object)
def valuetype(self):
return self.descriptor.valuetype(self.object)
def doc(self):
return self.descriptor.doc(self.object)
def shortdoc(self):
return self.descriptor.shortdoc(self.object)
def value(self):
return self.descriptor.value(self.object)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xattrs__(self, mode="default"):
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 attrs = ("name()", "attrtype()", "valuetype()", "value()", "shortdoc()")
if mode == "detail":
attrs += ("doc()",)
return attrs
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def __xrepr__(self, mode="default"):
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 yield (-1, True)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 valuetype = self.valuetype()
if valuetype is not noitem:
for part in xrepr(valuetype):
yield part
yield (astyle.style_default, " ")
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 yield (astyle.style_default, self.attrtype())
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 yield (astyle.style_default, " ")
walter.doerwald
* IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail...
r355 yield (astyle.style_default, self.name())
yield (astyle.style_default, " of ")
for part in xrepr(self.object):
yield part
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
Move ibrowse into a separate module.
r272 try:
walter.doerwald
Prefer ibrowse over igrid as the default browser.
r541 from ibrowse import ibrowse
walter.doerwald
Move ibrowse into a separate module.
r272 except ImportError:
walter.doerwald
Register ipipe's displayhooks via the generic function...
r958 # No curses (probably Windows) => try igrid
walter.doerwald
Add Nik Tautenhahns igrid extension. (igrid is a wxPython-based...
r534 try:
walter.doerwald
Prefer ibrowse over igrid as the default browser.
r541 from igrid import igrid
walter.doerwald
Add Nik Tautenhahns igrid extension. (igrid is a wxPython-based...
r534 except ImportError:
walter.doerwald
Fix typo.
r956 # no wx either => use ``idump`` as the default display.
walter.doerwald
Add Nik Tautenhahns igrid extension. (igrid is a wxPython-based...
r534 defaultdisplay = idump
else:
walter.doerwald
Prefer ibrowse over igrid as the default browser.
r541 defaultdisplay = igrid
__all__.append("igrid")
walter.doerwald
Move ibrowse into a separate module.
r272 else:
walter.doerwald
Prefer ibrowse over igrid as the default browser.
r541 defaultdisplay = ibrowse
__all__.append("ibrowse")
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208
walter.doerwald
Register ipipe's displayhooks via the generic function...
r958 # If we're running under IPython, register our objects with IPython's
# generic function ``result_display``, else install a displayhook
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 # directly as sys.displayhook
walter.doerwald
Register ipipe's displayhooks via the generic function...
r958 if generics is not None:
def display_display(obj):
return obj.display()
generics.result_display.when_type(Display)(display_display)
def display_tableobject(obj):
return display_display(defaultdisplay(obj))
generics.result_display.when_type(Table)(display_tableobject)
def display_tableclass(obj):
return display_tableobject(obj())
generics.result_display.when_type(Table.__metaclass__)(display_tableclass)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 else:
def installdisplayhook():
_originalhook = sys.displayhook
def displayhook(obj):
if isinstance(obj, type) and issubclass(obj, Table):
obj = obj()
if isinstance(obj, Table):
walter.doerwald
Use the display constructor in the ipipe displayhook instead of __or__...
r954 obj = defaultdisplay(obj)
vivainio
Added Walter Dorwald's "ipipe.py" to Extensions.
r208 if isinstance(obj, Display):
return obj.display()
else:
_originalhook(obj)
sys.displayhook = displayhook
installdisplayhook()