~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/DebugClients/Python/AsyncIOBase.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
# Copyright (c) 2002 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
4
 
# Copyright (c) 2000 Phil Thompson <phil@river-bank.demon.co.uk>
5
 
#
6
 
 
7
 
"""
8
 
Module implementing a Qt free base class of an asynchronous interface for the debugger.
9
 
"""
10
 
 
11
 
 
12
 
class AsyncIOBase:
13
 
    """
14
 
    Class implementing asynchronous reading and writing.
15
 
    """
16
 
    def __init__(self):
17
 
        """
18
 
        Constructor
19
 
        
20
 
        @param parent the optional parent of this object (QObject) (ignored)
21
 
        """
22
 
        # There is no connection yet.
23
 
        self.disconnect()
24
 
 
25
 
    def disconnect(self):
26
 
        """
27
 
        Public method to disconnect any current connection.
28
 
        """
29
 
        self.readfd = None
30
 
        self.writefd = None
31
 
 
32
 
    def setDescriptors(self,rfd,wfd):
33
 
        """
34
 
        Public method called to set the descriptors for the connection.
35
 
        
36
 
        @param rfd file descriptor of the input file (int)
37
 
        @param wfd file descriptor of the output file (int)
38
 
        """
39
 
        self.rbuf = ''
40
 
        self.readfd = rfd
41
 
 
42
 
        self.wbuf = ''
43
 
        self.writefd = wfd
44
 
 
45
 
    def readReady(self,fd):
46
 
        """
47
 
        Protected method called when there is data ready to be read.
48
 
        
49
 
        @param fd file descriptor of the file that has data to be read (int)
50
 
        """
51
 
        try:
52
 
            got = self.readfd.readline_p()
53
 
        except:
54
 
            return
55
 
 
56
 
        if len(got) == 0:
57
 
            self.sessionClose()
58
 
            return
59
 
 
60
 
        self.rbuf = self.rbuf + got
61
 
 
62
 
        # Call handleLine for the line if it is complete.
63
 
        eol = self.rbuf.find('\n')
64
 
 
65
 
        while eol >= 0:
66
 
            s = self.rbuf[:eol + 1]
67
 
            self.rbuf = self.rbuf[eol + 1:]
68
 
            self.handleLine(s)
69
 
            eol = self.rbuf.find('\n')
70
 
 
71
 
    def writeReady(self,fd):
72
 
        """
73
 
        Protected method called when we are ready to write data.
74
 
        
75
 
        @param fd file descriptor of the file that has data to be written (int)
76
 
        """
77
 
        self.writefd.write(self.wbuf)
78
 
        self.writefd.flush()
79
 
        self.wbuf = ''
80
 
 
81
 
    def write(self,s):
82
 
        """
83
 
        Public method to write a string.
84
 
        
85
 
        @param s the data to be written (string)
86
 
        """
87
 
        self.wbuf = self.wbuf + s