1# Copyright 2020, Google Inc. 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: 7# 8# * Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# * Redistributions in binary form must reproduce the above 11# copyright notice, this list of conditions and the following disclaimer 12# in the documentation and/or other materials provided with the 13# distribution. 14# * Neither the name of Google Inc. nor the names of its 15# contributors may be used to endorse or promote products derived from 16# this software without specific prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29"""Stream Exceptions. 30""" 31 32# Note: request.connection.write/read are used in this module, even though 33# mod_python document says that they should be used only in connection 34# handlers. Unfortunately, we have no other options. For example, 35# request.write/read are not suitable because they don't allow direct raw bytes 36# writing/reading. 37 38 39# Exceptions 40class ConnectionTerminatedException(Exception): 41 """This exception will be raised when a connection is terminated 42 unexpectedly. 43 """ 44 45 pass 46 47 48class InvalidFrameException(ConnectionTerminatedException): 49 """This exception will be raised when we received an invalid frame we 50 cannot parse. 51 """ 52 53 pass 54 55 56class BadOperationException(Exception): 57 """This exception will be raised when send_message() is called on 58 server-terminated connection or receive_message() is called on 59 client-terminated connection. 60 """ 61 62 pass 63 64 65class UnsupportedFrameException(Exception): 66 """This exception will be raised when we receive a frame with flag, opcode 67 we cannot handle. Handlers can just catch and ignore this exception and 68 call receive_message() again to continue processing the next frame. 69 """ 70 71 pass 72 73 74class InvalidUTF8Exception(Exception): 75 """This exception will be raised when we receive a text frame which 76 contains invalid UTF-8 strings. 77 """ 78 79 pass 80 81 82# vi:sts=4 sw=4 et 83