Skip to content
This repository was archived by the owner on Nov 15, 2019. It is now read-only.

Commit d5c856f

Browse files
committed
Prevent recompiling of regex
1 parent a2740d7 commit d5c856f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

loader/standard_loader.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ class ParsedBundle(namedtuple('ParsedBundle', ['bundle_uuid', 'metadata_dict', '
1818
def pprint(self):
1919
return pprint.pformat(self, indent=4)
2020

21+
2122
class StandardFormatBundleUploader:
23+
_uuid_regex = re.compile('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
24+
2225
def __init__(self, dss_uploader: DssUploader, metadata_file_uploader: MetadataFileUploader) -> None:
2326
self.dss_uploader = dss_uploader
2427
self.metadata_file_uploader = metadata_file_uploader
@@ -35,10 +38,9 @@ def _parse_bundle(bundle: dict) -> ParsedBundle:
3538
raise
3639
return ParsedBundle(bundle_uuid, metadata_dict, data_objects)
3740

38-
@staticmethod
39-
def _get_file_uuid(file_guid: str):
40-
uuid_regex = re.compile('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
41-
result = uuid_regex.findall(file_guid.lower())
41+
@classmethod
42+
def _get_file_uuid(cls, file_guid: str):
43+
result = cls._uuid_regex.findall(file_guid.lower())
4244
if result is None:
4345
raise ValueError(f'Misformatted file_guid: {file_guid} should contain a uuid.')
4446
if len(result) != 1:
@@ -118,6 +120,7 @@ def load_all_bundles(self, input_json: typing.List[dict]):
118120
bundles_loaded.append(bundle)
119121
logger.info(f'Successfully loaded bundle {parsed_bundle.bundle_uuid}')
120122
except KeyboardInterrupt:
123+
# The bundle that was being processed durng the iterrupt isn't recorded anywhere
121124
logger.exception('Loading canceled with keyboard interrupt')
122125
finally:
123126
bundles_unattempted = len(input_json) \

0 commit comments

Comments
 (0)