]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/pseudo.py
c709a8351ca40a507069bbac83738e901c9b9be0
[wxWidgets.git] / wxPython / wxPython / lib / PyCrust / pseudo.py
1 """Provides a variety of classes to create pseudo keywords and pseudo files."""
2
3 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
4 __cvsid__ = "$Id$"
5 __date__ = "July 1, 2001"
6 __version__ = "$Revision$"[11:-2]
7
8 class PseudoKeyword:
9 """A callable class that calls a method passed as a parameter.
10
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:
16
17 >>> quit = PseudoKeyword(SomeObject.someMethod)
18 >>> quit
19
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.
24
25 If SomeObject.someMethod can take parameters, they can still be
26 passed by using the keyword in the traditional way with parens.
27 """
28 def __init__(self, method):
29 """Create a callable object that executes method when called."""
30
31 # XXX Should probably check that this is a callable object.
32 self.method = method
33
34 def __call__(self, *args, **kwds):
35 self.method(*args, **kwds)
36
37 def __repr__(self):
38 self()
39 return ''
40
41
42 class PseudoFile:
43
44 def __init__(self):
45 """Create a file-like object."""
46 pass
47
48 def readline(self):
49 pass
50
51 def write(self, s):
52 pass
53
54 def writelines(self, l):
55 map(self.write, l)
56
57 def flush(self):
58 pass
59
60 def isatty(self):
61 pass
62
63
64 class PseudoFileIn(PseudoFile):
65
66 def __init__(self, readline):
67 self.readline = readline
68
69 def isatty(self):
70 return 1
71
72
73 class PseudoFileOut(PseudoFile):
74
75 def __init__(self, write):
76 self.write = write
77
78 def isatty(self):
79 return 1
80
81
82 class PseudoFileErr(PseudoFile):
83
84 def __init__(self, write):
85 self.write = write
86
87 def isatty(self):
88 return 1
89
90