Module Command :: Class stacker
[hide private]

Class stacker

source code

object --+
         |
        stacker
Known Subclasses:

A mixin that accumulates options and provides a factory for instances of the same class.

stacker saves the list of arguments and the dictionairy of keywords. It also offers a callable interface that acts as af factory of new instance of a a class. When called it combines all stored arguments and keywords with additional ones. This facilitates the following pattern:

   RefToMyObjectInstance -option | ...

Here option is a reference to an instance of the class option. What happens in this example is this (pseudocode):

   RefToMyObjectInstance = MyObject(option1=value)
   RefToMyObjectInstance -option | ...
   
   RefToMyObjectInstance.__sub__(option2)
       calls:
   RefToMyObjectInstance.__cal__(options2.name=option2.value)
       results in:
   an (anonymous) object of the same class as RefToMyObjectInstance with
   both options (option1 and option2) set.
Instance Methods [hide private]
 
__call__(self, *args, **kw)
Facilitates using a instance as a factory for the class it belongs to.
source code
 
__init__(self, *args, **kw)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__sub__(self, right) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__call__(self, *args, **kw)
(Call operator)

source code 

Facilitates using a instance as a factory for the class it belongs to.

This way we can create an instance of a class with the same name as a class to be used as a shortcut when calling without arguments while creating seperate anonimous instances when calling with arguments.

Example: for a class 'ls' we can now do this in Command.py:

   ls=ls()

This way we can now write the following:

   from Command import *

   ls | sort > stdout

while we can still write:

   ls('*.txt') | sort(reverse=true) > stdout

extra arguments and options are accumlated which allows us to write (with the help of the __sub__ operator defined in the stacker class:

   ...| grep('aaa') -i -v | ...

here we create a grep instance and then a new grep instance is created with the -i (i.e. the __sub__ method on the grep instance is called with the predefined i (and instance of the option class).)

__init__(self, *args, **kw)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)