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

Use modern Python syntax set literals and dict comprehension#415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jgraham merged 1 commit intohtml5lib:masterfromjdufresne:pyupgrade
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletionshtml5lib/_inputstream.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,13 +34,13 @@
else:
invalid_unicode_re = re.compile(invalid_unicode_no_surrogate)

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

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

Expand Down
9 changes: 4 additions & 5 deletionshtml5lib/constants.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -519,8 +519,8 @@
"xmlns:xlink": ("xmlns", "xlink", namespaces["xmlns"])
}

unadjustForeignAttributes =dict([((ns, local), qname) for qname, (prefix, local, ns) in
adjustForeignAttributes.items()])
unadjustForeignAttributes ={(ns, local): qname for qname, (prefix, local, ns) in
adjustForeignAttributes.items()}

spaceCharacters = frozenset([
"\t",
Expand All@@ -544,8 +544,7 @@
digits = frozenset(string.digits)
hexDigits = frozenset(string.hexdigits)

asciiUpper2Lower = dict([(ord(c), ord(c.lower()))
for c in string.ascii_uppercase])
asciiUpper2Lower = {ord(c): ord(c.lower()) for c in string.ascii_uppercase}

# Heading elements need to be ordered
headingElements = (
Expand DownExpand Up@@ -2934,7 +2933,7 @@
tokenTypes["EmptyTag"]])


prefixes =dict([(v, k) for k, v in namespaces.items()])
prefixes ={v: k for k, v in namespaces.items()}
prefixes["http://www.w3.org/1998/Math/MathML"] = "math"


Expand Down
9 changes: 4 additions & 5 deletionshtml5lib/html5parser.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,8 +119,8 @@ def __init__(self, tree=None, strict=False, namespaceHTMLElements=True, debug=Fa
self.tree = tree(namespaceHTMLElements)
self.errors = []

self.phases =dict([(name, cls(self, self.tree)) for name, cls in
getPhases(debug).items()])
self.phases ={name: cls(self, self.tree) for name, cls in
getPhases(debug).items()}

def _parse(self, stream, innerHTML=False, container="div", scripting=False, **kwargs):

Expand DownExpand Up@@ -413,8 +413,7 @@ def parseRCDataRawtext(self, token, contentType):
def getPhases(debug):
def log(function):
"""Logger that records which phase processes each token"""
type_names = dict((value, key) for key, value in
tokenTypes.items())
type_names = {value: key for key, value in tokenTypes.items()}

def wrapped(self, *args, **kwargs):
if function.__name__.startswith("process") and len(args) > 0:
Expand DownExpand Up@@ -2478,7 +2477,7 @@ def processStartTag(self, token):
currentNode = self.tree.openElements[-1]
if (token["name"] in self.breakoutElements or
(token["name"] == "font" and
set(token["data"].keys()) &set(["color", "face", "size"]))):
set(token["data"].keys()) &{"color", "face", "size"})):
self.parser.parseError("unexpected-html-element-in-foreign-content",
{"name": token["name"]})
while (self.tree.openElements[-1].namespace !=
Expand Down
2 changes: 1 addition & 1 deletionhtml5lib/tests/test_serializer.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,7 @@ def _convertAttrib(self, attribs):


def serialize_html(input, options):
options =dict([(str(k), v) for k, v in options.items()])
options ={str(k): v for k, v in options.items()}
encoding = options.get("encoding", None)
if "encoding" in options:
del options["encoding"]
Expand Down
2 changes: 1 addition & 1 deletionhtml5lib/tests/tokenizer.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@ def parse(self, stream, encoding=None, innerHTML=False):
tokenizer.currentToken = {"type": "startTag",
"name": self._lastStartTag}

types =dict((v, k) for k, v in constants.tokenTypes.items())
types ={v: k for k, v in constants.tokenTypes.items()}
for token in tokenizer:
getattr(self, 'process%s' % types[token["type"]])(token)

Expand Down
6 changes: 3 additions & 3 deletionshtml5lib/treebuilders/base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,9 @@

listElementsMap = {
None: (frozenset(scopingElements), False),
"button": (frozenset(scopingElements |set([(namespaces["html"], "button")])), False),
"list": (frozenset(scopingElements |set([(namespaces["html"], "ol"),
(namespaces["html"], "ul")])), False),
"button": (frozenset(scopingElements |{(namespaces["html"], "button")}), False),
"list": (frozenset(scopingElements |{(namespaces["html"], "ol"),
(namespaces["html"], "ul")}), False),
"table": (frozenset([(namespaces["html"], "html"),
(namespaces["html"], "table")]), False),
"select": (frozenset([(namespaces["html"], "optgroup"),
Expand Down
8 changes: 4 additions & 4 deletionsutils/entities.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,10 +8,10 @@ def parse(path="html5ents.xml"):


def entity_table(tree):
returndict((entity_name("".join(tr[0].xpath(".//text()"))),
entity_characters(tr[1].text))
for tr in tree.xpath("//h:tbody/h:tr",
namespaces={"h": "http://www.w3.org/1999/xhtml"}))
return{entity_name("".join(tr[0].xpath(".//text()"))):
entity_characters(tr[1].text)
for tr in tree.xpath("//h:tbody/h:tr",
namespaces={"h": "http://www.w3.org/1999/xhtml"})}


def entity_name(inp):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp