#NEWLINE# def _parse_tag( self , tag ) : #NEWLINE# #INDENT# '\n        Given a string assumed to be an opening tag or a ending tag, validates it and return\n        a 4-tuple of the form:\n            (valid, tag_name, closing, option)\n        ' #NEWLINE# if ( ( not ( tag . startswith ( self . _TAG_OPENING ) and tag . endswith ( self . _TAG_ENDING ) ) ) or ( '\n' in tag ) or ( '\r' in tag ) or ( tag . count ( self . _TAG_OPENING ) > 1 ) or ( tag . count ( self . _TAG_ENDING ) > 1 ) ) : #NEWLINE# #INDENT# return ( False , tag , False , None ) #NEWLINE# #UNINDENT# tag_name = tag [ len ( self . _TAG_OPENING ) : ( - len ( self . _TAG_ENDING ) ) ] . strip ( ) #NEWLINE# if ( not tag_name ) : #NEWLINE# #INDENT# return ( False , tag , False , None ) #NEWLINE# #UNINDENT# closing = False #NEWLINE# option = None #NEWLINE# if tag_name . startswith ( '/' ) : #NEWLINE# #INDENT# tag_name = tag_name [ 1 : ] #NEWLINE# closing = True #NEWLINE# #UNINDENT# if ( ( '=' in tag_name ) and closing ) : #NEWLINE# #INDENT# return ( False , tag , False , None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( '=' in tag_name ) : #NEWLINE# #INDENT# option_pos = tag_name . find ( '=' ) #NEWLINE# option = tag_name [ ( option_pos + 1 ) : ] #NEWLINE# tag_name = tag_name [ : option_pos ] #NEWLINE# #UNINDENT# #UNINDENT# return ( True , tag_name . strip ( ) . lower ( ) , closing , option )