diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index 1660af59c6..926c0f9c7e 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2008, Marshall T. Vandegrift ' __docformat__ = 'restructuredtext en' -import os, re, uuid, logging +import os, re, logging from collections import defaultdict from itertools import count from urlparse import urldefrag, urlparse, urlunparse, urljoin @@ -21,6 +21,7 @@ from calibre import (isbytestring, as_unicode, get_types_map) from calibre.ebooks.oeb.parse_utils import (barename, XHTML_NS, RECOVER_PARSER, namespace, XHTML, parse_html, NotHTML) from calibre.utils.cleantext import clean_xml_chars +from calibre.utils.short_uuid import uuid4 XML_NS = 'http://www.w3.org/XML/1998/namespace' OEB_DOC_NS = 'http://openebook.org/namespaces/oeb-document/1.0/' @@ -100,7 +101,7 @@ def close_self_closing_tags(raw): return _self_closing_pat.sub(r'<\g\g>>', raw) def uuid_id(): - return 'u'+unicode(uuid.uuid4()) + return u'u'+uuid4() def itercsslinks(raw): for match in _css_url_re.finditer(raw): diff --git a/src/calibre/ebooks/oeb/polish/check/opf.py b/src/calibre/ebooks/oeb/polish/check/opf.py index cc2ed6a2e4..0dae3f15c1 100644 --- a/src/calibre/ebooks/oeb/polish/check/opf.py +++ b/src/calibre/ebooks/oeb/polish/check/opf.py @@ -191,9 +191,9 @@ class NoUID(BaseError): BaseError.__init__(self, _('The OPF has no unique identifier'), name) def __call__(self, container): - import uuid + from calibre.ebooks.oeb.base import uuid_id opf = container.opf - uid = 'u' + str(uuid.uuid4()) + uid = uuid_id() opf.set('unique-identifier', uid) m = container.opf_xpath('/opf:package/opf:metadata') if not m: diff --git a/src/calibre/ebooks/oeb/polish/check/parsing.py b/src/calibre/ebooks/oeb/polish/check/parsing.py index 7e8878e0d3..507c45878d 100644 --- a/src/calibre/ebooks/oeb/polish/check/parsing.py +++ b/src/calibre/ebooks/oeb/polish/check/parsing.py @@ -344,9 +344,9 @@ class InvalidId(BaseError): self.invalid_id = eid def __call__(self, container): - import uuid + from calibre.ebooks.oeb.base import uuid_id from calibre.ebooks.oeb.polish.replace import replace_ids - newid = 'g' + uuid.uuid4().hex + newid = uuid_id() changed = False elems = (e for e in container.parsed(self.name).xpath('//*[@id]') if e.get('id') == self.invalid_id) for e in elems: