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

Commite5d395c

Browse files
committed
Silence wrong-import-position
1 parenta017b88 commite5d395c

File tree

6 files changed

+60
-58
lines changed

6 files changed

+60
-58
lines changed

‎html5lib/serializer/htmlserializer.py‎

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
importre
55

6+
fromcodecsimportregister_error,xmlcharrefreplace_errors
7+
68
from ..constantsimportvoidElements,booleanAttributes,spaceCharacters
79
from ..constantsimportrcdataElements,entities,xmlEntities
810
from ..importutils
@@ -21,61 +23,54 @@
2123
"\u2008\u2009\u200a\u2028\u2029\u202f\u205f"
2224
"\u3000]")
2325

24-
try:
25-
fromcodecsimportregister_error,xmlcharrefreplace_errors
26-
exceptImportError:
27-
unicode_encode_errors="strict"
28-
else:
29-
unicode_encode_errors="htmlentityreplace"
30-
31-
encode_entity_map= {}
32-
is_ucs4=len("\U0010FFFF")==1
33-
fork,vinlist(entities.items()):
34-
# skip multi-character entities
35-
if ((is_ucs4andlen(v)>1)or
36-
(notis_ucs4andlen(v)>2)):
37-
continue
38-
ifv!="&":
39-
iflen(v)==2:
40-
v=utils.surrogatePairToCodepoint(v)
41-
else:
42-
v=ord(v)
43-
ifvnotinencode_entity_mapork.islower():
44-
# prefer < over < and similarly for &, >, etc.
45-
encode_entity_map[v]=k
46-
47-
defhtmlentityreplace_errors(exc):
48-
ifisinstance(exc, (UnicodeEncodeError,UnicodeTranslateError)):
49-
res= []
50-
codepoints= []
51-
skip=False
52-
fori,cinenumerate(exc.object[exc.start:exc.end]):
53-
ifskip:
54-
skip=False
55-
continue
56-
index=i+exc.start
57-
ifutils.isSurrogatePair(exc.object[index:min([exc.end,index+2])]):
58-
codepoint=utils.surrogatePairToCodepoint(exc.object[index:index+2])
59-
skip=True
60-
else:
61-
codepoint=ord(c)
62-
codepoints.append(codepoint)
63-
forcpincodepoints:
64-
e=encode_entity_map.get(cp)
65-
ife:
66-
res.append("&")
67-
res.append(e)
68-
ifnote.endswith(";"):
69-
res.append(";")
70-
else:
71-
res.append("&#x%s;"% (hex(cp)[2:]))
72-
return ("".join(res),exc.end)
73-
else:
74-
returnxmlcharrefreplace_errors(exc)
7526

76-
register_error(unicode_encode_errors,htmlentityreplace_errors)
27+
encode_entity_map= {}
28+
is_ucs4=len("\U0010FFFF")==1
29+
fork,vinlist(entities.items()):
30+
# skip multi-character entities
31+
if ((is_ucs4andlen(v)>1)or
32+
(notis_ucs4andlen(v)>2)):
33+
continue
34+
ifv!="&":
35+
iflen(v)==2:
36+
v=utils.surrogatePairToCodepoint(v)
37+
else:
38+
v=ord(v)
39+
ifvnotinencode_entity_mapork.islower():
40+
# prefer < over < and similarly for &, >, etc.
41+
encode_entity_map[v]=k
42+
43+
44+
defhtmlentityreplace_errors(exc):
45+
ifisinstance(exc, (UnicodeEncodeError,UnicodeTranslateError)):
46+
res= []
47+
codepoints= []
48+
skip=False
49+
fori,cinenumerate(exc.object[exc.start:exc.end]):
50+
ifskip:
51+
skip=False
52+
continue
53+
index=i+exc.start
54+
ifutils.isSurrogatePair(exc.object[index:min([exc.end,index+2])]):
55+
codepoint=utils.surrogatePairToCodepoint(exc.object[index:index+2])
56+
skip=True
57+
else:
58+
codepoint=ord(c)
59+
codepoints.append(codepoint)
60+
forcpincodepoints:
61+
e=encode_entity_map.get(cp)
62+
ife:
63+
res.append("&")
64+
res.append(e)
65+
ifnote.endswith(";"):
66+
res.append(";")
67+
else:
68+
res.append("&#x%s;"% (hex(cp)[2:]))
69+
return ("".join(res),exc.end)
70+
else:
71+
returnxmlcharrefreplace_errors(exc)
7772

78-
delregister_error
73+
register_error("htmlentityreplace",htmlentityreplace_errors)
7974

8075

8176
classHTMLSerializer(object):
@@ -168,7 +163,7 @@ def __init__(self, **kwargs):
168163
defencode(self,string):
169164
assert(isinstance(string,text_type))
170165
ifself.encoding:
171-
returnstring.encode(self.encoding,unicode_encode_errors)
166+
returnstring.encode(self.encoding,"htmlentityreplace")
172167
else:
173168
returnstring
174169

‎html5lib/tests/support.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__importabsolute_import,division,unicode_literals
22

3+
# pylint:disable=wrong-import-position
4+
35
importos
46
importsys
57
importcodecs
@@ -68,6 +70,8 @@
6870
"walker":treewalkers.getTreeWalker("genshi")
6971
}
7072

73+
# pylint:enable=wrong-import-position
74+
7175

7276
defget_data_files(subdirectory,files='*.dat',search_dir=test_dir):
7377
returnsorted(glob.glob(os.path.join(search_dir,subdirectory,files)))

‎html5lib/tests/test_encoding.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def test_encoding():
5555
yield (runParserEncodingTest,test[b'data'],test[b'encoding'])
5656
yield (runPreScanEncodingTest,test[b'data'],test[b'encoding'])
5757

58+
# pylint:disable=wrong-import-position
5859
try:
5960
try:
6061
importcharade# noqa
@@ -67,3 +68,4 @@ def test_chardet():
6768
withopen(os.path.join(test_dir,"encoding","chardet","test_big5.txt"),"rb")asfp:
6869
encoding=inputstream.HTMLInputStream(fp.read()).charEncoding
6970
assertencoding[0].name=="big5"
71+
# pylint:enable=wrong-import-position

‎html5lib/tests/test_serializer.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
fromhtml5lib.serializerimportHTMLSerializer,serialize
1313
fromhtml5lib.treewalkers._baseimportTreeWalker
1414

15+
# pylint:disable=wrong-import-position
1516
optionals_loaded= []
1617

1718
try:
1819
fromlxmlimportetree
1920
optionals_loaded.append("lxml")
2021
exceptImportError:
2122
pass
23+
# pylint:enable=wrong-import-position
2224

2325
default_namespace=constants.namespaces["html"]
2426

‎html5lib/tokenizer.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from __future__importabsolute_import,division,unicode_literals
22

3-
try:
4-
chr=unichr# noqa
5-
exceptNameError:
6-
pass
3+
fromsiximportunichraschr
74

85
fromcollectionsimportdeque
96

‎html5lib/trie/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
Trie=PyTrie
66

7+
# pylint:disable=wrong-import-position
78
try:
89
from .datrieimportTrieasDATrie
910
exceptImportError:
1011
pass
1112
else:
1213
Trie=DATrie
14+
# pylint:enable=wrong-import-position

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp