From 5524fd6336a9162aef7687e84705114aa3eb47cd Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Wed, 25 Mar 2015 17:59:42 +0000 Subject: Compile SmartOS line-parsing regex once. --- cloudinit/sources/DataSourceSmartOS.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py index ec2d10ae..c9b497df 100644 --- a/cloudinit/sources/DataSourceSmartOS.py +++ b/cloudinit/sources/DataSourceSmartOS.py @@ -315,6 +315,10 @@ class JoyentMetadataClient(object): The full specification can be found at http://eng.joyent.com/mdata/protocol.html """ + line_regex = re.compile( + r'V2 (?P\d+) (?P[0-9a-f]+)' + r' (?P(?P[0-9a-f]+) (?PSUCCESS|NOTFOUND)' + r'( (?P.+))?)') def __init__(self, serial): self.serial = serial @@ -324,11 +328,7 @@ class JoyentMetadataClient(object): binascii.crc32(body.encode('utf-8')) & 0xffffffff) def _get_value_from_frame(self, expected_request_id, frame): - regex = ( - r'V2 (?P\d+) (?P[0-9a-f]+)' - r' (?P(?P[0-9a-f]+) (?PSUCCESS|NOTFOUND)' - r'( (?P.+))?)') - frame_data = re.match(regex, frame).groupdict() + frame_data = self.line_regex.match(frame).groupdict() if int(frame_data['length']) != len(frame_data['body']): raise JoyentMetadataFetchException( 'Incorrect frame length given ({0} != {1}).'.format( -- cgit v1.2.3