Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit808d102

Browse files
SimonSapingsnedders
authored andcommitted
Add a documentEncoding property to HTML5Parser,fixhtml5lib#121.
1 parent3c3dd75 commit808d102

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+
defdocumentEncoding(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+
ifnothasattr(self,'tokenizer'):
140+
returnNone
141+
returnself.tokenizer.stream.charEncoding[0]
142+
132143
defisHTMLIntegrationPoint(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
defrunParserEncodingTest(data,encoding):
3030
p=HTMLParser()
31+
assertp.documentEncodingisNone
3132
p.parse(data,useChardet=False)
3233
encoding=encoding.lower().decode("ascii")
3334

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

3637

3738
defrunPreScanEncodingTest(data,encoding):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp