]>
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]
9 """A callable class that calls a method passed as a parameter.
11 Good for creating a pseudo keyword in the python runtime
12 environment. The keyword is really an object that has a repr()
13 that calls itself which calls the method that was passed in the
14 init of the object. All this just to avoid having to type in the
15 closing parens on a method. So, for example:
17 >>> quit = PseudoKeyword(SomeObject.someMethod)
20 SomeObject.someMethod gets executed as if it had been called
21 directly and the user didn't have to type the parens, like
22 'quit()'. This technique is most applicable for pseudo keywords
23 like quit, exit and help.
25 If SomeObject.someMethod can take parameters, they can still be
26 passed by using the keyword in the traditional way with parens."""
28 def __init__(self
, method
):
29 """Create a callable object that executes method when called."""
34 raise ValueError, 'method must be callable'
36 def __call__(self
, *args
, **kwds
):
37 self
.method(*args
, **kwds
)
47 """Create a file-like object."""
56 def writelines(self
, l
):
66 class PseudoFileIn(PseudoFile
):
68 def __init__(self
, readline
, readlines
=None):
69 if callable(readline
):
70 self
.readline
= readline
72 raise ValueError, 'readline must be callable'
73 if callable(readlines
):
74 self
.readlines
= readlines
80 class PseudoFileOut(PseudoFile
):
82 def __init__(self
, write
):
86 raise ValueError, 'write must be callable'
92 class PseudoFileErr(PseudoFile
):
94 def __init__(self
, write
):
98 raise ValueError, 'write must be callable'