]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/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]
8 """A callable class that calls a method passed as a parameter.
10 Good for creating a pseudo keyword in the python runtime
11 environment. The keyword is really an object that has a repr()
12 that calls itself which calls the method that was passed in the
13 init of the object. All this just to avoid having to type in the
14 closing parens on a method. So, for example:
16 >>> quit = PseudoKeyword(SomeObject.someMethod)
19 SomeObject.someMethod gets executed as if it had been called
20 directly and the user didn't have to type the parens, like
21 "quit()". This technique is most applicable for pseudo keywords
22 like quit, exit and help.
24 If SomeObject.someMethod can take parameters, they can still be
25 passed by using the keyword in the traditional way with parens.
27 def __init__(self
, method
):
28 """Create a callable object that executes method when called."""
33 raise ValueError, 'method must be callable'
35 def __call__(self
, *args
, **kwds
):
36 self
.method(*args
, **kwds
)
46 """Create a file-like object."""
55 def writelines(self
, l
):
65 class PseudoFileIn(PseudoFile
):
67 def __init__(self
, readline
):
68 if callable(readline
):
69 self
.readline
= readline
71 raise ValueError, 'readline must be callable'
77 class PseudoFileOut(PseudoFile
):
79 def __init__(self
, write
):
83 raise ValueError, 'write must be callable'
89 class PseudoFileErr(PseudoFile
):
91 def __init__(self
, write
):
95 raise ValueError, 'write must be callable'