Package httxlib :: Module httxerror
[hide private]
[frames] | no frames]

Source Code for Module httxlib.httxerror

  1  #!/usr/bin/env python 
  2  # -*- coding: latin-1; py-indent-offset:4 -*- 
  3  ################################################################################ 
  4  #  
  5  # This file is part of HttxLib 
  6  # 
  7  # HttxLib is an HTTP(s) Python library suited multithreaded/multidomain 
  8  # applications 
  9  # 
 10  # Copyright (C) 2010-2011 Daniel Rodriguez (aka Daniel Rodriksson) 
 11  # Copyright (C) 2011 Sensible Odds Ltd 
 12  # 
 13  # You can learn more and contact the author at: 
 14  # 
 15  #    http://code.google.com/p/httxlib/ 
 16  # 
 17  # HttxLib is free software: you can redistribute it and/or modify 
 18  # it under the terms of the GNU General Public License as published by 
 19  # the Free Software Foundation, either version 3 of the License, or 
 20  # (at your option) any later version. 
 21  # 
 22  # HttxLib is distributed in the hope that it will be useful, 
 23  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 24  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 25  # GNU General Public License for more details. 
 26  # 
 27  # You should have received a copy of the GNU General Public License 
 28  # along with HttxLib. If not, see <http://www.gnu.org/licenses/>. 
 29  # 
 30  ################################################################################ 
 31  ''' 
 32  Implementation of Exceptions raised by HttxLib 
 33   
 34  Because HttxLib is built on top of httplib, all exceptions derive from 
 35  HTTPException to enable a catch-all case 
 36  ''' 
 37   
 38  from httplib import HTTPException 
 39   
 40   
41 -class SocketException(HTTPException):
42 ''' 43 A class representing a socket exception like closed connection, 44 timeout, dns failure resolution and others 45 46 HTTPException is HTTP centered, but the HttxLib wants to isolate 47 the user from having to install their own except for a socket 48 exception and therefore socket errors are caught 49 ''' 50
51 - def __init__(self, *args):
52 ''' 53 Constructor. Passes the args to Exception as explicitly stated 54 in the HTTPException definition in httplib.py 55 56 @param args: list of arguments 57 @type args: tuple 58 ''' 59 Exception.__init__(self, *args)
60 61 62 # Alias 63 HttxSocketException = SocketException 64 65
66 -class HttxException(HTTPException):
67 ''' 68 A class representing a HTTP related exceptions raised by HttxLib 69 70 @ivar response: response that has triggered the exception 71 @type response: L{HttxResponse} 72 ''' 73
74 - def __init__(self, response, *args):
75 ''' 76 Constructor. Passes the args to Exception as explicitly stated 77 in the HTTPException definition in httplib.py 78 79 @param response: response that has triggered the exception 80 @type response: L{HttxResponse} 81 @param args: list of arguments 82 @type args: tuple 83 ''' 84 Exception.__init__(self, *args) 85 self.response = response
86 87
88 -class RedirectError(HttxException):
89 ''' 90 A class representing a redirection error (like missing location header, 91 not allowed in a POST request and others) 92 ''' 93
94 - def __init__(self, response, *args):
95 ''' 96 Constructor. Delegates construction to the base class L{HttxException} 97 98 @param response: response that has triggered the exception 99 @type response: L{HttxResponse} 100 @param args: list of arguments 101 @type args: tuple 102 ''' 103 HttxException.__init__(self, response, *args)
104 105
106 -class MaxRedirectError(RedirectError):
107 ''' 108 A class representing an error because the configure maxiumum number 109 of redirections has been reached 110 ''' 111
112 - def __init__(self, response, *args):
113 ''' 114 Constructor. Delegates construction to the base class L{HttxException} 115 116 @param response: response that has triggered the exception 117 @type response: L{HttxResponse} 118 @param args: list of arguments 119 @type args: tuple 120 ''' 121 HttxException.__init__(self, response, *args)
122 123
124 -class ExternalRedirectError(RedirectError):
125 ''' 126 A class representing an error because external redirections are disabled 127 but the response redirected to an external host 128 '''
129 - def __init__(self, response, *args):
130 ''' 131 Constructor. Delegates construction to the base class L{HttxException} 132 133 @param response: response that has triggered the exception 134 @type response: L{HttxResponse} 135 @param args: list of arguments 136 @type args: tuple 137 ''' 138 HttxException.__init__(self, response, *args)
139