/[anoncvs]/projects/dispense2/sql-edition/servers/VendingMachine.py


UCC Code Repository

Diff of /projects/dispense2/sql-edition/servers/VendingMachine.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by dagobah, Sun Jun 27 18:38:29 2004 UTC revision 1.8 by cameron, Sat Jul 31 09:39:34 2004 UTC
# Line 12  DOOR = 1 Line 12  DOOR = 1
12  SWITCH = 2  SWITCH = 2
13  KEY = 3  KEY = 3
14    
15    class VendingException(Exception): pass
16    
17  class VendingMachine:  class VendingMachine:
18          def __init__(self, rfh, wfh):          def __init__(self, rfh, wfh):
19                  self.events = []                  self.events = []
# Line 27  class VendingMachine: Line 29  class VendingMachine:
29                  self.wfh.write('PING\n')                  self.wfh.write('PING\n')
30                  code = ''                  code = ''
31                  while code != '000':                  while code != '000':
32                          (code, _) = self.get_response()                          code = self.get_response()[0]
33                  self.get_switches()                  self.get_switches()
34    
35          def await_prompt(self):          def await_prompt(self):
# Line 36  class VendingMachine: Line 38  class VendingMachine:
38                  prefix = ''                  prefix = ''
39                  s = ''                  s = ''
40                  while True:                  while True:
41                          s = self.rfh.read(1)                          try:
42                          if s == '': raise Exception('nothing read!')                                  s = self.rfh.read(1)
43                            except socket.error:
44                                    print "Blah, seems DEC server has fallen over"
45                                    raise VendingException('failed to read input from vending machine')
46                            if s == '': raise VendingException('nothing read!')
47                          if s == '\n' or s == '\r':                          if s == '\n' or s == '\r':
48                                  state = 1                                  state = 1
49                                  prefix = ''                                  prefix = ''

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26