def attribute_rule(allowed_attrs):
 def fn(tag):
  for (attr, val) in list(tag.attrs.items()):
   rule = allowed_attrs.get(attr)
   if rule:
    if callable(rule):
     new_val = rule(val)
     if (new_val is None):
      del tag[attr]
     else:
      tag[attr] = new_val
    else:
     pass
   else:
    del tag[attr]
 return fn

def attribute_rule ( allowed_attrs ) : def fn ( tag ) : for ( attr , val ) in list ( tag . attrs . items ( ) ) : rule = allowed_attrs . get ( attr ) if rule : if callable ( rule ) : new_val = rule ( val ) if ( new_val is None ) : del tag [ attr ] else : tag [ attr ] = new_val else : pass else : del tag [ attr ] return fn
generator for functions that can be used as entries in whitelister .