]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/py/pseudo.py
   1 """Provides a variety of classes to create pseudo keywords and pseudo files.""" 
   3 __author__ 
= "Patrick K. O'Brien <pobrien@orbtech.com>" 
   5 __revision__ 
= "$Revision$"[11:-2] 
  15     """A callable class that calls a method passed as a parameter. 
  17     Good for creating a pseudo keyword in the python runtime 
  18     environment. The keyword is really an object that has a repr() 
  19     that calls itself which calls the method that was passed in the 
  20     init of the object. All this just to avoid having to type in the 
  21     closing parens on a method. So, for example: 
  23         >>> quit = PseudoKeyword(SomeObject.someMethod) 
  26     SomeObject.someMethod gets executed as if it had been called 
  27     directly and the user didn't have to type the parens, like 
  28     'quit()'. This technique is most applicable for pseudo keywords 
  29     like quit, exit and help. 
  31     If SomeObject.someMethod can take parameters, they can still be 
  32     passed by using the keyword in the traditional way with parens.""" 
  34     def __init__(self
, method
): 
  35         """Create a callable object that executes method when called.""" 
  40             raise ValueError, 'method must be callable' 
  42     def __call__(self
, *args
, **kwds
): 
  43         self
.method(*args
, **kwds
) 
  53         """Create a file-like object.""" 
  62     def writelines(self
, l
): 
  72 class PseudoFileIn(PseudoFile
): 
  74     def __init__(self
, readline
, readlines
=None): 
  75         if callable(readline
): 
  76             self
.readline 
= readline
 
  78             raise ValueError, 'readline must be callable' 
  79         if callable(readlines
): 
  80             self
.readlines 
= readlines
 
  86 class PseudoFileOut(PseudoFile
): 
  88     def __init__(self
, write
): 
  92             raise ValueError, 'write must be callable' 
  98 class PseudoFileErr(PseudoFile
): 
 100     def __init__(self
, write
): 
 104             raise ValueError, 'write must be callable'