From 4174efda6c1c1886e4abc444719cacf74eb51fa5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 25 Jul 2014 13:29:46 +0530 Subject: [PATCH] DRYer --- src/calibre/gui2/tweak_book/editor/__init__.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/__init__.py b/src/calibre/gui2/tweak_book/editor/__init__.py index ce73756a3e..5d2ff0853d 100644 --- a/src/calibre/gui2/tweak_book/editor/__init__.py +++ b/src/calibre/gui2/tweak_book/editor/__init__.py @@ -15,12 +15,9 @@ _xml_types = {'application/oebps-page-map+xml', 'application/vnd.adobe-page-temp guess_type('a.'+x) for x in ('ncx', 'opf', 'svg', 'xpgt', 'xml')} def syntax_from_mime(name, mime): - if mime in OEB_DOCS: - return 'html' - if mime in OEB_STYLES: - return 'css' - if mime in _xml_types: - return 'xml' + for syntax, types in (('html', OEB_DOCS), ('css', OEB_STYLES), ('xml', _xml_types)): + if mime in types: + return syntax if mime.startswith('text/'): return 'text' if mime.startswith('image/') and mime.partition('/')[-1].lower() in {