mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Update odfpy (used to conver OpenOffice documents)
This commit is contained in:
parent
dc06ef85cf
commit
062fb907e3
@ -16,7 +16,6 @@ from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \
|
|||||||
from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog
|
from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog
|
||||||
from calibre.gui2.dialogs.fetch_metadata import FetchMetadata
|
from calibre.gui2.dialogs.fetch_metadata import FetchMetadata
|
||||||
from calibre.gui2.dialogs.tag_editor import TagEditor
|
from calibre.gui2.dialogs.tag_editor import TagEditor
|
||||||
from calibre.gui2.dialogs.password import PasswordDialog
|
|
||||||
from calibre.gui2.widgets import ProgressIndicator
|
from calibre.gui2.widgets import ProgressIndicator
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
from calibre.ebooks.metadata import authors_to_sort_string, string_to_authors, authors_to_string
|
from calibre.ebooks.metadata import authors_to_sort_string, string_to_authors, authors_to_string
|
||||||
@ -360,26 +359,8 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
tag_string = ', '.join(d.tags)
|
tag_string = ', '.join(d.tags)
|
||||||
self.tags.setText(tag_string)
|
self.tags.setText(tag_string)
|
||||||
|
|
||||||
def lt_password_dialog(self):
|
|
||||||
return PasswordDialog(self, 'LibraryThing account',
|
|
||||||
_('<p>Enter your username and password for '
|
|
||||||
'<b>LibraryThing.com</b>. This is <b>optional</b>. It will '
|
|
||||||
'make fetching of covers faster and more reliable.<br/>If '
|
|
||||||
'you do not have an account, you can '
|
|
||||||
'<a href=\'http://www.librarything.com\'>register</a> for '
|
|
||||||
'free.</p>'))
|
|
||||||
|
|
||||||
def change_password(self):
|
|
||||||
d = self.lt_password_dialog()
|
|
||||||
d.exec_()
|
|
||||||
|
|
||||||
def fetch_cover(self):
|
def fetch_cover(self):
|
||||||
isbn = unicode(self.isbn.text()).strip()
|
isbn = unicode(self.isbn.text()).strip()
|
||||||
#d = self.lt_password_dialog()
|
|
||||||
#if not gui_conf['asked_library_thing_password'] and \
|
|
||||||
# (not d.username() or not d.password()):
|
|
||||||
# d.exec_()
|
|
||||||
# gui_conf['asked_library_thing_password'] = True
|
|
||||||
self.fetch_cover_button.setEnabled(False)
|
self.fetch_cover_button.setEnabled(False)
|
||||||
self.setCursor(Qt.WaitCursor)
|
self.setCursor(Qt.WaitCursor)
|
||||||
title, author = map(unicode, (self.title.text(), self.authors.text()))
|
title, author = map(unicode, (self.title.text(), self.authors.text()))
|
||||||
|
@ -182,11 +182,6 @@ def cnv_points(attribute, arg, element):
|
|||||||
raise ValueError, "Points must be string or [(0,0),(1,1)] - not %s" % arg
|
raise ValueError, "Points must be string or [(0,0),(1,1)] - not %s" % arg
|
||||||
return strarg
|
return strarg
|
||||||
|
|
||||||
def cnv_position(attribute, arg, element):
|
|
||||||
if element == (STYLENS,u'tab-stop'):
|
|
||||||
return cnv_length(attribute, arg, element)
|
|
||||||
return cnv_string(attribute, arg, element)
|
|
||||||
|
|
||||||
def cnv_positiveInteger(attribute, arg, element):
|
def cnv_positiveInteger(attribute, arg, element):
|
||||||
return str(arg)
|
return str(arg)
|
||||||
|
|
||||||
@ -253,7 +248,7 @@ attrconverters = {
|
|||||||
((CHARTNS,u'gap-width'), None): cnv_string,
|
((CHARTNS,u'gap-width'), None): cnv_string,
|
||||||
((CHARTNS,u'interpolation'), None): cnv_string,
|
((CHARTNS,u'interpolation'), None): cnv_string,
|
||||||
((CHARTNS,u'interval-major'), None): cnv_string,
|
((CHARTNS,u'interval-major'), None): cnv_string,
|
||||||
((CHARTNS,u'interval-minor'), None): cnv_string,
|
((CHARTNS,u'interval-minor-divisor'), None): cnv_string,
|
||||||
((CHARTNS,u'japanese-candle-stick'), None): cnv_boolean,
|
((CHARTNS,u'japanese-candle-stick'), None): cnv_boolean,
|
||||||
((CHARTNS,u'label-arrangement'), None): cnv_string,
|
((CHARTNS,u'label-arrangement'), None): cnv_string,
|
||||||
((CHARTNS,u'label-cell-address'), None): cnv_string,
|
((CHARTNS,u'label-cell-address'), None): cnv_string,
|
||||||
@ -352,6 +347,7 @@ attrconverters = {
|
|||||||
((DRAWNS,u'caption-line-length'), None): cnv_length,
|
((DRAWNS,u'caption-line-length'), None): cnv_length,
|
||||||
((DRAWNS,u'caption-point-x'), None): cnv_string,
|
((DRAWNS,u'caption-point-x'), None): cnv_string,
|
||||||
((DRAWNS,u'caption-point-y'), None): cnv_string,
|
((DRAWNS,u'caption-point-y'), None): cnv_string,
|
||||||
|
((DRAWNS,u'caption-id'), None): cnv_IDREF,
|
||||||
((DRAWNS,u'caption-type'), None): cnv_string,
|
((DRAWNS,u'caption-type'), None): cnv_string,
|
||||||
((DRAWNS,u'chain-next-name'), None): cnv_string,
|
((DRAWNS,u'chain-next-name'), None): cnv_string,
|
||||||
((DRAWNS,u'class-id'), None): cnv_string,
|
((DRAWNS,u'class-id'), None): cnv_string,
|
||||||
@ -476,6 +472,7 @@ attrconverters = {
|
|||||||
((DRAWNS,u'modifiers'), None): cnv_string,
|
((DRAWNS,u'modifiers'), None): cnv_string,
|
||||||
((DRAWNS,u'name'), None): cnv_NCName,
|
((DRAWNS,u'name'), None): cnv_NCName,
|
||||||
# ((DRAWNS,u'name'), None): cnv_string,
|
# ((DRAWNS,u'name'), None): cnv_string,
|
||||||
|
((DRAWNS,u'nav-order'), None): cnv_IDREF,
|
||||||
((DRAWNS,u'nohref'), None): cnv_string,
|
((DRAWNS,u'nohref'), None): cnv_string,
|
||||||
((DRAWNS,u'notify-on-update-of-ranges'), None): cnv_string,
|
((DRAWNS,u'notify-on-update-of-ranges'), None): cnv_string,
|
||||||
((DRAWNS,u'object'), None): cnv_string,
|
((DRAWNS,u'object'), None): cnv_string,
|
||||||
@ -683,7 +680,7 @@ attrconverters = {
|
|||||||
((MANIFESTNS,'initialisation-vector'), None): cnv_string,
|
((MANIFESTNS,'initialisation-vector'), None): cnv_string,
|
||||||
((MANIFESTNS,'iteration-count'), None): cnv_nonNegativeInteger,
|
((MANIFESTNS,'iteration-count'), None): cnv_nonNegativeInteger,
|
||||||
((MANIFESTNS,'key-derivation-name'), None): cnv_string,
|
((MANIFESTNS,'key-derivation-name'), None): cnv_string,
|
||||||
((MANIFESTNS,'manifest:media-type'), None): cnv_string,
|
((MANIFESTNS,'media-type'), None): cnv_string,
|
||||||
((MANIFESTNS,'salt'), None): cnv_string,
|
((MANIFESTNS,'salt'), None): cnv_string,
|
||||||
((MANIFESTNS,'size'), None): cnv_nonNegativeInteger,
|
((MANIFESTNS,'size'), None): cnv_nonNegativeInteger,
|
||||||
((METANS,u'cell-count'), None): cnv_nonNegativeInteger,
|
((METANS,u'cell-count'), None): cnv_nonNegativeInteger,
|
||||||
@ -746,6 +743,7 @@ attrconverters = {
|
|||||||
((OFFICENS,u'target-frame'), None): cnv_string,
|
((OFFICENS,u'target-frame'), None): cnv_string,
|
||||||
((OFFICENS,u'target-frame-name'), None): cnv_string,
|
((OFFICENS,u'target-frame-name'), None): cnv_string,
|
||||||
((OFFICENS,u'time-value'), None): cnv_duration,
|
((OFFICENS,u'time-value'), None): cnv_duration,
|
||||||
|
((OFFICENS,u'title'), None): cnv_string,
|
||||||
((OFFICENS,u'value'), None): cnv_double,
|
((OFFICENS,u'value'), None): cnv_double,
|
||||||
((OFFICENS,u'value-type'), None): cnv_string,
|
((OFFICENS,u'value-type'), None): cnv_string,
|
||||||
((OFFICENS,u'version'), None): cnv_string,
|
((OFFICENS,u'version'), None): cnv_string,
|
||||||
@ -783,6 +781,7 @@ attrconverters = {
|
|||||||
((PRESENTATIONNS,u'preset-id'), None): cnv_string,
|
((PRESENTATIONNS,u'preset-id'), None): cnv_string,
|
||||||
((PRESENTATIONNS,u'preset-sub-type'), None): cnv_string,
|
((PRESENTATIONNS,u'preset-sub-type'), None): cnv_string,
|
||||||
((PRESENTATIONNS,u'show'), None): cnv_string,
|
((PRESENTATIONNS,u'show'), None): cnv_string,
|
||||||
|
((PRESENTATIONNS,u'show-end-of-presentation-slide'), None): cnv_boolean,
|
||||||
((PRESENTATIONNS,u'show-logo'), None): cnv_boolean,
|
((PRESENTATIONNS,u'show-logo'), None): cnv_boolean,
|
||||||
((PRESENTATIONNS,u'source'), None): cnv_string,
|
((PRESENTATIONNS,u'source'), None): cnv_string,
|
||||||
((PRESENTATIONNS,u'speed'), None): cnv_string,
|
((PRESENTATIONNS,u'speed'), None): cnv_string,
|
||||||
@ -873,6 +872,8 @@ attrconverters = {
|
|||||||
((STYLENS,u'flow-with-text'), None): cnv_boolean,
|
((STYLENS,u'flow-with-text'), None): cnv_boolean,
|
||||||
((STYLENS,u'font-adornments'), None): cnv_string,
|
((STYLENS,u'font-adornments'), None): cnv_string,
|
||||||
((STYLENS,u'font-charset'), None): cnv_string,
|
((STYLENS,u'font-charset'), None): cnv_string,
|
||||||
|
((STYLENS,u'font-charset-asian'), None): cnv_string,
|
||||||
|
((STYLENS,u'font-charset-complex'), None): cnv_string,
|
||||||
((STYLENS,u'font-family-asian'), None): cnv_string,
|
((STYLENS,u'font-family-asian'), None): cnv_string,
|
||||||
((STYLENS,u'font-family-complex'), None): cnv_string,
|
((STYLENS,u'font-family-complex'), None): cnv_string,
|
||||||
((STYLENS,u'font-family-generic-asian'), None): cnv_string,
|
((STYLENS,u'font-family-generic-asian'), None): cnv_string,
|
||||||
@ -949,7 +950,8 @@ attrconverters = {
|
|||||||
((STYLENS,u'page-usage'), None): cnv_string,
|
((STYLENS,u'page-usage'), None): cnv_string,
|
||||||
((STYLENS,u'paper-tray-name'), None): cnv_string,
|
((STYLENS,u'paper-tray-name'), None): cnv_string,
|
||||||
((STYLENS,u'parent-style-name'), None): cnv_StyleNameRef,
|
((STYLENS,u'parent-style-name'), None): cnv_StyleNameRef,
|
||||||
((STYLENS,u'position'), None): cnv_position,
|
((STYLENS,u'position'), (STYLENS,u'tab-stop')): cnv_length,
|
||||||
|
((STYLENS,u'position'), None): cnv_string,
|
||||||
((STYLENS,u'print'), None): cnv_string,
|
((STYLENS,u'print'), None): cnv_string,
|
||||||
((STYLENS,u'print-content'), None): cnv_boolean,
|
((STYLENS,u'print-content'), None): cnv_boolean,
|
||||||
((STYLENS,u'print-orientation'), None): cnv_string,
|
((STYLENS,u'print-orientation'), None): cnv_string,
|
||||||
@ -1015,7 +1017,7 @@ attrconverters = {
|
|||||||
((STYLENS,u'wrap'), None): cnv_string,
|
((STYLENS,u'wrap'), None): cnv_string,
|
||||||
((STYLENS,u'wrap-contour'), None): cnv_boolean,
|
((STYLENS,u'wrap-contour'), None): cnv_boolean,
|
||||||
((STYLENS,u'wrap-contour-mode'), None): cnv_string,
|
((STYLENS,u'wrap-contour-mode'), None): cnv_string,
|
||||||
((STYLENS,u'wrap-dynamic-treshold'), None): cnv_string,
|
((STYLENS,u'wrap-dynamic-threshold'), None): cnv_length,
|
||||||
((STYLENS,u'writing-mode-automatic'), None): cnv_boolean,
|
((STYLENS,u'writing-mode-automatic'), None): cnv_boolean,
|
||||||
((STYLENS,u'writing-mode'), None): cnv_string,
|
((STYLENS,u'writing-mode'), None): cnv_string,
|
||||||
((SVGNS,u'accent-height'), None): cnv_integer,
|
((SVGNS,u'accent-height'), None): cnv_integer,
|
||||||
@ -1122,7 +1124,7 @@ attrconverters = {
|
|||||||
((TABLENS,u'database-table-name'), None): cnv_string,
|
((TABLENS,u'database-table-name'), None): cnv_string,
|
||||||
((TABLENS,u'date-end'), None): cnv_string,
|
((TABLENS,u'date-end'), None): cnv_string,
|
||||||
((TABLENS,u'date-start'), None): cnv_string,
|
((TABLENS,u'date-start'), None): cnv_string,
|
||||||
((TABLENS,u'date-value-type'), None): cnv_date,
|
((TABLENS,u'date-value'), None): cnv_date,
|
||||||
((TABLENS,u'default-cell-style-name'), None): cnv_StyleNameRef,
|
((TABLENS,u'default-cell-style-name'), None): cnv_StyleNameRef,
|
||||||
((TABLENS,u'direction'), None): cnv_string,
|
((TABLENS,u'direction'), None): cnv_string,
|
||||||
((TABLENS,u'display-border'), None): cnv_boolean,
|
((TABLENS,u'display-border'), None): cnv_boolean,
|
||||||
@ -1304,7 +1306,7 @@ attrconverters = {
|
|||||||
((TEXTNS,u'database-name'), None): cnv_string,
|
((TEXTNS,u'database-name'), None): cnv_string,
|
||||||
((TEXTNS,u'date-adjust'), None): cnv_duration,
|
((TEXTNS,u'date-adjust'), None): cnv_duration,
|
||||||
((TEXTNS,u'date-value'), None): cnv_date,
|
((TEXTNS,u'date-value'), None): cnv_date,
|
||||||
((TEXTNS,u'date-value'), None): cnv_dateTime,
|
# ((TEXTNS,u'date-value'), None): cnv_dateTime,
|
||||||
((TEXTNS,u'default-style-name'), None): cnv_StyleNameRef,
|
((TEXTNS,u'default-style-name'), None): cnv_StyleNameRef,
|
||||||
((TEXTNS,u'description'), None): cnv_string,
|
((TEXTNS,u'description'), None): cnv_string,
|
||||||
((TEXTNS,u'display'), None): cnv_string,
|
((TEXTNS,u'display'), None): cnv_string,
|
||||||
@ -1366,6 +1368,7 @@ attrconverters = {
|
|||||||
((TEXTNS,u'outline-level'), None): cnv_string,
|
((TEXTNS,u'outline-level'), None): cnv_string,
|
||||||
((TEXTNS,u'page-adjust'), None): cnv_integer,
|
((TEXTNS,u'page-adjust'), None): cnv_integer,
|
||||||
((TEXTNS,u'pages'), None): cnv_string,
|
((TEXTNS,u'pages'), None): cnv_string,
|
||||||
|
((TEXTNS,u'paragraph-style-name'), None): cnv_StyleNameRef,
|
||||||
((TEXTNS,u'placeholder-type'), None): cnv_string,
|
((TEXTNS,u'placeholder-type'), None): cnv_string,
|
||||||
((TEXTNS,u'prefix'), None): cnv_string,
|
((TEXTNS,u'prefix'), None): cnv_string,
|
||||||
((TEXTNS,u'protected'), None): cnv_boolean,
|
((TEXTNS,u'protected'), None): cnv_boolean,
|
||||||
@ -1417,6 +1420,7 @@ attrconverters = {
|
|||||||
((TEXTNS,u'use-objects'), None): cnv_boolean,
|
((TEXTNS,u'use-objects'), None): cnv_boolean,
|
||||||
((TEXTNS,u'use-other-objects'), None): cnv_boolean,
|
((TEXTNS,u'use-other-objects'), None): cnv_boolean,
|
||||||
((TEXTNS,u'use-outline-level'), None): cnv_boolean,
|
((TEXTNS,u'use-outline-level'), None): cnv_boolean,
|
||||||
|
((TEXTNS,u'use-soft-page-breaks'), None): cnv_boolean,
|
||||||
((TEXTNS,u'use-spreadsheet-objects'), None): cnv_boolean,
|
((TEXTNS,u'use-spreadsheet-objects'), None): cnv_boolean,
|
||||||
((TEXTNS,u'use-tables'), None): cnv_boolean,
|
((TEXTNS,u'use-tables'), None): cnv_boolean,
|
||||||
((TEXTNS,u'value'), None): cnv_nonNegativeInteger,
|
((TEXTNS,u'value'), None): cnv_nonNegativeInteger,
|
||||||
|
@ -258,10 +258,7 @@ class Element(Node):
|
|||||||
self.ownerDocument = None
|
self.ownerDocument = None
|
||||||
self.childNodes=[]
|
self.childNodes=[]
|
||||||
self.allowed_children = grammar.allowed_children.get(self.qname)
|
self.allowed_children = grammar.allowed_children.get(self.qname)
|
||||||
namespace = self.qname[0]
|
prefix = self.get_nsprefix(self.qname[0])
|
||||||
prefix = _nsassign(namespace)
|
|
||||||
if not self.namespaces.has_key(namespace):
|
|
||||||
self.namespaces[namespace] = prefix
|
|
||||||
self.tagName = prefix + ":" + self.qname[1]
|
self.tagName = prefix + ":" + self.qname[1]
|
||||||
if text is not None:
|
if text is not None:
|
||||||
self.addText(text)
|
self.addText(text)
|
||||||
@ -296,6 +293,13 @@ class Element(Node):
|
|||||||
if self.getAttrNS(r[0],r[1]) is None:
|
if self.getAttrNS(r[0],r[1]) is None:
|
||||||
raise AttributeError, "Required attribute missing: %s in <%s>" % (r[1].lower().replace('-',''), self.tagName)
|
raise AttributeError, "Required attribute missing: %s in <%s>" % (r[1].lower().replace('-',''), self.tagName)
|
||||||
|
|
||||||
|
def get_nsprefix(self, namespace):
|
||||||
|
if namespace is None: namespace = ""
|
||||||
|
prefix = _nsassign(namespace)
|
||||||
|
if not self.namespaces.has_key(namespace):
|
||||||
|
self.namespaces[namespace] = prefix
|
||||||
|
return prefix
|
||||||
|
|
||||||
def allowed_attributes(self):
|
def allowed_attributes(self):
|
||||||
return grammar.allowed_attributes.get(self.qname)
|
return grammar.allowed_attributes.get(self.qname)
|
||||||
|
|
||||||
@ -378,24 +382,18 @@ class Element(Node):
|
|||||||
Must overwrite, If attribute already exists.
|
Must overwrite, If attribute already exists.
|
||||||
"""
|
"""
|
||||||
allowed_attrs = self.allowed_attributes()
|
allowed_attrs = self.allowed_attributes()
|
||||||
prefix = _nsassign(namespace)
|
prefix = self.get_nsprefix(namespace)
|
||||||
if not self.namespaces.has_key(namespace):
|
|
||||||
self.namespaces[namespace] = prefix
|
|
||||||
# if allowed_attrs and (namespace, localpart) not in allowed_attrs:
|
# if allowed_attrs and (namespace, localpart) not in allowed_attrs:
|
||||||
# raise AttributeError, "Attribute %s:%s is not allowed in element <%s>" % ( prefix, localpart, self.tagName)
|
# raise AttributeError, "Attribute %s:%s is not allowed in element <%s>" % ( prefix, localpart, self.tagName)
|
||||||
c = AttrConverters()
|
c = AttrConverters()
|
||||||
self.attributes[prefix + ":" + localpart] = c.convert((namespace, localpart), value, self.qname)
|
self.attributes[prefix + ":" + localpart] = c.convert((namespace, localpart), value, self.qname)
|
||||||
|
|
||||||
def getAttrNS(self, namespace, localpart):
|
def getAttrNS(self, namespace, localpart):
|
||||||
prefix = _nsassign(namespace)
|
prefix = self.get_nsprefix(namespace)
|
||||||
if not self.namespaces.has_key(namespace):
|
|
||||||
self.namespaces[namespace] = prefix
|
|
||||||
return self.attributes.get(prefix + ":" + localpart)
|
return self.attributes.get(prefix + ":" + localpart)
|
||||||
|
|
||||||
def removeAttrNS(self, namespace, localpart):
|
def removeAttrNS(self, namespace, localpart):
|
||||||
prefix = _nsassign(namespace)
|
prefix = self.get_nsprefix(namespace)
|
||||||
if not self.namespaces.has_key(namespace):
|
|
||||||
self.namespaces[namespace] = prefix
|
|
||||||
del self.attributes[prefix + ":" + localpart]
|
del self.attributes[prefix + ":" + localpart]
|
||||||
|
|
||||||
def getAttribute(self, attr):
|
def getAttribute(self, attr):
|
||||||
|
@ -109,11 +109,6 @@ inline_elements = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
struct_elements = (
|
|
||||||
(CONFIGNS,'config-item-set'),
|
|
||||||
(TABLENS,u'table-cell'),
|
|
||||||
)
|
|
||||||
|
|
||||||
# It is almost impossible to determine what elements are block elements.
|
# It is almost impossible to determine what elements are block elements.
|
||||||
# There are so many that don't fit the form
|
# There are so many that don't fit the form
|
||||||
block_elements = (
|
block_elements = (
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -29,12 +29,7 @@ from xml.sax.xmlreader import InputSource
|
|||||||
import xml.sax.saxutils
|
import xml.sax.saxutils
|
||||||
from element import Element
|
from element import Element
|
||||||
from namespaces import OFFICENS
|
from namespaces import OFFICENS
|
||||||
|
|
||||||
try:
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parse the XML files
|
# Parse the XML files
|
||||||
@ -70,7 +65,7 @@ class LoadParser(handler.ContentHandler):
|
|||||||
# Add any accumulated text content
|
# Add any accumulated text content
|
||||||
content = ''.join(self.data).strip()
|
content = ''.join(self.data).strip()
|
||||||
if len(content) > 0:
|
if len(content) > 0:
|
||||||
self.parent.addText(content)
|
self.parent.addText(content, check_grammar=False)
|
||||||
self.data = []
|
self.data = []
|
||||||
# Create the element
|
# Create the element
|
||||||
attrdict = {}
|
attrdict = {}
|
||||||
@ -109,7 +104,7 @@ class LoadParser(handler.ContentHandler):
|
|||||||
self.level = self.level - 1
|
self.level = self.level - 1
|
||||||
str = ''.join(self.data)
|
str = ''.join(self.data)
|
||||||
if len(str.strip()) > 0:
|
if len(str.strip()) > 0:
|
||||||
self.curr.addText(str)
|
self.curr.addText(str, check_grammar=False)
|
||||||
self.data = []
|
self.data = []
|
||||||
self.curr = self.curr.parentNode
|
self.curr = self.curr.parentNode
|
||||||
self.parent = self.curr
|
self.parent = self.curr
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2006-2007 Søren Roug, European Environment Agency
|
# Copyright (C) 2006-2009 Søren Roug, European Environment Agency
|
||||||
#
|
#
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
@ -17,7 +17,7 @@
|
|||||||
#
|
#
|
||||||
# Contributor(s):
|
# Contributor(s):
|
||||||
#
|
#
|
||||||
TOOLSVERSION = u"ODFPY/0.8.2dev"
|
TOOLSVERSION = u"ODFPY/0.9.1dev"
|
||||||
|
|
||||||
ANIMNS = u"urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
|
ANIMNS = u"urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
|
||||||
DBNS = u"urn:oasis:names:tc:opendocument:xmlns:database:1.0"
|
DBNS = u"urn:oasis:names:tc:opendocument:xmlns:database:1.0"
|
||||||
@ -71,7 +71,7 @@ nsdict = {
|
|||||||
OFFICENS: u'office',
|
OFFICENS: u'office',
|
||||||
OOONS: u'ooo',
|
OOONS: u'ooo',
|
||||||
OOOWNS: u'ooow',
|
OOOWNS: u'ooow',
|
||||||
OOOCNS: u'ooc',
|
OOOCNS: u'oooc',
|
||||||
PRESENTATIONNS: u'presentation',
|
PRESENTATIONNS: u'presentation',
|
||||||
RDFANS: u'rdfa',
|
RDFANS: u'rdfa',
|
||||||
SCRIPTNS: u'script',
|
SCRIPTNS: u'script',
|
||||||
|
@ -25,11 +25,7 @@ import xml.sax
|
|||||||
from xml.sax import handler, expatreader
|
from xml.sax import handler, expatreader
|
||||||
from xml.sax.xmlreader import InputSource
|
from xml.sax.xmlreader import InputSource
|
||||||
from xml.sax.saxutils import escape, quoteattr
|
from xml.sax.saxutils import escape, quoteattr
|
||||||
|
|
||||||
try:
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
from namespaces import ANIMNS, CHARTNS, CONFIGNS, DCNS, DR3DNS, DRAWNS, FONS, \
|
from namespaces import ANIMNS, CHARTNS, CONFIGNS, DCNS, DR3DNS, DRAWNS, FONS, \
|
||||||
FORMNS, MATHNS, METANS, NUMBERNS, OFFICENS, PRESENTATIONNS, SCRIPTNS, \
|
FORMNS, MATHNS, METANS, NUMBERNS, OFFICENS, PRESENTATIONNS, SCRIPTNS, \
|
||||||
|
@ -24,12 +24,7 @@ import zipfile
|
|||||||
from xml.sax import make_parser,handler
|
from xml.sax import make_parser,handler
|
||||||
from xml.sax.xmlreader import InputSource
|
from xml.sax.xmlreader import InputSource
|
||||||
import xml.sax.saxutils
|
import xml.sax.saxutils
|
||||||
|
|
||||||
try:
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
|
|
||||||
MANIFESTNS="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
|
MANIFESTNS="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
|
||||||
|
|
||||||
|
@ -44,19 +44,19 @@ def Chart(**args):
|
|||||||
def DdeSource(**args):
|
def DdeSource(**args):
|
||||||
return Element(qname = (OFFICENS,'dde-source'), **args)
|
return Element(qname = (OFFICENS,'dde-source'), **args)
|
||||||
|
|
||||||
def Document(version="1.0", **args):
|
def Document(version="1.1", **args):
|
||||||
return Element(qname = (OFFICENS,'document'), version=version, **args)
|
return Element(qname = (OFFICENS,'document'), version=version, **args)
|
||||||
|
|
||||||
def DocumentContent(version="1.0", **args):
|
def DocumentContent(version="1.1", **args):
|
||||||
return Element(qname = (OFFICENS, 'document-content'), version=version, **args)
|
return Element(qname = (OFFICENS, 'document-content'), version=version, **args)
|
||||||
|
|
||||||
def DocumentMeta(version="1.0", **args):
|
def DocumentMeta(version="1.1", **args):
|
||||||
return Element(qname = (OFFICENS, 'document-meta'), version=version, **args)
|
return Element(qname = (OFFICENS, 'document-meta'), version=version, **args)
|
||||||
|
|
||||||
def DocumentSettings(version="1.0", **args):
|
def DocumentSettings(version="1.1", **args):
|
||||||
return Element(qname = (OFFICENS, 'document-settings'), version=version, **args)
|
return Element(qname = (OFFICENS, 'document-settings'), version=version, **args)
|
||||||
|
|
||||||
def DocumentStyles(version="1.0", **args):
|
def DocumentStyles(version="1.1", **args):
|
||||||
return Element(qname = (OFFICENS, 'document-styles'), version=version, **args)
|
return Element(qname = (OFFICENS, 'document-styles'), version=version, **args)
|
||||||
|
|
||||||
def Drawing(**args):
|
def Drawing(**args):
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
from style import Style, ParagraphProperties, TextProperties
|
|
||||||
|
|
||||||
def addOOoStandardStyles(styles):
|
|
||||||
style = Style(name="Standard", family="paragraph", attributes={'class':"text"})
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Text_20_body", displayname="Text body", family="paragraph", parentstylename="Standard", attributes={'class':"text"})
|
|
||||||
p = ParagraphProperties(margintop="0cm", marginbottom="0.212cm")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Text_20_body_20_indent", displayname="Text body indent", family="paragraph", parentstylename="Text_20_body", attributes={'class':"text"})
|
|
||||||
p = ParagraphProperties(marginleft="0.499cm", marginright="0cm", textindent="0cm", autotextindent="false")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Salutation", family="paragraph", parentstylename="Standard", attributes={'class':"text"})
|
|
||||||
p = ParagraphProperties(numberlines="false", linenumber=0)
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Signature", family="paragraph", parentstylename="Standard", attributes={'class':"text"})
|
|
||||||
p = ParagraphProperties(numberlines="false", linenumber=0)
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Heading", family="paragraph", parentstylename="Standard", nextstylename="Text_20_body", attributes={'class':"text"})
|
|
||||||
p = ParagraphProperties(margintop="0.423cm", marginbottom="0.212cm", keepwithnext="always")
|
|
||||||
style.addElement(p)
|
|
||||||
p = TextProperties(fontname="Nimbus Sans L", fontsize="14pt", fontnameasian="DejaVu LGC Sans", fontsizeasian="14pt", fontnamecomplex="DejaVu LGC Sans", fontsizecomplex="14pt")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Heading_20_1", displayname="Heading 1", family="paragraph", parentstylename="Heading", nextstylename="Text_20_body", attributes={'class':"text"}, defaultoutlinelevel=1)
|
|
||||||
p = TextProperties(fontsize="115%", fontweight="bold", fontsizeasian="115%", fontweightasian="bold", fontsizecomplex="115%", fontweightcomplex="bold")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Heading_20_2", displayname="Heading 2", family="paragraph", parentstylename="Heading", nextstylename="Text_20_body", attributes={'class':"text"}, defaultoutlinelevel=2)
|
|
||||||
p = TextProperties(fontsize="14pt", fontstyle="italic", fontweight="bold", fontsizeasian="14pt", fontstyleasian="italic", fontweightasian="bold", fontsizecomplex="14pt", fontstylecomplex="italic", fontweightcomplex="bold")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Heading_20_3", displayname="Heading 3", family="paragraph", parentstylename="Heading", nextstylename="Text_20_body", attributes={'class':"text"}, defaultoutlinelevel=3)
|
|
||||||
p = TextProperties(fontsize="14pt", fontweight="bold", fontsizeasian="14pt", fontweightasian="bold", fontsizecomplex="14pt", fontweightcomplex="bold")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="List", family="paragraph", parentstylename="Text_20_body", attributes={'class':"list"})
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Caption", family="paragraph", parentstylename="Standard", attributes={'class':"extra"})
|
|
||||||
p = ParagraphProperties(margintop="0.212cm", marginbottom="0.212cm", numberlines="false", linenumber="0")
|
|
||||||
style.addElement(p)
|
|
||||||
p = TextProperties(fontsize="12pt", fontstyle="italic", fontsizeasian="12pt", fontstyleasian="italic", fontsizecomplex="12pt", fontstylecomplex="italic")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Index", family="paragraph", parentstylename="Standard", attributes={'class':"index"})
|
|
||||||
p = ParagraphProperties(numberlines="false", linenumber=0)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Source_20_Text", displayname="Source Text", family="text")
|
|
||||||
p = TextProperties(fontname="Courier", fontnameasian="Courier", fontnamecomplex="Courier")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
||||||
|
|
||||||
style = Style(name="Variable", family="text")
|
|
||||||
p = TextProperties(fontstyle="italic", fontstyleasian="italic", fontstylecomplex="italic")
|
|
||||||
style.addElement(p)
|
|
||||||
styles.addElement(style)
|
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2006-2008 Søren Roug, European Environment Agency
|
# Copyright (C) 2006-2009 Søren Roug, European Environment Agency
|
||||||
#
|
#
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
@ -300,6 +300,37 @@ class OpenDocument:
|
|||||||
self.Pictures[manifestfn] = (IS_IMAGE, content, mediatype)
|
self.Pictures[manifestfn] = (IS_IMAGE, content, mediatype)
|
||||||
return manifestfn
|
return manifestfn
|
||||||
|
|
||||||
|
def addPictureFromFile(self, filename, mediatype=None):
|
||||||
|
""" Add a picture
|
||||||
|
It uses the same convention as OOo, in that it saves the picture in
|
||||||
|
the zipfile in the subdirectory 'Pictures'.
|
||||||
|
If mediatype is not given, it will be guessed from the filename
|
||||||
|
extension.
|
||||||
|
"""
|
||||||
|
if mediatype is None:
|
||||||
|
mediatype, encoding = mimetypes.guess_type(filename)
|
||||||
|
if mediatype is None:
|
||||||
|
mediatype = ''
|
||||||
|
try: ext = filename[filename.rindex('.'):]
|
||||||
|
except ValueError: ext=''
|
||||||
|
else:
|
||||||
|
ext = mimetypes.guess_extension(mediatype)
|
||||||
|
manifestfn = "Pictures/%0.0f%s" % ((time.time()*10000000000), ext)
|
||||||
|
self.Pictures[manifestfn] = (IS_FILENAME, filename, mediatype)
|
||||||
|
return manifestfn
|
||||||
|
|
||||||
|
def addPictureFromString(self, content, mediatype):
|
||||||
|
""" Add a picture
|
||||||
|
It uses the same convention as OOo, in that it saves the picture in
|
||||||
|
the zipfile in the subdirectory 'Pictures'. The content variable
|
||||||
|
is a string that contains the binary image data. The mediatype
|
||||||
|
indicates the image format.
|
||||||
|
"""
|
||||||
|
ext = mimetypes.guess_extension(mediatype)
|
||||||
|
manifestfn = "Pictures/%0.0f%s" % ((time.time()*10000000000), ext)
|
||||||
|
self.Pictures[manifestfn] = (IS_IMAGE, content, mediatype)
|
||||||
|
return manifestfn
|
||||||
|
|
||||||
def addThumbnail(self, filecontent=None):
|
def addThumbnail(self, filecontent=None):
|
||||||
""" Add a fixed thumbnail
|
""" Add a fixed thumbnail
|
||||||
The thumbnail in the library is big, so this is pretty useless.
|
The thumbnail in the library is big, so this is pretty useless.
|
||||||
@ -394,6 +425,7 @@ class OpenDocument:
|
|||||||
|
|
||||||
# Write any extra files
|
# Write any extra files
|
||||||
for op in self._extra:
|
for op in self._extra:
|
||||||
|
if op.filename == "META-INF/documentsignatures.xml": continue # Don't save signatures
|
||||||
self.manifest.addElement(manifest.FileEntry(fullpath=op.filename, mediatype=op.mediatype))
|
self.manifest.addElement(manifest.FileEntry(fullpath=op.filename, mediatype=op.mediatype))
|
||||||
zi = zipfile.ZipInfo(op.filename.encode('utf-8'), self._now)
|
zi = zipfile.ZipInfo(op.filename.encode('utf-8'), self._now)
|
||||||
zi.compress_type = zipfile.ZIP_DEFLATED
|
zi.compress_type = zipfile.ZIP_DEFLATED
|
||||||
|
@ -31,11 +31,7 @@ import xml.sax.saxutils
|
|||||||
|
|
||||||
from odf.namespaces import OFFICENS, TEXTNS
|
from odf.namespaces import OFFICENS, TEXTNS
|
||||||
|
|
||||||
try:
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
|
|
||||||
OUTENCODING = "utf-8"
|
OUTENCODING = "utf-8"
|
||||||
|
|
||||||
|
@ -27,3 +27,8 @@ from element import Element
|
|||||||
def Model(**args):
|
def Model(**args):
|
||||||
return Element(qname = (XFORMSNS,'model'), **args)
|
return Element(qname = (XFORMSNS,'model'), **args)
|
||||||
|
|
||||||
|
def Instance(**args):
|
||||||
|
return Element(qname = (XFORMSNS,'instance'), **args)
|
||||||
|
|
||||||
|
def Bind(**args):
|
||||||
|
return Element(qname = (XFORMSNS,'bind'), **args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user