Package libprs500 :: Module errors
[hide private]
[frames] | no frames]

Source Code for Module libprs500.errors

 1  ##    Copyright (C) 2006 Kovid Goyal kovid@kovidgoyal.net 
 2  ##    This program is free software; you can redistribute it and/or modify 
 3  ##    it under the terms of the GNU General Public License as published by 
 4  ##    the Free Software Foundation; either version 2 of the License, or 
 5  ##    (at your option) any later version. 
 6  ## 
 7  ##    This program is distributed in the hope that it will be useful, 
 8  ##    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 9  ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
10  ##    GNU General Public License for more details. 
11  ## 
12  ##    You should have received a copy of the GNU General Public License along 
13  ##    with this program; if not, write to the Free Software Foundation, Inc., 
14  ##    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
15  """ 
16  Defines the errors that libprs500 generates. 
17   
18  G{classtree ProtocolError} 
19  """ 
20  from exceptions import Exception 
21   
22 -class ProtocolError(Exception):
23 """ The base class for all exceptions in this package """
24 - def __init__(self, msg):
25 Exception.__init__(self, msg)
26
27 -class PacketError(ProtocolError):
28 """ Errors with creating/interpreting packets """
29
30 -class ArgumentError(ProtocolError):
31 """ Errors caused by invalid arguments to a public interface function """
32
33 -class PathError(ArgumentError):
34 """ When a user supplies an incorrect/invalid path """
35
36 -class ControlError(ProtocolError):
37 """ Errors in Command/Response pairs while communicating with the device """
38 - def __init__(self, query=None, response=None, desc=None):
39 self.query = query 40 self.response = response 41 Exception.__init__(self, desc)
42
43 - def __str__(self):
44 if self.query and self.response: 45 return "Got unexpected response:\n" + \ 46 "query:\n"+str(self.query.query)+"\n"+\ 47 "expected:\n"+str(self.query.response)+"\n" +\ 48 "actual:\n"+str(self.response) 49 if self.desc: 50 return self.desc 51 return "Unknown control error occurred"
52