Make parsing of OPF major version more robust

This commit is contained in:
Kovid Goyal 2016-06-16 12:59:39 +05:30
parent 72115a92b1
commit 5a2c70e91e

View File

@ -20,10 +20,15 @@ PARSER = etree.XMLParser(recover=True, no_network=True)
OPFVersion = namedtuple('OPFVersion', 'major minor patch') OPFVersion = namedtuple('OPFVersion', 'major minor patch')
def parse_opf_version(raw): def parse_opf_version(raw):
parts = (raw or '').split('.')
try:
major = int(parts[0])
except Exception:
return OPFVersion(2, 0, 0)
try: try:
v = list(map(int, raw.split('.'))) v = list(map(int, raw.split('.')))
except Exception: except Exception:
v = [2, 0, 0] v = [major, 0, 0]
while len(v) < 3: while len(v) < 3:
v.append(0) v.append(0)
v = v[:3] v = v[:3]