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

Commitaf19281

Browse files
jdufresnejgraham
authored andcommitted
Use modern Python syntax set literals and dict comprehension (#415)
Available since Python 2.7. Instances discovered using pyupgrade.
1 parent77879b0 commitaf19281

File tree

7 files changed

+24
-26
lines changed

7 files changed

+24
-26
lines changed

‎html5lib/_inputstream.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
else:
3535
invalid_unicode_re=re.compile(invalid_unicode_no_surrogate)
3636

37-
non_bmp_invalid_codepoints=set([0x1FFFE,0x1FFFF,0x2FFFE,0x2FFFF,0x3FFFE,
38-
0x3FFFF,0x4FFFE,0x4FFFF,0x5FFFE,0x5FFFF,
39-
0x6FFFE,0x6FFFF,0x7FFFE,0x7FFFF,0x8FFFE,
40-
0x8FFFF,0x9FFFE,0x9FFFF,0xAFFFE,0xAFFFF,
41-
0xBFFFE,0xBFFFF,0xCFFFE,0xCFFFF,0xDFFFE,
42-
0xDFFFF,0xEFFFE,0xEFFFF,0xFFFFE,0xFFFFF,
43-
0x10FFFE,0x10FFFF])
37+
non_bmp_invalid_codepoints={0x1FFFE,0x1FFFF,0x2FFFE,0x2FFFF,0x3FFFE,
38+
0x3FFFF,0x4FFFE,0x4FFFF,0x5FFFE,0x5FFFF,
39+
0x6FFFE,0x6FFFF,0x7FFFE,0x7FFFF,0x8FFFE,
40+
0x8FFFF,0x9FFFE,0x9FFFF,0xAFFFE,0xAFFFF,
41+
0xBFFFE,0xBFFFF,0xCFFFE,0xCFFFF,0xDFFFE,
42+
0xDFFFF,0xEFFFE,0xEFFFF,0xFFFFE,0xFFFFF,
43+
0x10FFFE,0x10FFFF}
4444

4545
ascii_punctuation_re=re.compile("[\u0009-\u000D\u0020-\u002F\u003A-\u0040\u005C\u005B-\u0060\u007B-\u007E]")
4646

‎html5lib/constants.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@
519519
"xmlns:xlink": ("xmlns","xlink",namespaces["xmlns"])
520520
}
521521

522-
unadjustForeignAttributes=dict([((ns,local),qname)forqname, (prefix,local,ns)in
523-
adjustForeignAttributes.items()])
522+
unadjustForeignAttributes={(ns,local):qnameforqname, (prefix,local,ns)in
523+
adjustForeignAttributes.items()}
524524

525525
spaceCharacters=frozenset([
526526
"\t",
@@ -544,8 +544,7 @@
544544
digits=frozenset(string.digits)
545545
hexDigits=frozenset(string.hexdigits)
546546

547-
asciiUpper2Lower=dict([(ord(c),ord(c.lower()))
548-
forcinstring.ascii_uppercase])
547+
asciiUpper2Lower= {ord(c):ord(c.lower())forcinstring.ascii_uppercase}
549548

550549
# Heading elements need to be ordered
551550
headingElements= (
@@ -2934,7 +2933,7 @@
29342933
tokenTypes["EmptyTag"]])
29352934

29362935

2937-
prefixes=dict([(v,k)fork,vinnamespaces.items()])
2936+
prefixes={v:kfork,vinnamespaces.items()}
29382937
prefixes["http://www.w3.org/1998/Math/MathML"]="math"
29392938

29402939

‎html5lib/html5parser.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def __init__(self, tree=None, strict=False, namespaceHTMLElements=True, debug=Fa
119119
self.tree=tree(namespaceHTMLElements)
120120
self.errors= []
121121

122-
self.phases=dict([(name,cls(self,self.tree))forname,clsin
123-
getPhases(debug).items()])
122+
self.phases={name:cls(self,self.tree)forname,clsin
123+
getPhases(debug).items()}
124124

125125
def_parse(self,stream,innerHTML=False,container="div",scripting=False,**kwargs):
126126

@@ -413,8 +413,7 @@ def parseRCDataRawtext(self, token, contentType):
413413
defgetPhases(debug):
414414
deflog(function):
415415
"""Logger that records which phase processes each token"""
416-
type_names=dict((value,key)forkey,valuein
417-
tokenTypes.items())
416+
type_names= {value:keyforkey,valueintokenTypes.items()}
418417

419418
defwrapped(self,*args,**kwargs):
420419
iffunction.__name__.startswith("process")andlen(args)>0:
@@ -2478,7 +2477,7 @@ def processStartTag(self, token):
24782477
currentNode=self.tree.openElements[-1]
24792478
if (token["name"]inself.breakoutElementsor
24802479
(token["name"]=="font"and
2481-
set(token["data"].keys())&set(["color","face","size"]))):
2480+
set(token["data"].keys())&{"color","face","size"})):
24822481
self.parser.parseError("unexpected-html-element-in-foreign-content",
24832482
{"name":token["name"]})
24842483
while (self.tree.openElements[-1].namespace!=

‎html5lib/tests/test_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _convertAttrib(self, attribs):
8080

8181

8282
defserialize_html(input,options):
83-
options=dict([(str(k),v)fork,vinoptions.items()])
83+
options={str(k):vfork,vinoptions.items()}
8484
encoding=options.get("encoding",None)
8585
if"encoding"inoptions:
8686
deloptions["encoding"]

‎html5lib/tests/tokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def parse(self, stream, encoding=None, innerHTML=False):
2828
tokenizer.currentToken= {"type":"startTag",
2929
"name":self._lastStartTag}
3030

31-
types=dict((v,k)fork,vinconstants.tokenTypes.items())
31+
types={v:kfork,vinconstants.tokenTypes.items()}
3232
fortokenintokenizer:
3333
getattr(self,'process%s'%types[token["type"]])(token)
3434

‎html5lib/treebuilders/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
listElementsMap= {
1212
None: (frozenset(scopingElements),False),
13-
"button": (frozenset(scopingElements|set([(namespaces["html"],"button")])),False),
14-
"list": (frozenset(scopingElements|set([(namespaces["html"],"ol"),
15-
(namespaces["html"],"ul")])),False),
13+
"button": (frozenset(scopingElements|{(namespaces["html"],"button")}),False),
14+
"list": (frozenset(scopingElements|{(namespaces["html"],"ol"),
15+
(namespaces["html"],"ul")}),False),
1616
"table": (frozenset([(namespaces["html"],"html"),
1717
(namespaces["html"],"table")]),False),
1818
"select": (frozenset([(namespaces["html"],"optgroup"),

‎utils/entities.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ def parse(path="html5ents.xml"):
88

99

1010
defentity_table(tree):
11-
returndict((entity_name("".join(tr[0].xpath(".//text()"))),
12-
entity_characters(tr[1].text))
13-
fortrintree.xpath("//h:tbody/h:tr",
14-
namespaces={"h":"http://www.w3.org/1999/xhtml"}))
11+
return{entity_name("".join(tr[0].xpath(".//text()"))):
12+
entity_characters(tr[1].text)
13+
fortrintree.xpath("//h:tbody/h:tr",
14+
namespaces={"h":"http://www.w3.org/1999/xhtml"})}
1515

1616

1717
defentity_name(inp):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp