@@ -21,9 +21,14 @@ def __iter__(self):
2121 # replace charset with actual encoding
2222 has_http_equiv_content_type = False
2323 content_index = - 1
24- for i ,(name ,value ) in enumerate (token ["data" ]):
25- if name .lower () == 'charset' :
26- token ["data" ][i ] = (u'charset' , self .encoding )
24+ for i ,attr in enumerate (token ["data" ]):
25+ namespace = attr ["namespace" ]
26+ name = attr ["name" ]
27+ value = attr ["value" ]
28+ if namespace != None :
29+ continue
30+ elif name .lower () == 'charset' :
31+ token ["data" ][i ]["value" ] = self .encoding
2732 meta_found = True
2833 break
2934 elif name == 'http-equiv' and value .lower () == 'content-type' :
@@ -32,15 +37,15 @@ def __iter__(self):
3237 content_index = i
3338 else :
3439 if has_http_equiv_content_type and content_index >= 0 :
35- token ["data" ][content_index ] = ( u'content' , u' text/html; charset=%s' % self .encoding )
40+ token ["data" ][content_index ][ "value" ] = u' text/html; charset=%s' % self .encoding
3641 meta_found = True
3742
3843 elif token ["name" ].lower () == "head" and not meta_found :
3944 # insert meta into empty head
4045 yield {"type" : "StartTag" , "name" : "head" ,
4146 "data" : token ["data" ]}
4247 yield {"type" : "EmptyTag" , "name" : "meta" ,
43- "data" : [[ " charset" , self .encoding ] ]}
48+ "data" : [{ "namespace" : None , "name" : " charset" , "value" : self .encoding } ]}
4449 yield {"type" : "EndTag" , "name" : "head" }
4550 meta_found = True
4651 continue
@@ -51,7 +56,7 @@ def __iter__(self):
5156 yield pending .pop (0 )
5257 if not meta_found :
5358 yield {"type" : "EmptyTag" , "name" : "meta" ,
54- "data" : [[ " charset" , self .encoding ] ]}
59+ "data" : [{ "namespace" : None , "name" : " charset" , "value" : self .encoding } ]}
5560 while pending :
5661 yield pending .pop (0 )
5762 meta_found = True
0 commit comments