|
1 | 1 | from __future__importabsolute_import,division,unicode_literals
|
2 | 2 | fromsiximporttext_type
|
3 | 3 |
|
4 |
| -try: |
5 |
| -fromfunctoolsimportreduce |
6 |
| -exceptImportError: |
7 |
| -pass |
| 4 | +importre |
8 | 5 |
|
9 | 6 | from ..constantsimportvoidElements,booleanAttributes,spaceCharacters
|
10 | 7 | from ..constantsimportrcdataElements,entities,xmlEntities
|
|
13 | 10 |
|
14 | 11 | spaceCharacters="".join(spaceCharacters)
|
15 | 12 |
|
| 13 | +quoteAttributeSpec=re.compile("["+spaceCharacters+"\"'=<>`]") |
| 14 | + |
16 | 15 | try:
|
17 | 16 | fromcodecsimportregister_error,xmlcharrefreplace_errors
|
18 | 17 | exceptImportError:
|
@@ -240,11 +239,10 @@ def serialize(self, treewalker, encoding=None):
|
240 | 239 | (knotinbooleanAttributes.get(name,tuple())and
|
241 | 240 | knotinbooleanAttributes.get("",tuple())):
|
242 | 241 | yieldself.encodeStrict("=")
|
243 |
| -ifself.quote_attr_valuesornotv: |
| 242 | +ifself.quote_attr_values: |
244 | 243 | quote_attr=True
|
245 | 244 | else:
|
246 |
| -quote_attr=reduce(lambdax,y:xor (yinv), |
247 |
| -spaceCharacters+">\"'=",False) |
| 245 | +quote_attr=len(v)==0orquoteAttributeSpec.search(v) |
248 | 246 | v=v.replace("&","&")
|
249 | 247 | ifself.escape_lt_in_attrs:
|
250 | 248 | v=v.replace("<","<")
|
|