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

Commitcc03260

Browse files
author
Mark Pilgrim
committed
refactor individual attribute test methods slightly
--HG--extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40987
1 parent9e7dc96 commitcc03260

File tree

1 file changed

+89
-91
lines changed

1 file changed

+89
-91
lines changed

‎src/html5lib/filters/validator.py

Lines changed: 89 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -335,97 +335,6 @@ def checkStartTagUnknownAttributes(self, token):
335335
"datavars": {"tagName":name,
336336
"attributeName":attrName}}
337337

338-
##########################################################################
339-
# Attribute validation
340-
##########################################################################
341-
342-
defcheckAttributeValues(self,token):
343-
tagName=token.get("name","")
344-
fakeToken= {"tagName":tagName.capitalize()}
345-
forattrName,attrValueintoken.get("data", []):
346-
attrName=attrName.lower()
347-
fakeToken["attributeName"]=attrName.capitalize()
348-
method=getattr(self,"validateAttributeValue%(tagName)s%(attributeName)s"%fakeToken,None)
349-
ifmethod:
350-
fortinmethod(token,tagName,attrName,attrValue)or []:yieldt
351-
else:
352-
method=getattr(self,"validateAttributeValue%(attributeName)s"%fakeToken,None)
353-
ifmethod:
354-
fortinmethod(token,tagName,attrName,attrValue)or []:yieldt
355-
356-
defvalidateAttributeValueClass(self,token,tagName,attrName,attrValue):
357-
fortinself.checkTokenList(tagName,attrName,attrValue)or []:
358-
yieldt
359-
yield {"type":"ParseError",
360-
"data":"invalid-attribute-value",
361-
"datavars": {"tagName":tagName,
362-
"attributeName":attrName}}
363-
364-
defvalidateAttributeValueContenteditable(self,token,tagName,attrName,attrValue):
365-
fortinself.checkEnumeratedValue(token,tagName,attrName,attrValue,frozenset(('true','false','')))or []:yieldt
366-
367-
defvalidateAttributeValueDir(self,token,tagName,attrName,attrValue):
368-
fortinself.checkEnumeratedValue(token,tagName,attrName,attrValue,frozenset(('ltr','rtl')))or []:yieldt
369-
370-
defvalidateAttributeValueDraggable(self,token,tagName,attrName,attrValue):
371-
fortinself.checkEnumeratedValue(token,tagName,attrName,attrValue,frozenset(('true','false')))or []:yieldt
372-
373-
defvalidateAttributeValueIrrelevant(self,token,tagName,attrName,attrValue):
374-
fortinself.checkBooleanValue(token,tagName,attrName,attrValue)or []:yieldt
375-
376-
defvalidateAttributeValueLang(self,token,tagName,attrName,attrValue):
377-
ifnotattrValue:return# blank is OK
378-
ifnotiso639codes.isValidLangCode(attrValue):
379-
yield {"type":"ParseError",
380-
"data":"invalid-lang-code",
381-
"datavars": {"tagName":tagName,
382-
"attributeName":attrName,
383-
"attributeValue":attrValue}}
384-
385-
defvalidateAttributeValueContextmenu(self,token,tagName,attrName,attrValue):
386-
fortinself.checkIDValue(token,tagName,attrName,attrValue)or []:yieldt
387-
self.thingsThatPointToAnID.append(token)
388-
389-
defvalidateAttributeValueId(self,token,tagName,attrName,attrValue):
390-
# This method has side effects. It adds 'token' to the list of
391-
# things that define an ID (self.thingsThatDefineAnID) so that we can
392-
# later check 1) whether an ID is duplicated, and 2) whether all the
393-
# things that point to something else by ID (like <label for> or
394-
# <span contextmenu>) point to an ID that actually exists somewhere.
395-
fortinself.checkIDValue(token,tagName,attrName,attrValue)or []:yieldt
396-
ifnotattrValue:return
397-
ifattrValueinself.IDsWeHaveKnownAndLoved:
398-
yield {"type":"ParseError",
399-
"data":"duplicate-id",
400-
"datavars": {"tagName":tagName}}
401-
self.IDsWeHaveKnownAndLoved.append(attrValue)
402-
self.thingsThatDefineAnID.append(token)
403-
404-
defvalidateAttributeValueTabindex(self,token,tagName,attrName,attrValue):
405-
fortinself.checkIntegerValue(token,tagName,attrName,attrValue)or []:yieldt
406-
407-
defvalidateAttributeValueRef(self,token,tagName,attrName,attrValue):
408-
# XXX
409-
pass
410-
411-
defvalidateAttributeValueTemplate(self,token,tagName,attrName,attrValue):
412-
# XXX
413-
pass
414-
415-
defvalidateAttributeValueHtmlXmlns(self,token,tagName,attrName,attrValue):
416-
ifattrValue!="http://www.w3.org/1999/xhtml":
417-
yield {"type":"ParseError",
418-
"data":"invalid-root-namespace",
419-
"datavars": {"tagName":tagName,
420-
"attributeName":attrName}}
421-
422-
defvalidateAttributeValueBaseHref(self,token,tagName,attrName,attrValue):
423-
# XXX
424-
pass
425-
426-
defvalidateAttributeValueBaseTarget(self,token,tagName,attrName,attrValue):
427-
fortinself.checkBrowsingContext(token,tagName,attrName,attrValue)or []:yieldt
428-
429338
##########################################################################
430339
# Attribute validation helpers
431340
##########################################################################
@@ -552,6 +461,95 @@ def checkBrowsingContext(self, token, tagName, attrName, attrValue):
552461
"datavars": {"tagName":tagName,
553462
"attributeName":attrName}}
554463

464+
##########################################################################
465+
# Attribute validation
466+
##########################################################################
467+
468+
defcheckAttributeValues(self,token):
469+
tagName=token.get("name","")
470+
fakeToken= {"tagName":tagName.capitalize()}
471+
forattrName,attrValueintoken.get("data", []):
472+
attrName=attrName.lower()
473+
fakeToken["attributeName"]=attrName.capitalize()
474+
method=getattr(self,"validateAttributeValue%(tagName)s%(attributeName)s"%fakeToken,None)
475+
ifmethod:
476+
fortinmethod(token,tagName,attrName,attrValue)or []:yieldt
477+
else:
478+
method=getattr(self,"validateAttributeValue%(attributeName)s"%fakeToken,None)
479+
ifmethod:
480+
fortinmethod(token,tagName,attrName,attrValue)or []:yieldt
481+
482+
defvalidateAttributeValueClass(self,token,tagName,attrName,attrValue):
483+
fortinself.checkTokenList(tagName,attrName,attrValue)or []:
484+
yieldt
485+
yield {"type":"ParseError",
486+
"data":"invalid-attribute-value",
487+
"datavars": {"tagName":tagName,
488+
"attributeName":attrName}}
489+
490+
defvalidateAttributeValueContenteditable(self,token,tagName,attrName,attrValue):
491+
fortinself.checkEnumeratedValue(token,tagName,attrName,attrValue,frozenset(('true','false','')))or []:yieldt
492+
493+
defvalidateAttributeValueDir(self,token,tagName,attrName,attrValue):
494+
fortinself.checkEnumeratedValue(token,tagName,attrName,attrValue,frozenset(('ltr','rtl')))or []:yieldt
495+
496+
defvalidateAttributeValueDraggable(self,token,tagName,attrName,attrValue):
497+
fortinself.checkEnumeratedValue(token,tagName,attrName,attrValue,frozenset(('true','false')))or []:yieldt
498+
499+
defvalidateAttributeValueIrrelevant(self,token,tagName,attrName,attrValue):
500+
fortinself.checkBooleanValue(token,tagName,attrName,attrValue)or []:yieldt
501+
502+
defvalidateAttributeValueLang(self,token,tagName,attrName,attrValue):
503+
ifnotattrValue:return# blank is OK
504+
ifnotiso639codes.isValidLangCode(attrValue):
505+
yield {"type":"ParseError",
506+
"data":"invalid-lang-code",
507+
"datavars": {"tagName":tagName,
508+
"attributeName":attrName,
509+
"attributeValue":attrValue}}
510+
511+
defvalidateAttributeValueContextmenu(self,token,tagName,attrName,attrValue):
512+
fortinself.checkIDValue(token,tagName,attrName,attrValue)or []:yieldt
513+
self.thingsThatPointToAnID.append(token)
514+
515+
defvalidateAttributeValueId(self,token,tagName,attrName,attrValue):
516+
# This method has side effects. It adds 'token' to the list of
517+
# things that define an ID (self.thingsThatDefineAnID) so that we can
518+
# later check 1) whether an ID is duplicated, and 2) whether all the
519+
# things that point to something else by ID (like <label for> or
520+
# <span contextmenu>) point to an ID that actually exists somewhere.
521+
fortinself.checkIDValue(token,tagName,attrName,attrValue)or []:yieldt
522+
ifnotattrValue:return
523+
ifattrValueinself.IDsWeHaveKnownAndLoved:
524+
yield {"type":"ParseError",
525+
"data":"duplicate-id",
526+
"datavars": {"tagName":tagName}}
527+
self.IDsWeHaveKnownAndLoved.append(attrValue)
528+
self.thingsThatDefineAnID.append(token)
529+
530+
validateAttributeValueTabindex=checkIntegerValue
531+
532+
defvalidateAttributeValueRef(self,token,tagName,attrName,attrValue):
533+
# XXX
534+
pass
535+
536+
defvalidateAttributeValueTemplate(self,token,tagName,attrName,attrValue):
537+
# XXX
538+
pass
539+
540+
defvalidateAttributeValueHtmlXmlns(self,token,tagName,attrName,attrValue):
541+
ifattrValue!="http://www.w3.org/1999/xhtml":
542+
yield {"type":"ParseError",
543+
"data":"invalid-root-namespace",
544+
"datavars": {"tagName":tagName,
545+
"attributeName":attrName}}
546+
547+
defvalidateAttributeValueBaseHref(self,token,tagName,attrName,attrValue):
548+
# XXX
549+
pass
550+
551+
validateAttributeValueBaseTarget=checkBrowsingContext
552+
555553
##########################################################################
556554
# Whole document validation (IDs, etc.)
557555
##########################################################################

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp