Skip to content

Commit f28b9e6

Browse files
committed
---
yaml --- r: 182775 b: refs/heads/beta c: 109a6bc h: refs/heads/master i: 182773: 8b8647e 182771: 07fbb42 182767: 7fd1181 v: v3
1 parent 6a86fbb commit f28b9e6

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: bbb2871bfba427654d70592f0f4fa0d1806a3fa0
34+
refs/heads/beta: 109a6bc86c110751118307b969616319d8ed795b
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: eb836bf767aa1d8d4cba488a9091cde3c0ab4b2f

branches/beta/src/etc/htmldocck.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,40 +118,54 @@
118118
VOID_ELEMENTS = set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
119119
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'])
120120

121-
# simplified HTML parser.
122-
# this is possible because we are dealing with very regular HTML from rustdoc;
123-
# we only have to deal with i) void elements and ii) empty attributes.
121+
124122
class CustomHTMLParser(HTMLParser):
123+
"""simplified HTML parser.
124+
125+
this is possible because we are dealing with very regular HTML from
126+
rustdoc; we only have to deal with i) void elements and ii) empty
127+
attributes."""
125128
def __init__(self, target=None):
126129
HTMLParser.__init__(self)
127130
self.__builder = target or ET.TreeBuilder()
131+
128132
def handle_starttag(self, tag, attrs):
129133
attrs = dict((k, v or '') for k, v in attrs)
130134
self.__builder.start(tag, attrs)
131-
if tag in VOID_ELEMENTS: self.__builder.end(tag)
135+
if tag in VOID_ELEMENTS:
136+
self.__builder.end(tag)
137+
132138
def handle_endtag(self, tag):
133139
self.__builder.end(tag)
140+
134141
def handle_startendtag(self, tag, attrs):
135142
attrs = dict((k, v or '') for k, v in attrs)
136143
self.__builder.start(tag, attrs)
137144
self.__builder.end(tag)
145+
138146
def handle_data(self, data):
139147
self.__builder.data(data)
148+
140149
def handle_entityref(self, name):
141150
self.__builder.data(entitydefs[name])
151+
142152
def handle_charref(self, name):
143153
code = int(name[1:], 16) if name.startswith(('x', 'X')) else int(name, 10)
144154
self.__builder.data(unichr(code).encode('utf-8'))
155+
145156
def close(self):
146157
HTMLParser.close(self)
147158
return self.__builder.close()
148159

149160
Command = namedtuple('Command', 'negated cmd args lineno')
150161

151-
# returns a generator out of the file object, which
152-
# - removes `\\` then `\n` then a shared prefix with the previous line then optional whitespace;
153-
# - keeps a line number (starting from 0) of the first line being concatenated.
162+
154163
def concat_multi_lines(f):
164+
"""returns a generator out of the file object, which
165+
- removes `\\` then `\n` then a shared prefix with the previous line then
166+
optional whitespace;
167+
- keeps a line number (starting from 0) of the first line being
168+
concatenated."""
155169
lastline = None # set to the last line when the last line has a backslash
156170
firstlineno = None
157171
catenated = ''
@@ -162,7 +176,8 @@ def concat_multi_lines(f):
162176
if lastline is not None:
163177
maxprefix = 0
164178
for i in xrange(min(len(line), len(lastline))):
165-
if line[i] != lastline[i]: break
179+
if line[i] != lastline[i]:
180+
break
166181
maxprefix += 1
167182
line = line[maxprefix:].lstrip()
168183

@@ -184,11 +199,14 @@ def concat_multi_lines(f):
184199
(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
185200
(?P<args>.*)$
186201
''', re.X)
202+
203+
187204
def get_commands(template):
188205
with open(template, 'rUb') as f:
189206
for lineno, line in concat_multi_lines(f):
190207
m = LINE_PATTERN.search(line)
191-
if not m: continue
208+
if not m:
209+
continue
192210

193211
negated = (m.group('negated') == '!')
194212
cmd = m.group('cmd')
@@ -198,17 +216,22 @@ def get_commands(template):
198216
args = shlex.split(args)
199217
yield Command(negated=negated, cmd=cmd, args=args, lineno=lineno+1)
200218

219+
201220
def _flatten(node, acc):
202-
if node.text: acc.append(node.text)
221+
if node.text:
222+
acc.append(node.text)
203223
for e in node:
204224
_flatten(e, acc)
205-
if e.tail: acc.append(e.tail)
225+
if e.tail:
226+
acc.append(e.tail)
227+
206228

207229
def flatten(node):
208230
acc = []
209231
_flatten(node, acc)
210232
return ''.join(acc)
211233

234+
212235
def normalize_xpath(path):
213236
if path.startswith('//'):
214237
return '.' + path # avoid warnings
@@ -218,6 +241,7 @@ def normalize_xpath(path):
218241
raise RuntimeError('Non-absolute XPath is not supported due to \
219242
the implementation issue.')
220243

244+
221245
class CachedFiles(object):
222246
def __init__(self, root):
223247
self.root = root
@@ -267,6 +291,7 @@ def get_tree(self, path):
267291
self.trees[path] = tree
268292
return self.trees[path]
269293

294+
270295
def check_string(data, pat, regexp):
271296
if not pat:
272297
return True # special case a presence testing
@@ -277,6 +302,7 @@ def check_string(data, pat, regexp):
277302
pat = ' '.join(pat.split())
278303
return pat in data
279304

305+
280306
def check_tree_attr(tree, path, attr, pat, regexp):
281307
path = normalize_xpath(path)
282308
ret = False
@@ -287,9 +313,11 @@ def check_tree_attr(tree, path, attr, pat, regexp):
287313
continue
288314
else:
289315
ret = check_string(value, pat, regexp)
290-
if ret: break
316+
if ret:
317+
break
291318
return ret
292319

320+
293321
def check_tree_text(tree, path, pat, regexp):
294322
path = normalize_xpath(path)
295323
ret = False
@@ -300,9 +328,11 @@ def check_tree_text(tree, path, pat, regexp):
300328
continue
301329
else:
302330
ret = check_string(value, pat, regexp)
303-
if ret: break
331+
if ret:
332+
break
304333
return ret
305334

335+
306336
def check(target, commands):
307337
cache = CachedFiles(target)
308338
for c in commands:
@@ -323,7 +353,8 @@ def check(target, commands):
323353
ret = check_tree_attr(cache.get_tree(c.args[0]), pat, attr, c.args[2], regexp)
324354
else: # normalized text
325355
pat = c.args[1]
326-
if pat.endswith('/text()'): pat = pat[:-7]
356+
if pat.endswith('/text()'):
357+
pat = pat[:-7]
327358
ret = check_tree_text(cache.get_tree(c.args[0]), pat, c.args[2], regexp)
328359
else:
329360
raise RuntimeError('Invalid number of @{} arguments \
@@ -348,4 +379,3 @@ def check(target, commands):
348379
raise SystemExit(1)
349380
else:
350381
check(sys.argv[1], get_commands(sys.argv[2]))
351-

0 commit comments

Comments
 (0)