Classify trunacted input as its own exception type.
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 28 Mar 2018 15:51:47 +0000 (17:51 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 28 Mar 2018 15:51:47 +0000 (17:51 +0200)
wrw/req.py

index b08afae..010e907 100644 (file)
@@ -51,6 +51,10 @@ def fixcase(str):
         i += 1
     return str
 
+class shortinput(IOError, EOFError):
+    def __init__(self):
+        super().__init__("Unexpected EOF")
+
 class limitreader(object):
     def __init__(self, back, limit):
         self.bk = back
@@ -68,7 +72,7 @@ class limitreader(object):
         while len(self.buf) < ra:
             ret = self.bk.read(ra - len(self.buf))
             if ret == b"":
-                raise IOError("Unexpected EOF")
+                raise shortinput()
             self.buf.extend(ret)
             self.rb += len(ret)
         ret = bytes(self.buf[:ra])
@@ -98,7 +102,7 @@ class limitreader(object):
             ra = min(ra, 1024)
             ret = self.bk.read(ra)
             if ret == b"":
-                raise IOError("Unpexpected EOF")
+                raise shortinput()
             self.buf.extend(ret)
             self.rb += len(ret)