Hello,
I'm developing a plugin that just convert pixel values to em but I'm facing this error (as title) when I run the script on Sigil 0.8.7 on my friends computer. Note that this script work fine with 0.9.10 on my computer. He said, he need the old version because there is some error that the new version skipped when he checked the ePub so he don't want to switch.
Someone can help me how to fix this please ? What can cause the problem in these version ?
Thanks.
Spoiler:
This is the content of plugin.py
Code:
import sys
import re
class Px2Em:
"""
Convert Pixel values to Em.
FIXME : "can't use string pattern on bytes like object" on sigil 0.8.7
"""
def __init__(self):
self._stylesheet = ""
self._new_stylesheet = ""
def _read(self, read_data):
'''
Read the data param and init the object value.
'''
self._stylesheet = read_data
def _replace(self):
'''
Replace px values with em values.
1px = 1/16 em
'''
self._rgx = re.compile(r'(\d+(\.\d+)?)px')
self._resall = self._rgx.findall(self._stylesheet)
if self._resall is not None:
for self._r in self._resall:
self._stylesheet = re.sub(
str(self._r[0])+'px', str(float(self._r[0])/16)+'em', self._stylesheet)
self._new_stylesheet = self._stylesheet
def _update(self, bk, id_file):
'''
Update the existing stylesheet with the new content.
'''
try:
bk.writefile(id_file, self._new_stylesheet)
except:
print(str(sys.exc_info()[0]) +
" : " + str(sys.exc_info()[1]))
def run(bk):
try:
px2em = Px2Em()
for id_file, href in bk.css_iter():
data = bk.readfile(id_file)
px2em._read(data)
px2em._replace()
px2em._update(bk, id_file)
except:
print(str(sys.exc_info()[0]) + " : " + str(sys.exc_info()[1]))
return 0
def main():
print("[-] No main")
return -1
if __name__ == "__main__":
sys.exit(main())