1import binascii 2 3from six import PY3 4 5 6class FormParserError(ValueError): 7 """Base error class for our form parser.""" 8 pass 9 10 11class ParseError(FormParserError): 12 """This exception (or a subclass) is raised when there is an error while 13 parsing something. 14 """ 15 16 #: This is the offset in the input data chunk (*NOT* the overall stream) in 17 #: which the parse error occured. It will be -1 if not specified. 18 offset = -1 19 20 21class MultipartParseError(ParseError): 22 """This is a specific error that is raised when the MultipartParser detects 23 an error while parsing. 24 """ 25 pass 26 27 28class QuerystringParseError(ParseError): 29 """This is a specific error that is raised when the QuerystringParser 30 detects an error while parsing. 31 """ 32 pass 33 34 35class DecodeError(ParseError): 36 """This exception is raised when there is a decoding error - for example 37 with the Base64Decoder or QuotedPrintableDecoder. 38 """ 39 pass 40 41 42# On Python 3.3, IOError is the same as OSError, so we don't want to inherit 43# from both of them. We handle this case below. 44if IOError is not OSError: # pragma: no cover 45 class FileError(FormParserError, IOError, OSError): 46 """Exception class for problems with the File class.""" 47 pass 48else: # pragma: no cover 49 class FileError(FormParserError, OSError): 50 """Exception class for problems with the File class.""" 51 pass 52 53# We check which version of Python we're on to figure out what error we need 54# to catch for invalid Base64. 55if PY3: # pragma: no cover 56 Base64Error = binascii.Error 57else: # pragma: no cover 58 Base64Error = TypeError 59