wepub

Check-in [e73f6a45c6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Normalize use of [un]quote_plus. Fix chapter numbering error (very first chapter was previously not reachable).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:e73f6a45c65527fe5f29d7c080668acf40f613a23224a8c67204c536a15b3fce
User & Date: vandys 2018-06-12 23:41:46
Context
2018-06-29
00:22
We have a styling file, use it. check-in: e4c67a9fe8 user: vandys tags: master, trunk
2018-06-12
23:41
Normalize use of [un]quote_plus. Fix chapter numbering error (very first chapter was previously not reachable). check-in: e73f6a45c6 user: vandys tags: master, trunk
2018-04-26
00:55
Tidy up display and styling. Fix (again) bug with chapter numbering. check-in: cb7f4d4130 user: vandyswa@gmail.com tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to get.py.

7
8
9
10
11
12
13

14
15
16
17
18
19
20
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
181
182
183
184
185
186
187
188


189
190
191
192
193
194
195
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#	Main UI.  Top part is playlist, bottom is file/dir browser
#  /media/<prefix>/...
#	For each prefix of files, its contents is served by
#	way of its path under here.
import os, time, stat, urllib, json
import epub
import chore


# How many of their most recent books to offer
NRECENT = 4

# The GET part of our handling
class GET_mixin(object):

................................................................................
        for f,ftm in newest:
            # Make URL a local ref, so it can straddle HTTP/HTTPS
            #  and internal versus extenal port numbering.
            url = '/' + ('/'.join(f.split('/')[3:]))

            # Extract title of book
            parts = f.split('/')
            title = urllib.unquote_plus(parts[-2])
            secnum = int(parts[-1])

            # When they read it
            tm = time.localtime(ftm)
            tms = time.strftime("%m/%d %H:%M", tm)

            # Add table entry
................................................................................

        # We have the "cfg" for this prefix, point at the
        #  root of those files
        path = cfg["path"]
        rest = self.path.replace(f, '', 1)

        # Deflect nonsense
        parts = [urllib.unquote(p) for p in os.path.split(rest) if p]
        if any((f == "..") for f in parts):
            return False,None

        # Is this an active book?
        # /prefix/...path.../<book>/<chap#>
        if (len(parts) > 1) and parts[-2].endswith(".epub"):
            try:
................................................................................
            buf += '<div id="textview"\n'
            buf += '  style="color: white; background: black;'
            buf += '  width: 100%; font-size: 14px;">\n'
            buf += chore.utils.uncharenc(chap.read())
            buf += '</div>\n'
            if chapnum < len(book.chapters)-1:
                buf += '<a href="%d">Next Chapter</a>\n' % \
                 (chapnum+1,)
            doc.close()
            buf += '<script>reading("%s", "%s", "%s");</script>\n' % \
                (self.user, docpath, "textview")
            buf = self.build_tailer(buf)

            return True,self.send_result(buf, "text/html")

................................................................................
                book = epub.Book(doc)
            except:
                return False,None
            buf = self.build_header("<h2>Chapters</h2><p>\n")
            buf += "<ul>\n"
            for chnum in xrange(len(book.chapters)):
                chnum += 1
                tpath = [section] + parts + [ "%d" % (chnum,) ]


                tpath = os.path.join(*tpath)
                buf += ' <li><a href="/%s">%d</a></li>\n' % \
                    (tpath, chnum)
            buf += "</ul>\n"

            # Your index
            buf = self.build_tailer(buf)
................................................................................
        buf = self.build_header("<h2>%s</h2><p>\n" % (label,))

        # List book files (if any)
        if books:
            buf += "<p><h3>Books</h3>\n<ul>\n"
            for f in sorted(books):
                buf += ' <li><a href="%s">%s</a></li>\n' % \
                    (os.path.join(self.path, f), f[:-5])
            buf += "</ul>\n"

        # List sub-folders (if any)
        if dirs:
            buf += "<p><h3>Sub-Folders</h3>\n<ul>\n"
            for d in sorted(dirs):
                buf += ' <li><a href="%s">%s</a></li>\n' % \
                    (os.path.join(self.path, d), d)
            buf += "</ul>\n"

        buf = self.build_tailer(buf)
        return True,self.send_result(buf, "text/html")

    # /state.json?doc=X
    # User's saved state for reading the document with path X
................................................................................
            return False,None
        doc = self.vals.get("doc")
        if doc is None:
            return False,None

        # Get a filesystem safe name, see if we can get the info
        try:
            doc = urllib.quote_plus(urllib.unquote_plus(doc))
            f = open("var/state/%s/%s.json" % (self.user, doc), "r")
            buf = f.read()
            f.close()
        except:
            return False,None

        return True,self.send_result(buf, "application/json")







>







 







|







 







|







 







|







 







|
>
>







 







|







|







 







|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
...
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#	Main UI.  Top part is playlist, bottom is file/dir browser
#  /media/<prefix>/...
#	For each prefix of files, its contents is served by
#	way of its path under here.
import os, time, stat, urllib, json
import epub
import chore
from urllib import quote_plus, unquote_plus

# How many of their most recent books to offer
NRECENT = 4

# The GET part of our handling
class GET_mixin(object):

................................................................................
        for f,ftm in newest:
            # Make URL a local ref, so it can straddle HTTP/HTTPS
            #  and internal versus extenal port numbering.
            url = '/' + ('/'.join(f.split('/')[3:]))

            # Extract title of book
            parts = f.split('/')
            title = unquote_plus(parts[-2])
            secnum = int(parts[-1])

            # When they read it
            tm = time.localtime(ftm)
            tms = time.strftime("%m/%d %H:%M", tm)

            # Add table entry
................................................................................

        # We have the "cfg" for this prefix, point at the
        #  root of those files
        path = cfg["path"]
        rest = self.path.replace(f, '', 1)

        # Deflect nonsense
        parts = [unquote_plus(p) for p in os.path.split(rest) if p]
        if any((f == "..") for f in parts):
            return False,None

        # Is this an active book?
        # /prefix/...path.../<book>/<chap#>
        if (len(parts) > 1) and parts[-2].endswith(".epub"):
            try:
................................................................................
            buf += '<div id="textview"\n'
            buf += '  style="color: white; background: black;'
            buf += '  width: 100%; font-size: 14px;">\n'
            buf += chore.utils.uncharenc(chap.read())
            buf += '</div>\n'
            if chapnum < len(book.chapters)-1:
                buf += '<a href="%d">Next Chapter</a>\n' % \
                 (chapnum+2,)
            doc.close()
            buf += '<script>reading("%s", "%s", "%s");</script>\n' % \
                (self.user, docpath, "textview")
            buf = self.build_tailer(buf)

            return True,self.send_result(buf, "text/html")

................................................................................
                book = epub.Book(doc)
            except:
                return False,None
            buf = self.build_header("<h2>Chapters</h2><p>\n")
            buf += "<ul>\n"
            for chnum in xrange(len(book.chapters)):
                chnum += 1
                tpath = [section] + \
		    [quote_plus(p) for p in parts] + \
		    [ "%d" % (chnum,) ]
                tpath = os.path.join(*tpath)
                buf += ' <li><a href="/%s">%d</a></li>\n' % \
                    (tpath, chnum)
            buf += "</ul>\n"

            # Your index
            buf = self.build_tailer(buf)
................................................................................
        buf = self.build_header("<h2>%s</h2><p>\n" % (label,))

        # List book files (if any)
        if books:
            buf += "<p><h3>Books</h3>\n<ul>\n"
            for f in sorted(books):
                buf += ' <li><a href="%s">%s</a></li>\n' % \
		 (os.path.join(self.path, quote_plus(f)), f[:-5])
            buf += "</ul>\n"

        # List sub-folders (if any)
        if dirs:
            buf += "<p><h3>Sub-Folders</h3>\n<ul>\n"
            for d in sorted(dirs):
                buf += ' <li><a href="%s">%s</a></li>\n' % \
		 (os.path.join(self.path, quote_plus(d)), d)
            buf += "</ul>\n"

        buf = self.build_tailer(buf)
        return True,self.send_result(buf, "text/html")

    # /state.json?doc=X
    # User's saved state for reading the document with path X
................................................................................
            return False,None
        doc = self.vals.get("doc")
        if doc is None:
            return False,None

        # Get a filesystem safe name, see if we can get the info
        try:
            doc = quote_plus(unquote_plus(doc))
            f = open("var/state/%s/%s.json" % (self.user, doc), "r")
            buf = f.read()
            f.close()
        except:
            return False,None

        return True,self.send_result(buf, "application/json")