|
1 | 1 | from __future__ import absolute_import, division, unicode_literals
|
2 | 2 | from six import text_type
|
3 | 3 |
|
4 |
| -try: |
5 |
| - from functools import reduce |
6 |
| -except ImportError: |
7 |
| - pass |
| 4 | +import re |
8 | 5 |
|
9 | 6 | from ..constants import voidElements, booleanAttributes, spaceCharacters
|
10 | 7 | from ..constants import rcdataElements, entities, xmlEntities
|
|
13 | 10 |
|
14 | 11 | spaceCharacters = "".join(spaceCharacters)
|
15 | 12 |
|
| 13 | +quoteAttributeSpec = re.compile("[" + spaceCharacters + "\"'=<>`]") |
| 14 | + |
16 | 15 | try:
|
17 | 16 | from codecs import register_error, xmlcharrefreplace_errors
|
18 | 17 | except ImportError:
|
@@ -240,11 +239,10 @@ def serialize(self, treewalker, encoding=None):
|
240 | 239 | (k not in booleanAttributes.get(name, tuple()) and
|
241 | 240 | k not in booleanAttributes.get("", tuple())):
|
242 | 241 | yield self.encodeStrict("=")
|
243 |
| - if self.quote_attr_values or not v: |
| 242 | + if self.quote_attr_values: |
244 | 243 | quote_attr = True
|
245 | 244 | else:
|
246 |
| - quote_attr = reduce(lambda x, y: x or (y in v), |
247 |
| - spaceCharacters + ">\"'=", False) |
| 245 | + quote_attr = len(v) == 0 or quoteAttributeSpec.search(v) |
248 | 246 | v = v.replace("&", "&")
|
249 | 247 | if self.escape_lt_in_attrs:
|
250 | 248 | v = v.replace("<", "<")
|
|
0 commit comments