From d30502c8fe37bedb30ad9f3ddecd5191c5b077fb Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Wed, 28 Mar 2018 17:51:47 +0200 Subject: [PATCH] Classify trunacted input as its own exception type. --- wrw/req.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wrw/req.py b/wrw/req.py index b08afae..010e907 100644 --- a/wrw/req.py +++ b/wrw/req.py @@ -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) -- 2.11.0