Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 02-21-2019, 12:55 AM   #1
hantsaniala
Member
hantsaniala began at the beginning.
 
hantsaniala's Avatar
 
Posts: 16
Karma: 10
Join Date: Dec 2015
Device: sigil
"Can't use string pattern on bytes like object" on Sigil 0.8.7

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())
hantsaniala is offline   Reply With Quote
Old 02-21-2019, 01:25 AM   #2
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
You'll have to use decode():

Spoiler:
Code:
def run(bk):
    try:
        px2em = Px2Em()
        for id_file, href in bk.css_iter():
            if bk.launcher_version() <= 20151001: # Sigil-0.8.901 
                data = bk.readfile(id_file).decode('utf-8')
            else:
                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
Doitsu is offline   Reply With Quote
Advert
Old 02-21-2019, 01:35 AM   #3
hantsaniala
Member
hantsaniala began at the beginning.
 
hantsaniala's Avatar
 
Posts: 16
Karma: 10
Join Date: Dec 2015
Device: sigil
Quote:
Originally Posted by Doitsu View Post
You'll have to use decode():

Spoiler:
Code:
def run(bk):
    try:
        px2em = Px2Em()
        for id_file, href in bk.css_iter():
            if bk.launcher_version() <= 20151001: # Sigil-0.8.901 
                data = bk.readfile(id_file).decode('utf-8')
            else:
                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
Thanks bro, I've used decode before but not at this line. I haven't think about it. It works like a charm.
hantsaniala is offline   Reply With Quote
Old 02-21-2019, 05:28 AM   #4
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,550
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
For the record: I can't imagine what error your friend thinks 0.8.7 still checks for that newer versions skip. Flightcrew was moved from internal code to a plugin, but there's been no checks dropped from Flightcrew in that time.

He probably just mistakenly thinks that the Well-Formed Check in newer versions is the same as Flightcrew (F7) in the older version. *shrug*
DiapDealer is offline   Reply With Quote
Old 02-21-2019, 09:32 AM   #5
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
Yes, please teach your friend how to use FlightCrew properly in its plugin form and away from that archaic version of Sigil that has so many serious crashing bugs that have since been fixed in Sigil.
KevinH is online now   Reply With Quote
Advert
Old 02-22-2019, 09:36 AM   #6
hantsaniala
Member
hantsaniala began at the beginning.
 
hantsaniala's Avatar
 
Posts: 16
Karma: 10
Join Date: Dec 2015
Device: sigil
I'll take care of that. Thanks for the suggestion. But, even me I don't know about the FlightCrew plugin until now. But I'll try it and suggest it to my friend, don't worry. Many thanks !
hantsaniala is offline   Reply With Quote
Reply

Tags
plugin, sigil 0.8.7


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Workaround : Series, ignore multi-language "articles" for sort string Mdemaillard Library Management 0 01-03-2013 04:55 PM
0.7.56 Crash on startup: "'QWidget' Object has no attribute 'fillier'" MrAndreBB Calibre 0 04-17-2011 01:44 PM
Always same problem Calibre - MacBook Air 11 "Not enough arguments for format string" Beachu Calibre 7 02-19-2011 01:15 PM
Error help: "Invalid input object: NoneType" MichaelGray ePub 1 02-14-2010 09:16 AM
"The Schumann Frequency" : free book with a small string attached for Australians zelda_pinwheel Deals and Resources (No Self-Promotion or Affiliate Links) 5 10-07-2009 04:21 PM


All times are GMT -4. The time now is 11:17 AM.


MobileRead.com is a privately owned, operated and funded community.