summaryrefslogtreecommitdiffstats
path: root/Lib/encodings/utf_8_sig.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/encodings/utf_8_sig.py')
-rw-r--r--Lib/encodings/utf_8_sig.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/encodings/utf_8_sig.py b/Lib/encodings/utf_8_sig.py
index 92678d2..697ba95 100644
--- a/Lib/encodings/utf_8_sig.py
+++ b/Lib/encodings/utf_8_sig.py
@@ -84,12 +84,18 @@ class StreamReader(codecs.StreamReader):
pass
def decode(self, input, errors='strict'):
- if len(input) < 3 and codecs.BOM_UTF8.startswith(input):
- # not enough data to decide if this is a BOM
- # => try again on the next call
- return (u"", 0)
+ if len(input) < 3:
+ if codecs.BOM_UTF8.startswith(input):
+ # not enough data to decide if this is a BOM
+ # => try again on the next call
+ return (u"", 0)
+ elif input[:3] == codecs.BOM_UTF8:
+ self.decode = codecs.utf_8_decode
+ (output, consumed) = codecs.utf_8_decode(input[3:],errors)
+ return (output, consumed+3)
+ # (else) no BOM present
self.decode = codecs.utf_8_decode
- return decode(input, errors)
+ return codecs.utf_8_decode(input, errors)
### encodings module API