Skip to content

Commit 808d102

Browse files
SimonSapingsnedders
authored andcommitted
Add a documentEncoding property to HTML5Parser, fix html5lib#121.
1 parent 3c3dd75 commit 808d102

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

html5lib/html5parser.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ def reset(self):
129129

130130
self.framesetOK = True
131131

132+
@property
133+
def documentEncoding(self):
134+
"""The name of the character encoding
135+
that was used to decode the input stream,
136+
or :obj:`None` if that is not determined yet.
137+
138+
"""
139+
if not hasattr(self, 'tokenizer'):
140+
return None
141+
return self.tokenizer.stream.charEncoding[0]
142+
132143
def isHTMLIntegrationPoint(self, element):
133144
if (element.name == "annotation-xml" and
134145
element.namespace == namespaces["mathml"]):

html5lib/tests/test_encoding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ def test_codec_name_d(self):
2828

2929
def runParserEncodingTest(data, encoding):
3030
p = HTMLParser()
31+
assert p.documentEncoding is None
3132
p.parse(data, useChardet=False)
3233
encoding = encoding.lower().decode("ascii")
3334

34-
assert encoding == p.tokenizer.stream.charEncoding[0], errorMessage(data, encoding, p.tokenizer.stream.charEncoding[0])
35+
assert encoding == p.documentEncoding, errorMessage(data, encoding, p.documentEncoding)
3536

3637

3738
def runPreScanEncodingTest(data, encoding):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy