mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Merge upstream changes.
This commit is contained in:
commit
31f96140ad
@ -2,7 +2,9 @@
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
import sys, os, re, logging, time, subprocess, atexit, mimetypes
|
||||
import sys, os, re, logging, time, subprocess, atexit, mimetypes, \
|
||||
__builtin__
|
||||
__builtin__.__dict__['dynamic_property'] = lambda(func): func(None)
|
||||
from htmlentitydefs import name2codepoint
|
||||
from math import floor
|
||||
from logging import Formatter
|
||||
|
@ -116,8 +116,8 @@ class Device(Structure):
|
||||
raise Error("Cannot open device")
|
||||
return handle.contents
|
||||
|
||||
@apply
|
||||
def configurations():
|
||||
@dynamic_property
|
||||
def configurations(self):
|
||||
doc = """ List of device configurations. See L{ConfigDescriptor} """
|
||||
def fget(self):
|
||||
ans = []
|
||||
@ -127,8 +127,8 @@ class Device(Structure):
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
class Bus(Structure):
|
||||
@apply
|
||||
def device_list():
|
||||
@dynamic_property
|
||||
def device_list(self):
|
||||
doc = \
|
||||
"""
|
||||
Flat list of devices on this bus.
|
||||
@ -360,4 +360,4 @@ def get_devices():
|
||||
for dev in devices:
|
||||
device = (dev.device_descriptor.idVendor, dev.device_descriptor.idProduct, dev.device_descriptor.bcdDevice)
|
||||
ans.append(device)
|
||||
return ans
|
||||
return ans
|
@ -55,8 +55,8 @@ class Book(object):
|
||||
size = book_metadata_field("size", formatter=int)
|
||||
# When setting this attribute you must use an epoch
|
||||
datetime = book_metadata_field("date", formatter=strptime, setter=strftime)
|
||||
@apply
|
||||
def title_sorter():
|
||||
@dynamic_property
|
||||
def title_sorter(self):
|
||||
doc = '''String to sort the title. If absent, title is returned'''
|
||||
def fget(self):
|
||||
src = self.elem.getAttribute('titleSorter').strip()
|
||||
@ -67,8 +67,8 @@ class Book(object):
|
||||
self.elem.setAttribute('titleSorter', sortable_title(unicode(val)))
|
||||
return property(doc=doc, fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def thumbnail():
|
||||
@dynamic_property
|
||||
def thumbnail(self):
|
||||
doc = \
|
||||
"""
|
||||
The thumbnail. Should be a height 68 image.
|
||||
@ -88,15 +88,15 @@ class Book(object):
|
||||
return decode(rc)
|
||||
return property(fget=fget, doc=doc)
|
||||
|
||||
@apply
|
||||
def path():
|
||||
@dynamic_property
|
||||
def path(self):
|
||||
doc = """ Absolute path to book on device. Setting not supported. """
|
||||
def fget(self):
|
||||
return self.root + self.rpath
|
||||
return property(fget=fget, doc=doc)
|
||||
|
||||
@apply
|
||||
def db_id():
|
||||
@dynamic_property
|
||||
def db_id(self):
|
||||
doc = '''The database id in the application database that this file corresponds to'''
|
||||
def fget(self):
|
||||
match = re.search(r'_(\d+)$', self.rpath.rpartition('.')[0])
|
||||
@ -378,4 +378,4 @@ class BookList(_BookList):
|
||||
|
||||
def write(self, stream):
|
||||
""" Write XML representation of DOM tree to C{stream} """
|
||||
stream.write(self.document.toxml('utf-8'))
|
||||
stream.write(self.document.toxml('utf-8'))
|
@ -39,8 +39,8 @@ class FileFormatter(object):
|
||||
self.name = file.name
|
||||
self.path = file.path
|
||||
|
||||
@apply
|
||||
def mode_string():
|
||||
@dynamic_property
|
||||
def mode_string(self):
|
||||
doc=""" The mode string for this file. There are only two modes read-only and read-write """
|
||||
def fget(self):
|
||||
mode, x = "-", "-"
|
||||
@ -50,8 +50,8 @@ class FileFormatter(object):
|
||||
return mode
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def isdir_name():
|
||||
@dynamic_property
|
||||
def isdir_name(self):
|
||||
doc='''Return self.name + '/' if self is a directory'''
|
||||
def fget(self):
|
||||
name = self.name
|
||||
@ -61,8 +61,8 @@ class FileFormatter(object):
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
|
||||
@apply
|
||||
def name_in_color():
|
||||
@dynamic_property
|
||||
def name_in_color(self):
|
||||
doc=""" The name in ANSI text. Directories are blue, ebooks are green """
|
||||
def fget(self):
|
||||
cname = self.name
|
||||
@ -75,22 +75,22 @@ class FileFormatter(object):
|
||||
return cname
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def human_readable_size():
|
||||
@dynamic_property
|
||||
def human_readable_size(self):
|
||||
doc=""" File size in human readable form """
|
||||
def fget(self):
|
||||
return human_readable(self.size)
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def modification_time():
|
||||
@dynamic_property
|
||||
def modification_time(self):
|
||||
doc=""" Last modified time in the Linux ls -l format """
|
||||
def fget(self):
|
||||
return time.strftime("%Y-%m-%d %H:%M", time.localtime(self.wtime))
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def creation_time():
|
||||
@dynamic_property
|
||||
def creation_time(self):
|
||||
doc=""" Last modified time in the Linux ls -l format """
|
||||
def fget(self):
|
||||
return time.strftime("%Y-%m-%d %H:%M", time.localtime(self.ctime))
|
||||
@ -334,4 +334,4 @@ def main():
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
@ -284,8 +284,8 @@ class Command(TransferBuffer):
|
||||
# Length of the data part of this packet
|
||||
length = field(start=12, fmt=DWORD)
|
||||
|
||||
@apply
|
||||
def data():
|
||||
@dynamic_property
|
||||
def data(self):
|
||||
doc = \
|
||||
"""
|
||||
The data part of this command. Returned/set as/by a TransferBuffer.
|
||||
@ -447,8 +447,8 @@ class LongCommand(Command):
|
||||
self.length = 16
|
||||
self.command = command
|
||||
|
||||
@apply
|
||||
def command():
|
||||
@dynamic_property
|
||||
def command(self):
|
||||
doc = \
|
||||
"""
|
||||
Usually carries extra information needed for the command
|
||||
@ -568,8 +568,8 @@ class FileOpen(PathCommand):
|
||||
PathCommand.__init__(self, path, FileOpen.NUMBER, path_len_at_byte=20)
|
||||
self.mode = mode
|
||||
|
||||
@apply
|
||||
def mode():
|
||||
@dynamic_property
|
||||
def mode(self):
|
||||
doc = \
|
||||
"""
|
||||
The file open mode. Is either L{FileOpen.READ}
|
||||
@ -651,8 +651,8 @@ class Response(Command):
|
||||
raise PacketError("Response packets must have their number set to " \
|
||||
+ hex(0x00001000))
|
||||
|
||||
@apply
|
||||
def data():
|
||||
@dynamic_property
|
||||
def data(self):
|
||||
doc = \
|
||||
"""
|
||||
The last 3 DWORDs (12 bytes) of data in this
|
||||
@ -681,43 +681,43 @@ class ListResponse(Response):
|
||||
PATH_NOT_FOUND = 0xffffffd7 #: Queried path is not found
|
||||
PERMISSION_DENIED = 0xffffffd6 #: Permission denied
|
||||
|
||||
@apply
|
||||
def is_file():
|
||||
@dynamic_property
|
||||
def is_file(self):
|
||||
doc = """ True iff queried path is a file """
|
||||
def fget(self):
|
||||
return self.code == ListResponse.IS_FILE
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def is_invalid():
|
||||
@dynamic_property
|
||||
def is_invalid(self):
|
||||
doc = """ True iff queried path is invalid """
|
||||
def fget(self):
|
||||
return self.code == ListResponse.IS_INVALID
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def path_not_found():
|
||||
@dynamic_property
|
||||
def path_not_found(self):
|
||||
doc = """ True iff queried path is not found """
|
||||
def fget(self):
|
||||
return self.code == ListResponse.PATH_NOT_FOUND
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def permission_denied():
|
||||
@dynamic_property
|
||||
def permission_denied(self):
|
||||
doc = """ True iff permission is denied for path operations """
|
||||
def fget(self):
|
||||
return self.code == ListResponse.PERMISSION_DENIED
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def is_unmounted():
|
||||
@dynamic_property
|
||||
def is_unmounted(self):
|
||||
doc = """ True iff queried path is unmounted (i.e. removed storage card) """
|
||||
def fget(self):
|
||||
return self.code == ListResponse.IS_UNMOUNTED
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def is_eol():
|
||||
@dynamic_property
|
||||
def is_eol(self):
|
||||
doc = """ True iff there are no more items in the list """
|
||||
def fget(self):
|
||||
return self.code == ListResponse.IS_EOL
|
||||
@ -759,8 +759,8 @@ class FileProperties(Answer):
|
||||
# 0 = default permissions, 4 = read only
|
||||
permissions = field(start=36, fmt=DWORD)
|
||||
|
||||
@apply
|
||||
def is_dir():
|
||||
@dynamic_property
|
||||
def is_dir(self):
|
||||
doc = """True if path points to a directory, False if it points to a file."""
|
||||
|
||||
def fget(self):
|
||||
@ -776,8 +776,8 @@ class FileProperties(Answer):
|
||||
return property(doc=doc, fget=fget, fset=fset)
|
||||
|
||||
|
||||
@apply
|
||||
def is_readonly():
|
||||
@dynamic_property
|
||||
def is_readonly(self):
|
||||
doc = """ Whether this file is readonly."""
|
||||
|
||||
def fget(self):
|
||||
@ -801,8 +801,8 @@ class IdAnswer(Answer):
|
||||
|
||||
""" Defines the structure of packets that contain identifiers for queries. """
|
||||
|
||||
@apply
|
||||
def id():
|
||||
@dynamic_property
|
||||
def id(self):
|
||||
doc = \
|
||||
"""
|
||||
The identifier. C{unsigned int} stored in 4 bytes
|
||||
@ -841,8 +841,8 @@ class ListAnswer(Answer):
|
||||
name_length = field(start=20, fmt=DWORD)
|
||||
name = stringfield(name_length, start=24)
|
||||
|
||||
@apply
|
||||
def is_dir():
|
||||
@dynamic_property
|
||||
def is_dir(self):
|
||||
doc = \
|
||||
"""
|
||||
True if list item points to a directory, False if it points to a file.
|
||||
@ -859,4 +859,3 @@ class ListAnswer(Answer):
|
||||
|
||||
return property(doc=doc, fget=fget, fset=fset)
|
||||
|
||||
|
||||
|
@ -64,8 +64,8 @@ class Book(object):
|
||||
# When setting this attribute you must use an epoch
|
||||
datetime = book_metadata_field("date", formatter=strptime, setter=strftime)
|
||||
|
||||
@apply
|
||||
def title_sorter():
|
||||
@dynamic_property
|
||||
def title_sorter(self):
|
||||
doc = '''String to sort the title. If absent, title is returned'''
|
||||
def fget(self):
|
||||
src = self.elem.getAttribute('titleSorter').strip()
|
||||
@ -76,8 +76,8 @@ class Book(object):
|
||||
self.elem.setAttribute('titleSorter', sortable_title(unicode(val)))
|
||||
return property(doc=doc, fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def thumbnail():
|
||||
@dynamic_property
|
||||
def thumbnail(self):
|
||||
doc = \
|
||||
"""
|
||||
The thumbnail. Should be a height 68 image.
|
||||
@ -99,15 +99,15 @@ class Book(object):
|
||||
return decode(rc)
|
||||
return property(fget=fget, doc=doc)
|
||||
|
||||
@apply
|
||||
def path():
|
||||
@dynamic_property
|
||||
def path(self):
|
||||
doc = """ Absolute path to book on device. Setting not supported. """
|
||||
def fget(self):
|
||||
return self.mountpath + self.rpath
|
||||
return property(fget=fget, doc=doc)
|
||||
|
||||
@apply
|
||||
def db_id():
|
||||
@dynamic_property
|
||||
def db_id(self):
|
||||
doc = '''The database id in the application database that this file corresponds to'''
|
||||
def fget(self):
|
||||
match = re.search(r'_(\d+)$', self.rpath.rpartition('.')[0])
|
||||
@ -412,4 +412,4 @@ def fix_ids(main, card):
|
||||
regen_ids(main)
|
||||
regen_ids(card)
|
||||
|
||||
main.set_next_id(str(main.max_id()+1))
|
||||
main.set_next_id(str(main.max_id()+1))
|
@ -21,15 +21,15 @@ class Book(object):
|
||||
def __eq__(self, other):
|
||||
return self.path == other.path
|
||||
|
||||
@apply
|
||||
def title_sorter():
|
||||
@dynamic_property
|
||||
def title_sorter(self):
|
||||
doc = '''String to sort the title. If absent, title is returned'''
|
||||
def fget(self):
|
||||
return re.sub('^\s*A\s+|^\s*The\s+|^\s*An\s+', '', self.title).rstrip()
|
||||
return property(doc=doc, fget=fget)
|
||||
|
||||
@apply
|
||||
def thumbnail():
|
||||
@dynamic_property
|
||||
def thumbnail(self):
|
||||
return None
|
||||
|
||||
def __str__(self):
|
||||
@ -44,4 +44,3 @@ class BookList(_BookList):
|
||||
def set_tags(self, book, tags):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -31,8 +31,8 @@ from cssutils import CSSParser
|
||||
|
||||
class HTMLElement(HtmlElement):
|
||||
|
||||
@apply
|
||||
def specified_font_size():
|
||||
@dynamic_property
|
||||
def specified_font_size(self):
|
||||
|
||||
def fget(self):
|
||||
ans = self.get('specified_font_size', '')
|
||||
@ -47,8 +47,8 @@ class HTMLElement(HtmlElement):
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def computed_font_size():
|
||||
@dynamic_property
|
||||
def computed_font_size(self):
|
||||
def fget(self):
|
||||
ans = self.get('computed_font_size', '')
|
||||
if ans == '':
|
||||
@ -1148,4 +1148,4 @@ output = %s
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
sys.exit(main())
|
@ -207,32 +207,32 @@ class Tag(object):
|
||||
s += " at %08X, contents: %s" % (self.offset, repr(self.contents))
|
||||
return s
|
||||
|
||||
@apply
|
||||
def byte():
|
||||
@dynamic_property
|
||||
def byte(self):
|
||||
def fget(self):
|
||||
if len(self.contents) != 1:
|
||||
raise LRFParseError("Bad parameter for tag ID: %04X" % self.id)
|
||||
return struct.unpack("<B", self.contents)[0]
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def word():
|
||||
@dynamic_property
|
||||
def word(self):
|
||||
def fget(self):
|
||||
if len(self.contents) != 2:
|
||||
raise LRFParseError("Bad parameter for tag ID: %04X" % self.id)
|
||||
return struct.unpack("<H", self.contents)[0]
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def sword():
|
||||
@dynamic_property
|
||||
def sword(self):
|
||||
def fget(self):
|
||||
if len(self.contents) != 2:
|
||||
raise LRFParseError("Bad parameter for tag ID: %04X" % self.id)
|
||||
return struct.unpack("<h", self.contents)[0]
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def dword():
|
||||
@dynamic_property
|
||||
def dword(self):
|
||||
def fget(self):
|
||||
if len(self.contents) != 4:
|
||||
raise LRFParseError("Bad parameter for tag ID: %04X" % self.id)
|
||||
|
@ -38,8 +38,8 @@ class ManifestItem(Resource):
|
||||
res.mime_type = mt
|
||||
return res
|
||||
|
||||
@apply
|
||||
def media_type():
|
||||
@dynamic_property
|
||||
def media_type(self):
|
||||
def fget(self):
|
||||
return self.mime_type
|
||||
def fset(self, val):
|
||||
@ -242,14 +242,14 @@ class OPF(MetaInformation):
|
||||
def __init__(self):
|
||||
raise NotImplementedError('Abstract base class')
|
||||
|
||||
@apply
|
||||
def package():
|
||||
@dynamic_property
|
||||
def package(self):
|
||||
def fget(self):
|
||||
return self.soup.find(re.compile('package'))
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def metadata():
|
||||
@dynamic_property
|
||||
def metadata(self):
|
||||
def fget(self):
|
||||
return self.package.find(re.compile('metadata'))
|
||||
return property(fget=fget)
|
||||
@ -540,4 +540,4 @@ class OPFCreator(MetaInformation):
|
||||
if toc is not None and ncx_stream is not None:
|
||||
toc.render(ncx_stream, self.application_id)
|
||||
ncx_stream.flush()
|
||||
|
||||
|
@ -168,8 +168,8 @@ class ManifestItem(Resource):
|
||||
res.mime_type = mt
|
||||
return res
|
||||
|
||||
@apply
|
||||
def media_type():
|
||||
@dynamic_property
|
||||
def media_type(self):
|
||||
def fget(self):
|
||||
return self.mime_type
|
||||
def fset(self, val):
|
||||
@ -606,8 +606,8 @@ class OPF(object):
|
||||
for item in self.iterguide():
|
||||
item.set('href', get_href(item))
|
||||
|
||||
@apply
|
||||
def authors():
|
||||
@dynamic_property
|
||||
def authors(self):
|
||||
|
||||
def fget(self):
|
||||
ans = []
|
||||
@ -626,8 +626,8 @@ class OPF(object):
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def author_sort():
|
||||
@dynamic_property
|
||||
def author_sort(self):
|
||||
|
||||
def fget(self):
|
||||
matches = self.authors_path(self.metadata)
|
||||
@ -649,8 +649,8 @@ class OPF(object):
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def title_sort():
|
||||
@dynamic_property
|
||||
def title_sort(self):
|
||||
|
||||
def fget(self):
|
||||
matches = self.title_path(self.metadata)
|
||||
@ -672,8 +672,8 @@ class OPF(object):
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def title_sort():
|
||||
@dynamic_property
|
||||
def title_sort(self):
|
||||
|
||||
def fget(self):
|
||||
matches = self.title_path(self.metadata)
|
||||
@ -692,8 +692,8 @@ class OPF(object):
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def tags():
|
||||
@dynamic_property
|
||||
def tags(self):
|
||||
|
||||
def fget(self):
|
||||
ans = []
|
||||
@ -710,8 +710,8 @@ class OPF(object):
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def isbn():
|
||||
@dynamic_property
|
||||
def isbn(self):
|
||||
|
||||
def fget(self):
|
||||
for match in self.isbn_path(self.metadata):
|
||||
@ -727,8 +727,8 @@ class OPF(object):
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def application_id():
|
||||
@dynamic_property
|
||||
def application_id(self):
|
||||
|
||||
def fget(self):
|
||||
for match in self.application_id_path(self.metadata):
|
||||
@ -744,8 +744,8 @@ class OPF(object):
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@apply
|
||||
def book_producer():
|
||||
@dynamic_property
|
||||
def book_producer(self):
|
||||
|
||||
def fget(self):
|
||||
for match in self.bkp_path(self.metadata):
|
||||
@ -782,8 +782,8 @@ class OPF(object):
|
||||
return cpath
|
||||
|
||||
|
||||
@apply
|
||||
def cover():
|
||||
@dynamic_property
|
||||
def cover(self):
|
||||
|
||||
def fget(self):
|
||||
if self.guide is not None:
|
||||
@ -1034,4 +1034,4 @@ def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(OPFTest)
|
||||
|
||||
def test():
|
||||
unittest.TextTestRunner(verbosity=2).run(suite())
|
||||
unittest.TextTestRunner(verbosity=2).run(suite())
|
@ -86,8 +86,8 @@ class TOC(list):
|
||||
for i in obj.flat():
|
||||
yield i
|
||||
|
||||
@apply
|
||||
def abspath():
|
||||
@dynamic_property
|
||||
def abspath(self):
|
||||
doc='Return the file this toc entry points to as a absolute path to a file on the system.'
|
||||
def fget(self):
|
||||
if self.href is None:
|
||||
@ -208,4 +208,4 @@ class TOC(list):
|
||||
template = MarkupTemplate(ncx_template)
|
||||
raw = template.generate(uid=uid, toc=self, __appname__=__appname__)
|
||||
raw = raw.render(doctype=doctype)
|
||||
stream.write(raw)
|
||||
stream.write(raw)
|
@ -424,8 +424,8 @@ class Metadata(object):
|
||||
def __getattr__(self, term):
|
||||
return self.items[term]
|
||||
|
||||
@apply
|
||||
def _nsmap():
|
||||
@dynamic_property
|
||||
def _nsmap(self):
|
||||
def fget(self):
|
||||
nsmap = {}
|
||||
for term in self.items:
|
||||
@ -434,8 +434,8 @@ class Metadata(object):
|
||||
return nsmap
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def _opf1_nsmap():
|
||||
@dynamic_property
|
||||
def _opf1_nsmap(self):
|
||||
def fget(self):
|
||||
nsmap = self._nsmap
|
||||
for key, value in nsmap.items():
|
||||
@ -444,8 +444,8 @@ class Metadata(object):
|
||||
return nsmap
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def _opf2_nsmap():
|
||||
@dynamic_property
|
||||
def _opf2_nsmap(self):
|
||||
def fget(self):
|
||||
nsmap = self._nsmap
|
||||
nsmap.update(OPF2_NSMAP)
|
||||
@ -582,8 +582,8 @@ class Manifest(object):
|
||||
etree.SubElement(data, XHTML('body'))
|
||||
return data
|
||||
|
||||
@apply
|
||||
def data():
|
||||
@dynamic_property
|
||||
def data(self):
|
||||
def fget(self):
|
||||
if self._data is not None:
|
||||
return self._data
|
||||
@ -854,8 +854,8 @@ class Guide(object):
|
||||
return 'Reference(type=%r, title=%r, href=%r)' \
|
||||
% (self.type, self.title, self.href)
|
||||
|
||||
@apply
|
||||
def _order():
|
||||
@dynamic_property
|
||||
def _order(self):
|
||||
def fget(self):
|
||||
return self.ORDER.get(self.type, self.type)
|
||||
return property(fget=fget)
|
||||
@ -865,8 +865,8 @@ class Guide(object):
|
||||
return NotImplemented
|
||||
return cmp(self._order, other._order)
|
||||
|
||||
@apply
|
||||
def item():
|
||||
@dynamic_property
|
||||
def item(self):
|
||||
def fget(self):
|
||||
path = urldefrag(self.href)[0]
|
||||
hrefs = self.oeb.manifest.hrefs
|
||||
|
@ -197,14 +197,14 @@ class Document(QWebPage):
|
||||
def bookmark(self):
|
||||
return self.javascript('calculate_bookmark(%d)'%(self.ypos+25), 'string')
|
||||
|
||||
@apply
|
||||
def at_bottom():
|
||||
@dynamic_property
|
||||
def at_bottom(self):
|
||||
def fget(self):
|
||||
return self.height - self.ypos <= self.window_height
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def at_top():
|
||||
@dynamic_property
|
||||
def at_top(self):
|
||||
def fget(self):
|
||||
return self.ypos <= 0
|
||||
return property(fget=fget)
|
||||
@ -213,32 +213,32 @@ class Document(QWebPage):
|
||||
def test(self):
|
||||
pass
|
||||
|
||||
@apply
|
||||
def ypos():
|
||||
@dynamic_property
|
||||
def ypos(self):
|
||||
def fget(self):
|
||||
return self.javascript('window.pageYOffset', 'int')
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def window_height():
|
||||
@dynamic_property
|
||||
def window_height(self):
|
||||
def fget(self):
|
||||
return self.javascript('window.innerHeight', 'int')
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def window_width():
|
||||
@dynamic_property
|
||||
def window_width(self):
|
||||
def fget(self):
|
||||
return self.javascript('window.innerWidth', 'int')
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def xpos():
|
||||
@dynamic_property
|
||||
def xpos(self):
|
||||
def fget(self):
|
||||
return self.javascript('window.pageXOffset', 'int')
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def scroll_fraction():
|
||||
@dynamic_property
|
||||
def scroll_fraction(self):
|
||||
def fget(self):
|
||||
try:
|
||||
return float(self.ypos)/(self.height-self.window_height)
|
||||
@ -246,20 +246,20 @@ class Document(QWebPage):
|
||||
return 0.
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def hscroll_fraction():
|
||||
@dynamic_property
|
||||
def hscroll_fraction(self):
|
||||
def fget(self):
|
||||
return float(self.xpos)/self.width
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def height():
|
||||
@dynamic_property
|
||||
def height(self):
|
||||
def fget(self):
|
||||
return self.javascript('document.body.offsetHeight', 'int') # contentsSize gives inaccurate results
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def width():
|
||||
@dynamic_property
|
||||
def width(self):
|
||||
def fget(self):
|
||||
return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results
|
||||
return property(fget=fget)
|
||||
@ -338,20 +338,20 @@ class DocumentView(QWebView):
|
||||
def sizeHint(self):
|
||||
return self._size_hint
|
||||
|
||||
@apply
|
||||
def scroll_fraction():
|
||||
@dynamic_property
|
||||
def scroll_fraction(self):
|
||||
def fget(self):
|
||||
return self.document.scroll_fraction
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def hscroll_fraction():
|
||||
@dynamic_property
|
||||
def hscroll_fraction(self):
|
||||
def fget(self):
|
||||
return self.document.hscroll_fraction
|
||||
return property(fget=fget)
|
||||
|
||||
@apply
|
||||
def content_size():
|
||||
@dynamic_property
|
||||
def content_size(self):
|
||||
def fget(self):
|
||||
return self.document.width, self.document.height
|
||||
return property(fget=fget)
|
||||
|
@ -818,8 +818,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
# _lock_file = None
|
||||
self.conn.close()
|
||||
|
||||
@apply
|
||||
def user_version():
|
||||
@dynamic_property
|
||||
def user_version(self):
|
||||
doc = 'The user version of this database'
|
||||
def fget(self):
|
||||
return self.conn.get('pragma user_version;', all=False)
|
||||
@ -1670,4 +1670,4 @@ def text_to_tokens(text):
|
||||
|
||||
if __name__ == '__main__':
|
||||
sqlite.enable_callback_tracebacks(True)
|
||||
db = LibraryDatabase('/home/kovid/temp/library1.db.orig')
|
||||
db = LibraryDatabase('/home/kovid/temp/library1.db.orig')
|
@ -311,8 +311,8 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
An ebook metadata database that stores references to ebook files on disk.
|
||||
'''
|
||||
PATH_LIMIT = 40 if 'win32' in sys.platform else 100
|
||||
@apply
|
||||
def user_version():
|
||||
@dynamic_property
|
||||
def user_version(self):
|
||||
doc = 'The user version of this database'
|
||||
|
||||
def fget(self):
|
||||
@ -1323,4 +1323,4 @@ books_series_link feeds
|
||||
progress.reset()
|
||||
return len(books)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user