From 276ec769f7d863ef5bd413387d9ea8312434e2db Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 29 May 2010 00:45:37 -0600 Subject: [PATCH] Remove genshi from calibre source tree as calibre no longer depends on it --- COPYRIGHT | 12 +- src/calibre/library/catalog.py | 146 +- src/calibre/utils/genshi/LICENSE | 28 - src/calibre/utils/genshi/__init__.py | 26 - src/calibre/utils/genshi/builder.py | 362 ----- src/calibre/utils/genshi/core.py | 707 --------- src/calibre/utils/genshi/filters/__init__.py | 20 - src/calibre/utils/genshi/filters/html.py | 397 ----- src/calibre/utils/genshi/filters/i18n.py | 528 ------- src/calibre/utils/genshi/filters/transform.py | 1309 ----------------- src/calibre/utils/genshi/input.py | 449 ------ src/calibre/utils/genshi/output.py | 773 ---------- src/calibre/utils/genshi/path.py | 1170 --------------- src/calibre/utils/genshi/template/__init__.py | 23 - src/calibre/utils/genshi/template/base.py | 601 -------- .../utils/genshi/template/directives.py | 745 ---------- src/calibre/utils/genshi/template/eval.py | 826 ----------- .../utils/genshi/template/interpolation.py | 151 -- src/calibre/utils/genshi/template/loader.py | 328 ----- src/calibre/utils/genshi/template/markup.py | 305 ---- src/calibre/utils/genshi/template/plugin.py | 176 --- src/calibre/utils/genshi/template/text.py | 333 ----- src/calibre/utils/genshi/util.py | 250 ---- 23 files changed, 49 insertions(+), 9616 deletions(-) delete mode 100644 src/calibre/utils/genshi/LICENSE delete mode 100644 src/calibre/utils/genshi/__init__.py delete mode 100644 src/calibre/utils/genshi/builder.py delete mode 100644 src/calibre/utils/genshi/core.py delete mode 100644 src/calibre/utils/genshi/filters/__init__.py delete mode 100644 src/calibre/utils/genshi/filters/html.py delete mode 100644 src/calibre/utils/genshi/filters/i18n.py delete mode 100644 src/calibre/utils/genshi/filters/transform.py delete mode 100644 src/calibre/utils/genshi/input.py delete mode 100644 src/calibre/utils/genshi/output.py delete mode 100644 src/calibre/utils/genshi/path.py delete mode 100644 src/calibre/utils/genshi/template/__init__.py delete mode 100644 src/calibre/utils/genshi/template/base.py delete mode 100644 src/calibre/utils/genshi/template/directives.py delete mode 100644 src/calibre/utils/genshi/template/eval.py delete mode 100644 src/calibre/utils/genshi/template/interpolation.py delete mode 100644 src/calibre/utils/genshi/template/loader.py delete mode 100644 src/calibre/utils/genshi/template/markup.py delete mode 100644 src/calibre/utils/genshi/template/plugin.py delete mode 100644 src/calibre/utils/genshi/template/text.py delete mode 100644 src/calibre/utils/genshi/util.py diff --git a/COPYRIGHT b/COPYRIGHT index cc3214c9de..a31d1dbcda 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -30,6 +30,12 @@ License: BSD The full text of the BSD license is distributed as in /usr/share/common-licenses/BSD on Debian systems. +Files: /src/routes/* +Copyright: Copyright (c) 2005-2008 Ben Bangert +License: BSD + The full text of the BSD license is distributed as in + /usr/share/common-licenses/BSD on Debian systems. + Files: src/odf/* Copyright: Copyright (C) 2006-2008 Søren Roug, European Environment Agency License: LGPL2.1+ @@ -50,12 +56,6 @@ License: BSD The full text of the BSD license is distributed as in /usr/share/common-licenses/BSD on Debian systems. -Files: src/calibre/utils/genshi/* -Copyright: Copyright (C) 2006-2008 Edgewall Software -License: BSD - The full text of the BSD license is distributed as in - /usr/share/common-licenses/BSD on Debian systems. - Files: src/calibre/utils/lzx/* Copyright: Copyright (C) 2002, Matthew T. Russotto Copyright: Copyright (C) 2008, Marshall T. Vandegrift diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index 8f61930426..53a93deac4 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -127,120 +127,60 @@ class CSV_XML(CatalogPlugin): elif self.fmt == 'xml': from lxml import etree + from lxml.builder import E - from calibre.utils.genshi.template import MarkupTemplate + root = E.calibredb() + for r in data: + record = E.record() + root.append(record) - PY_NAMESPACE = "http://genshi.edgewall.org/" - PY = "{%s}" % PY_NAMESPACE - NSMAP = {'py' : PY_NAMESPACE} - root = etree.Element('calibredb', nsmap=NSMAP) - py_for = etree.SubElement(root, PY + 'for', each="record in data") - record = etree.SubElement(py_for, 'record') + for field in ('id', 'uuid', 'title', 'publisher', 'rating', 'size', + 'isbn'): + if field in fields: + val = r[field] + if val is None: + continue + if not isinstance(val, (str, unicode)): + val = unicode(val) + item = getattr(E, field)(val) + record.append(item) - if 'id' in fields: - record_child = etree.SubElement(record, 'id') - record_child.set(PY + "if", "record['id']") - record_child.text = "${record['id']}" + if 'authors' in fields: + aus = E.authors(sort=r['author_sort']) + for au in r['authors']: + aus.append(E.author(au)) + record.append(aus) - if 'uuid' in fields: - record_child = etree.SubElement(record, 'uuid') - record_child.set(PY + "if", "record['uuid']") - record_child.text = "${record['uuid']}" + for field in ('timestamp', 'pubdate'): + if field in fields: + record.append(getattr(E, field)(r[field].isoformat())) - if 'title' in fields: - record_child = etree.SubElement(record, 'title') - record_child.set(PY + "if", "record['title']") - record_child.text = "${record['title']}" + if 'tags' in fields and r['tags']: + tags = E.tags() + for tag in r['tags']: + tags.append(E.tag(tag)) + record.append(tags) - if 'authors' in fields: - record_child = etree.SubElement(record, 'authors', sort="${record['author_sort']}") - record_subchild = etree.SubElement(record_child, PY + 'for', each="author in record['authors']") - record_subsubchild = etree.SubElement(record_subchild, 'author') - record_subsubchild.text = '$author' + if 'comments' in fields and r['comments']: + record.append(E.comments(r['comments'])) - if 'publisher' in fields: - record_child = etree.SubElement(record, 'publisher') - record_child.set(PY + "if", "record['publisher']") - record_child.text = "${record['publisher']}" + if 'series' in fields and r['series']: + record.append(E.series(r['series'], + index=str(r['series_index']))) - if 'rating' in fields: - record_child = etree.SubElement(record, 'rating') - record_child.set(PY + "if", "record['rating']") - record_child.text = "${record['rating']}" + if 'cover' in fields and r['cover']: + record.append(E.cover(r['cover'].replace(os.sep, '/'))) - if 'date' in fields: - record_child = etree.SubElement(record, 'date') - record_child.set(PY + "if", "record['date']") - record_child.text = "${record['date'].isoformat()}" + if 'formats' in fields and r['formats']: + fmt = E.formats() + for f in r['formats']: + fmt.append(E.format(f.replace(os.sep, '/'))) + record.append(fmt) - if 'pubdate' in fields: - record_child = etree.SubElement(record, 'pubdate') - record_child.set(PY + "if", "record['pubdate']") - record_child.text = "${record['pubdate'].isoformat()}" + with open(path_to_output, 'w') as f: + f.write(etree.tostring(root, encoding='utf-8', + xml_declaration=True, pretty_print=True)) - if 'size' in fields: - record_child = etree.SubElement(record, 'size') - record_child.set(PY + "if", "record['size']") - record_child.text = "${record['size']}" - - if 'tags' in fields: - # - # - # $tag - # - # - record_child = etree.SubElement(record, 'tags') - record_child.set(PY + "if", "record['tags']") - record_subchild = etree.SubElement(record_child, PY + 'for', each="tag in record['tags']") - record_subsubchild = etree.SubElement(record_subchild, 'tag') - record_subsubchild.text = '$tag' - - if 'comments' in fields: - record_child = etree.SubElement(record, 'comments') - record_child.set(PY + "if", "record['comments']") - record_child.text = "${record['comments']}" - - if 'series' in fields: - # - # ${record['series']} - # - record_child = etree.SubElement(record, 'series') - record_child.set(PY + "if", "record['series']") - record_child.set('index', "${record['series_index']}") - record_child.text = "${record['series']}" - - if 'isbn' in fields: - record_child = etree.SubElement(record, 'isbn') - record_child.set(PY + "if", "record['isbn']") - record_child.text = "${record['isbn']}" - - if 'cover' in fields: - # - # ${record['cover'].replace(os.sep, '/')} - # - record_child = etree.SubElement(record, 'cover') - record_child.set(PY + "if", "record['cover']") - record_child.text = "${record['cover']}" - - if 'formats' in fields: - # - # - # ${path.replace(os.sep, '/')} - # - # - record_child = etree.SubElement(record, 'formats') - record_child.set(PY + "if", "record['formats']") - record_subchild = etree.SubElement(record_child, PY + 'for', each="path in record['formats']") - record_subsubchild = etree.SubElement(record_subchild, 'format') - record_subsubchild.text = "${path.replace(os.sep, '/')}" - - outfile = open(path_to_output, 'w') - template = MarkupTemplate(etree.tostring(root, xml_declaration=True, - encoding="UTF-8", pretty_print=True)) - outfile.write(template.generate(data=data, os=os).render('xml')) - outfile.close() - - return None class EPUB_MOBI(CatalogPlugin): 'ePub catalog generator' diff --git a/src/calibre/utils/genshi/LICENSE b/src/calibre/utils/genshi/LICENSE deleted file mode 100644 index 28b70b6fe2..0000000000 --- a/src/calibre/utils/genshi/LICENSE +++ /dev/null @@ -1,28 +0,0 @@ -Copyright © 2006-2007 Edgewall Software[[BR]] -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. The name of the author may not be used to endorse or promote - products derived from this software without specific prior - written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS -OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/src/calibre/utils/genshi/__init__.py b/src/calibre/utils/genshi/__init__.py deleted file mode 100644 index 813a3e4c99..0000000000 --- a/src/calibre/utils/genshi/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2006-2007 Edgewall Software -# All rights reserved. -# -# This software is licensed as described in the file COPYING, which -# you should have received as part of this distribution. The terms -# are also available at http://genshi.edgewall.org/wiki/License. -# -# This software consists of voluntary contributions made by many -# individuals. For the exact contribution history, see the revision -# history and logs, available at http://genshi.edgewall.org/log/. - -"""This package provides various means for generating and processing web markup -(XML or HTML). - -The design is centered around the concept of streams of markup events (similar -in concept to SAX parsing events) which can be processed in a uniform manner -independently of where or how they are produced. -""" - -__docformat__ = 'restructuredtext en' -__version__ = '0.5.0' - -from calibre.utils.genshi.core import * -from calibre.utils.genshi.input import ParseError, XML, HTML diff --git a/src/calibre/utils/genshi/builder.py b/src/calibre/utils/genshi/builder.py deleted file mode 100644 index fac6185f0a..0000000000 --- a/src/calibre/utils/genshi/builder.py +++ /dev/null @@ -1,362 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2006-2008 Edgewall Software -# All rights reserved. -# -# This software is licensed as described in the file COPYING, which -# you should have received as part of this distribution. The terms -# are also available at http://genshi.edgewall.org/wiki/License. -# -# This software consists of voluntary contributions made by many -# individuals. For the exact contribution history, see the revision -# history and logs, available at http://genshi.edgewall.org/log/. - -"""Support for programmatically generating markup streams from Python code using -a very simple syntax. The main entry point to this module is the `tag` object -(which is actually an instance of the ``ElementFactory`` class). You should -rarely (if ever) need to directly import and use any of the other classes in -this module. - -Elements can be created using the `tag` object using attribute access. For -example: - ->>> doc = tag.p('Some text and ', tag.a('a link', href='http://example.org/'), '.') ->>> doc - - -This produces an `Element` instance which can be further modified to add child -nodes and attributes. This is done by "calling" the element: positional -arguments are added as child nodes (alternatively, the `Element.append` method -can be used for that purpose), whereas keywords arguments are added as -attributes: - ->>> doc(tag.br) - ->>> print doc -

Some text and a link.

- -If an attribute name collides with a Python keyword, simply append an underscore -to the name: - ->>> doc(class_='intro') - ->>> print doc -

Some text and a link.

- -As shown above, an `Element` can easily be directly rendered to XML text by -printing it or using the Python ``str()`` function. This is basically a -shortcut for converting the `Element` to a stream and serializing that -stream: - ->>> stream = doc.generate() ->>> stream #doctest: +ELLIPSIS - ->>> print stream -

Some text and a link.

- - -The `tag` object also allows creating "fragments", which are basically lists -of nodes (elements or text) that don't have a parent element. This can be useful -for creating snippets of markup that are attached to a parent element later (for -example in a template). Fragments are created by calling the `tag` object, which -returns an object of type `Fragment`: - ->>> fragment = tag('Hello, ', tag.em('world'), '!') ->>> fragment - ->>> print fragment -Hello, world! -""" - -try: - set -except NameError: - from sets import Set as set - -from calibre.utils.genshi.core import Attrs, Markup, Namespace, QName, Stream, \ - START, END, TEXT - -__all__ = ['Fragment', 'Element', 'ElementFactory', 'tag'] -__docformat__ = 'restructuredtext en' - - -class Fragment(object): - """Represents a markup fragment, which is basically just a list of element - or text nodes. - """ - __slots__ = ['children'] - - def __init__(self): - """Create a new fragment.""" - self.children = [] - - def __add__(self, other): - return Fragment()(self, other) - - def __call__(self, *args): - """Append any positional arguments as child nodes. - - :see: `append` - """ - map(self.append, args) - return self - - def __iter__(self): - return self._generate() - - def __repr__(self): - return '<%s>' % self.__class__.__name__ - - def __str__(self): - return str(self.generate()) - - def __unicode__(self): - return unicode(self.generate()) - - def __html__(self): - return Markup(self.generate()) - - def append(self, node): - """Append an element or string as child node. - - :param node: the node to append; can be an `Element`, `Fragment`, or a - `Stream`, or a Python string or number - """ - if isinstance(node, (Stream, Element, basestring, int, float, long)): - # For objects of a known/primitive type, we avoid the check for - # whether it is iterable for better performance - self.children.append(node) - elif isinstance(node, Fragment): - self.children.extend(node.children) - elif node is not None: - try: - map(self.append, iter(node)) - except TypeError: - self.children.append(node) - - def _generate(self): - for child in self.children: - if isinstance(child, Fragment): - for event in child._generate(): - yield event - elif isinstance(child, Stream): - for event in child: - yield event - else: - if not isinstance(child, basestring): - child = unicode(child) - yield TEXT, child, (None, -1, -1) - - def generate(self): - """Return a markup event stream for the fragment. - - :rtype: `Stream` - """ - return Stream(self._generate()) - - -def _kwargs_to_attrs(kwargs): - attrs = [] - names = set() - for name, value in kwargs.items(): - name = name.rstrip('_').replace('_', '-') - if value is not None and name not in names: - attrs.append((QName(name), unicode(value))) - names.add(name) - return Attrs(attrs) - - -class Element(Fragment): - """Simple XML output generator based on the builder pattern. - - Construct XML elements by passing the tag name to the constructor: - - >>> print Element('strong') - - - Attributes can be specified using keyword arguments. The values of the - arguments will be converted to strings and any special XML characters - escaped: - - >>> print Element('textarea', rows=10, cols=60) -