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