@@ -136,13 +136,13 @@ def utf8decode(value):
136136 return value .decode ("utf-8" )
137137
138138def htmlescape (value ):
139- _ = (('&' , '&' ), ('<' , '<' ), ('>' , '>' ), ('"' , '"' ), ("'" , ''' ), (' ' , ' ' ))
140- return reduce (lambda x , y : x .replace (y [0 ], y [1 ]), _ , value )
139+ codes = (('&' , '&' ), ('<' , '<' ), ('>' , '>' ), ('"' , '"' ), ("'" , ''' ), (' ' , ' ' ))
140+ return reduce (lambda x , y : x .replace (y [0 ], y [1 ]), codes , value )
141141
142142def htmlunescape (value ):
143143 retVal = value
144144 if value and isinstance (value , basestring ):
145- _ = (('& ;' , '& ' ), ('< ;' , '< ' ), ('> ;' , '> ' ), ('" ;' , '" ' ), ('  ;' , ' ' ))
146- retVal = reduce (lambda x , y : x .replace (y [0 ], y [1 ]), _ , retVal )
147- retVal = re .sub ('&#(\d+);' , lambda x : unichr ( int (x .group (1 ))), retVal )
145+ codes = (('< ;' , '< ' ), ('> ;' , '> ' ), ('" ;' , '" ' ), ('  ;' , ' ' ), ('& ;' , '& ' ))
146+ retVal = reduce (lambda x , y : x .replace (y [0 ], y [1 ]), codes , retVal )
147+ retVal = re .sub ('&#(\d+);' , lambda x : getUnicode ( chr (x .group (1 ))), retVal )
148148 return retVal
0 commit comments