From 4fbbc18f9f5e4a3a95f942c2c5c3350c45bb5250 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sat, 25 May 2019 17:43:47 +0300 Subject: [PATCH] Accept mix of localized hints and regular names in XML importer --- service/port/xml.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/service/port/xml.py b/service/port/xml.py index f3b993fc8..40a4ef26b 100644 --- a/service/port/xml.py +++ b/service/port/xml.py @@ -47,8 +47,14 @@ L_MARK = "<localized hint="" LOCALIZED_PATTERN = re.compile(r'([^\*]+)\*') +class ExtractingError(Exception): + pass + + def _extract_match(t): m = LOCALIZED_PATTERN.match(t) + if m is None: + raise ExtractingError # hint attribute, text content return m.group(1), m.group(2) @@ -63,8 +69,11 @@ def _resolve_ship(fitting, sMkt, b_localized): shipType = fitting.getElementsByTagName("shipType").item(0).getAttribute("value") anything = None if b_localized: - # expect an official name, emergency cache - shipType, anything = _extract_match(shipType) + try: + # expect an official name, emergency cache + shipType, anything = _extract_match(shipType) + except ExtractingError: + pass limit = 2 ship = None @@ -107,8 +116,11 @@ def _resolve_module(hardware, sMkt, b_localized): moduleName = hardware.getAttribute("type") emergency = None if b_localized: - # expect an official name, emergency cache - moduleName, emergency = _extract_match(moduleName) + try: + # expect an official name, emergency cache + moduleName, emergency = _extract_match(moduleName) + except ExtractingError: + pass item = None limit = 2