Package coro :: Module frontdoor
[hide private]
[frames] | no frames]

Source Code for Module coro.frontdoor

 1  # Copyright (c) 2002-2011 IronPort Systems and Cisco Systems 
 2  #  
 3  # Permission is hereby granted, free of charge, to any person obtaining a copy 
 4  # of this software and associated documentation files (the "Software"), to deal 
 5  # in the Software without restriction, including without limitation the rights 
 6  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 7  # copies of the Software, and to permit persons to whom the Software is 
 8  # furnished to do so, subject to the following conditions: 
 9  #  
10  # The above copyright notice and this permission notice shall be included in 
11  # all copies or substantial portions of the Software. 
12  #  
13  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
14  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
15  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
16  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
17  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
18  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
19  # SOFTWARE. 
20   
21  # -*- Mode: Python -*- 
22   
23  # code is from jesse, thx. 
24   
25  import coro 
26  import termios 
27   
28  # from Python/Lib/tty.py 
29  # Indexes for termios list. 
30  IFLAG = 0 
31  OFLAG = 1 
32  CFLAG = 2 
33  LFLAG = 3 
34  ISPEED = 4 
35  OSPEED = 5 
36  CC = 6 
37   
38 -class stdin (coro.sock):
39
40 - def __init__ (self):
41 coro.sock.__init__ (self, fd=0) 42 self.fd = 0 43 self.old = termios.tcgetattr (self.fd) 44 #print 'old=%r' % (self.old,) 45 self.new = termios.tcgetattr (self.fd) 46 self.new[LFLAG] &= ~(termios.ICANON | termios.ECHO | termios.IEXTEN) 47 self.new[IFLAG] &= ~(termios.IGNBRK | termios.IXOFF | termios.IXON) 48 self.new[CC][termios.VMIN] = 1 49 self.new[CC][termios.VTIME] = 0 50 self.new[CC][termios.CINTR] = 254 # block ctrl-c? doesn't work. 51 #print 'new=%r' % (self.new,) 52 termios.tcsetattr (self.fd, termios.TCSANOW, self.new)
53
54 - def __dealloc__ (self):
55 self.restore()
56
57 - def restore (self):
58 #print '[restoring stdin to %r]' % (self.old,) 59 termios.tcsetattr (self.fd, termios.TCSAFLUSH, self.old)
60
61 - def read (self, size):
62 return self.recv (size)
63
64 - def write (self, data):
65 return self.send (data)
66
67 - def writelines (self, list):
68 return self.writev (filter (None, list))
69 70 # to use: 71 # 72 # s = stdin() 73 # while 1: 74 # block = s.recv (1024) 75 # 76 # be sure to call restore() or your terminal will be hosed. 77