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