> Modified:
> trunk/python/src/html5lib/serializer/htmlserializer.py
>
> Log:
> DRY
>
> Modified: trunk/python/src/html5lib/serializer/htmlserializer.py
> ==============================================================================
> --- trunk/python/src/html5lib/serializer/htmlserializer.py (original)
> +++ trunk/python/src/html5lib/serializer/htmlserializer.py Sun Jun 24
> 18:27:15 2007
> @@ -76,12 +76,9 @@
> def __init__(self, **kwargs):
> if kwargs.has_key('quote_char'):
> self.use_best_quote_char = False
> - for attr in ("quote_attr_values", "quote_char",
> "use_best_quote_char",
> - "minimize_boolean_attributes", "use_trailing_solidus",
> - "space_before_trailing_solidus", "omit_optional_tags",
> - "strip_whitespace", "inject_meta_charset", "escape_lt_in_attrs",
> - "escape_rcdata"):
> - setattr(self, attr, kwargs.get(attr, getattr(self, attr)))
> + for name,value in kwargs.items():
> + if name in dir(self.__class__) and not name.startswith('_'):
> + setattr(self, name, value)
> self.errors = []
> self.strict = False
There are implications behind this change:
1) with the original, default values defined at the class-level were
copied within each instance's __dict__ (meaning that if you change
HTMLSerializer.quote_attr_values you're not touching existing
instances)
2) with the new version, you can replace the serialize, render and
serializeError passing such named arguments to the constructor:
HTMLSerializer(serialize=True).
In a work: I hugely prefers r817 to r818.
If you don't want to "repeat yourself", I'd have no problem moving all
the default values into a 'defaults' dictionary and then using
"self.options = defaults.copy(); self.options.update(kwargs)" bu it
makes the code harder to read (you'd have to replace e.g.
self.quote_attr_values with self.options['quote_attr_values'])
--
Thomas Broyer
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"html5lib-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/html5lib-discuss?hl=en-GB
-~----------~----~----~----~------~----~------~--~---