Fix Secretary._unescape_links implementation failing on >=Py3.
This commit is contained in:
parent
18d2e70ed7
commit
ffe27a7a62
1 changed files with 9 additions and 2 deletions
11
secretary.py
11
secretary.py
|
|
@ -37,16 +37,24 @@ from xml.dom.minidom import parseString
|
||||||
from xml.parsers.expat import ExpatError, ErrorString
|
from xml.parsers.expat import ExpatError, ErrorString
|
||||||
from jinja2 import Environment, Undefined, Markup
|
from jinja2 import Environment, Undefined, Markup
|
||||||
|
|
||||||
|
__PY_MAYOR_VER__ = None
|
||||||
try:
|
try:
|
||||||
|
__PY_MAYOR_VER__ = sys.version_info.major
|
||||||
if sys.version_info.major == 3:
|
if sys.version_info.major == 3:
|
||||||
xrange = range
|
xrange = range
|
||||||
basestring = (str, bytes)
|
basestring = (str, bytes)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# On Python 2.6 sys.version_info is a tuple
|
# On Python 2.6 sys.version_info is a tuple
|
||||||
|
__PY_MAYOR_VER__ = 2
|
||||||
if not isinstance(sys.version_info, tuple):
|
if not isinstance(sys.version_info, tuple):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
if __PY_MAYOR_VER__ == 2:
|
||||||
|
from urllib import unquote
|
||||||
|
else:
|
||||||
|
from urllib.parse import unquote
|
||||||
|
|
||||||
FLOW_REFERENCES = {
|
FLOW_REFERENCES = {
|
||||||
'text:p' : 'text:p',
|
'text:p' : 'text:p',
|
||||||
'paragraph' : 'text:p',
|
'paragraph' : 'text:p',
|
||||||
|
|
@ -433,14 +441,13 @@ class Renderer(object):
|
||||||
def _unescape_links(self, xml_text):
|
def _unescape_links(self, xml_text):
|
||||||
"""Fix Libreoffice auto escaping of xlink:href attribute values.
|
"""Fix Libreoffice auto escaping of xlink:href attribute values.
|
||||||
This unescaping is only done on 'secretary' scheme URLs."""
|
This unescaping is only done on 'secretary' scheme URLs."""
|
||||||
import urllib
|
|
||||||
robj = re.compile(r'(?is)(xlink:href=\")secretary:(.*?)(\")')
|
robj = re.compile(r'(?is)(xlink:href=\")secretary:(.*?)(\")')
|
||||||
|
|
||||||
def replacement(match):
|
def replacement(match):
|
||||||
return Markup(''.join([
|
return Markup(''.join([
|
||||||
match.group(1),
|
match.group(1),
|
||||||
self.variable_pattern.sub(r'\1 SafeValue(\2) \3',
|
self.variable_pattern.sub(r'\1 SafeValue(\2) \3',
|
||||||
urllib.unquote(match.group(2))),
|
unquote(match.group(2))),
|
||||||
match.group(3)
|
match.group(3)
|
||||||
]))
|
]))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue