Update of /cvsroot/freevo/freevo/WIP/RobShortt/lib/vdrpylib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv887/lib/vdrpylib

Modified Files:
        svdrp.py 
Log Message:
Add close_connection which makes SVDRP close the connection after each command
because unfortunately the SVDRP interface only supports one open 
connection (HELLO?!?!).

Also debug some serious blocking bugs and make it fast, even while closing
the connection after each command.



Index: svdrp.py
===================================================================
RCS file: /cvsroot/freevo/freevo/WIP/RobShortt/lib/vdrpylib/svdrp.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** svdrp.py    19 Jul 2004 12:17:29 -0000      1.1
--- svdrp.py    21 Jul 2004 03:17:41 -0000      1.2
***************
*** 70,86 ****
        the plain telnet interface may also be used to drive the
        protocol manually.
        """
!       def __init__(self, host = None, port = SVDRP_PORT):
                  self.host = host
                  self.port = port
  
!               if host is None:
!                       telnetlib.Telnet.__init__(self)
!               else:
!                       telnetlib.Telnet.__init__(self, self.host, self.port)
!                       # consume all output
!                       result = ''
!                       while not result:
!                               result = self.read_very_eager()
  
        
--- 70,88 ----
        the plain telnet interface may also be used to drive the
        protocol manually.
+ 
+       close_connection makes SVDRP close the connection after each command
+       because unfortunately the SVDRP interface only supports one open 
+       connection (HELLO?!?!).
        """
!       def __init__(self, host, port = SVDRP_PORT, close_connection = 1):
                  self.host = host
                  self.port = port
+                 self.close_connection = close_connection
  
!               telnetlib.Telnet.__init__(self, self.host, self.port)
!                 #print 'RLS: after telnet init'
! 
!               if self.close_connection:
!                       self.close()
  
        
***************
*** 93,105 ****
                Don't try to reopen an already connected instance.
                """
                  if host:
                    telnetlib.Telnet.open(self, host, port)
!                 elif self.host:
                    telnetlib.Telnet.open(self, self.host, self.port)
  
  
        def close(self):
!                 self.write_cmd('quit')
                telnetlib.Telnet.close(self)
  
  
--- 95,129 ----
                Don't try to reopen an already connected instance.
                """
+               #print 'RLS: in open 1'
+                 if not host and not self.host:
+                     return
+ 
+                 if self.get_socket():
+                   return
+ 
                  if host:
+                   #print 'RLS: in open 2'
                    telnetlib.Telnet.open(self, host, port)
!                 else:
!                   #print 'RLS: in open 3'
                    telnetlib.Telnet.open(self, self.host, self.port)
  
+               #time.sleep(0.2)
+ 
+               # consume all output
+               result = ''
+               while not result:
+                       #print 'RLS: reading very eager'
+                       result = self.read_very_eager()
+                       #print 'RLS: read'
+               #print 'RLS: result="%s"' % result
+ 
  
        def close(self):
!                 self.write('quit\n')
!               reply = self.read_reply()
!               #time.sleep(0.2)
                telnetlib.Telnet.close(self)
+               return reply
  
  
***************
*** 116,130 ****
                """
                pat = re.compile('^\d\d\d .*\n', re.M)
!               reply = ''
!               buffer = self.read_very_eager()
!               while not pat.search(buffer):
!                       reply = reply + buffer
!                       time.sleep(0.2)
                        buffer = self.read_very_eager()
!               reply = reply + buffer
                return reply
  
  
!       def write_cmd(self, cmd):
                """Send text to the server and return its reply.
                
--- 140,158 ----
                """
                pat = re.compile('^\d\d\d .*\n', re.M)
!               #reply = ''
!               reply = self.read_very_eager()
!               #print 'RLS: initial reply "%s"' % reply
!               while not pat.search(reply):
                        buffer = self.read_very_eager()
!                       reply = reply + buffer
!                       #print 'RLS: reply now "%s"' % reply
!                       #time.sleep(0.2)
!                       #buffer = self.read_very_eager()
!                       #print 'RLS: reading reply got "%s"' % buffer
!               #reply = reply + buffer
                return reply
  
  
!       def write_cmd(self, cmd, close = -1):
                """Send text to the server and return its reply.
                
***************
*** 138,146 ****
                if len(cmd) == 0:
                        return ''
                if cmd[-1] != '\n':
                        cmd = cmd + '\n'
                self.read_very_eager()
                self.write(cmd)
!               return self.read_reply()
  
        
--- 166,187 ----
                if len(cmd) == 0:
                        return ''
+ 
+                 self.open()
+ 
                if cmd[-1] != '\n':
                        cmd = cmd + '\n'
                self.read_very_eager()
                self.write(cmd)
!               #time.sleep(0.2)
!                 reply = self.read_reply()
! 
!                 if close > 0:
!                     self.close()
!                   #print 'RLS: want to close %d' % close
!                 elif close == -1 and self.close_connection:
!                   #print 'RLS: want to close %d' % close
!                     self.close()
! 
!               return reply
  
        
***************
*** 189,192 ****
--- 230,240 ----
        
  
+       def current_chan(self):
+               """
+               Return the currently tuned channel.
+               """
+               return self.write_cmd('chan\n')
+ 
+ 
        def lstc(self, id = None):
                """List channel details.
***************
*** 237,241 ****
                successfully, false else.
                """
!               result = self.write_cmd('pute\n')
                if result[0:3] != '354':
                        print 'pute returned: ' + result
--- 285,289 ----
                successfully, false else.
                """
!               result = self.write_cmd('pute\n', close = 0)
                if result[0:3] != '354':
                        print 'pute returned: ' + result
***************
*** 247,250 ****
--- 295,302 ----
  
                result = self.read_reply()
+            
+                 if self.close_connection:
+                       self.close()
+ 
                if result[0:3] != '250':
                        print 'pute returned: ' + result



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to