]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/pseudo.py
d231dc26474c1eac18163d28fd32aae2a5c7c70f
1 """Provides a variety of classes to create pseudo keywords and pseudo files."""
3 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __version__
= "$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."""
30 # XXX Should probably check that this is a callable object.
33 def __call__(self
, *args
, **kwds
):
34 self
.method(*args
, **kwds
)
44 """Create a file-like object."""
53 def writelines(self
, l
):
63 class PseudoFileIn(PseudoFile
):
65 def __init__(self
, readline
):
66 self
.readline
= readline
72 class PseudoFileOut(PseudoFile
):
74 def __init__(self
, write
):
81 class PseudoFileErr(PseudoFile
):
83 def __init__(self
, write
):