@@ -50,8 +50,10 @@ def __init__(self, stream, encoding=None, parseMeta=True):
5050 "attributeValueUnQuoted" :self .attributeValueUnQuotedState ,
5151 "bogusComment" :self .bogusCommentState ,
5252 "markupDeclarationOpen" :self .markupDeclarationOpenState ,
53+ "commentStart" :self .commentStartState ,
54+ "commentStartDash" :self .commentStartDashState ,
5355 "comment" :self .commentState ,
54- "commentDash " :self .commentDashState ,
56+ "commentEndDash " :self .commentEndDashState ,
5557 "commentEnd" :self .commentEndState ,
5658 "doctype" :self .doctypeState ,
5759 "beforeDoctypeName" :self .beforeDoctypeNameState ,
@@ -616,7 +618,7 @@ def markupDeclarationOpenState(self):
616618 charStack = [self .stream .char (), self .stream .char ()]
617619 if charStack == [u"-" , u"-" ]:
618620 self .currentToken = {"type" : "Comment" , "data" : "" }
619- self .state = self .states ["comment " ]
621+ self .state = self .states ["commentStart " ]
620622 else :
621623 for x in xrange (5 ):
622624 charStack .append (self .stream .char ())
@@ -633,10 +635,49 @@ def markupDeclarationOpenState(self):
633635 self .state = self .states ["bogusComment" ]
634636 return True
635637
638+ def commentStartState (self ):
639+ data = self .stream .char ()
640+ if data == "-" :
641+ self .state = self .states ["commentStartDash" ]
642+ elif data == ">" :
643+ self .tokenQueue .append ({"type" : "ParseError" , "data" :
644+ _ ("Incorrect comment." )})
645+ self .tokenQueue .append (self .currentToken )
646+ self .state = self .states ["data" ]
647+ elif data == EOF :
648+ self .tokenQueue .append ({"type" : "ParseError" , "data" :
649+ _ ("Unexpected end of file in comment." )})
650+ self .tokenQueue .append (self .currentToken )
651+ self .state = self .states ["data" ]
652+ else :
653+ self .currentToken ["data" ] += data + self .stream .charsUntil (u"-" )
654+ self .state = self .states ["comment" ]
655+ return True
656+
657+ def commentStartDashState (self ):
658+ data = self .stream .char ()
659+ if data == "-" :
660+ self .state = self .states ["commentEnd" ]
661+ elif data == ">" :
662+ self .tokenQueue .append ({"type" : "ParseError" , "data" :
663+ _ ("Incorrect comment." )})
664+ self .tokenQueue .append (self .currentToken )
665+ self .state = self .states ["data" ]
666+ elif data == EOF :
667+ self .tokenQueue .append ({"type" : "ParseError" , "data" :
668+ _ ("Unexpected end of file in comment." )})
669+ self .tokenQueue .append (self .currentToken )
670+ self .state = self .states ["data" ]
671+ else :
672+ self .currentToken ["data" ] += data + self .stream .charsUntil (u"-" )
673+ self .state = self .states ["comment" ]
674+ return True
675+
676+
636677 def commentState (self ):
637678 data = self .stream .char ()
638679 if data == u"-" :
639- self .state = self .states ["commentDash " ]
680+ self .state = self .states ["commentEndDash " ]
640681 elif data == EOF :
641682 self .tokenQueue .append ({"type" : "ParseError" , "data" :
642683 _ ("Unexpected end of file in comment." )})
@@ -646,7 +687,7 @@ def commentState(self):
646687 self .currentToken ["data" ] += data + self .stream .charsUntil (u"-" )
647688 return True
648689
649- def commentDashState (self ):
690+ def commentEndDashState (self ):
650691 data = self .stream .char ()
651692 if data == u"-" :
652693 self .state = self .states ["commentEnd" ]
0 commit comments