diff options
author | Daniel Watkins <daniel.watkins@canonical.com> | 2015-03-25 17:59:42 +0000 |
---|---|---|
committer | Daniel Watkins <daniel.watkins@canonical.com> | 2015-03-25 17:59:42 +0000 |
commit | 5524fd6336a9162aef7687e84705114aa3eb47cd (patch) | |
tree | ac376c7ce3a82574f18f9c549041e3caeb40db77 /cloudinit/sources | |
parent | 5ae131cad02f383c9f3109ad0f51d918787b0196 (diff) | |
download | vyos-cloud-init-5524fd6336a9162aef7687e84705114aa3eb47cd.tar.gz vyos-cloud-init-5524fd6336a9162aef7687e84705114aa3eb47cd.zip |
Compile SmartOS line-parsing regex once.
Diffstat (limited to 'cloudinit/sources')
-rw-r--r-- | cloudinit/sources/DataSourceSmartOS.py | 10 |
1 files 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<length>\d+) (?P<checksum>[0-9a-f]+)' + r' (?P<body>(?P<request_id>[0-9a-f]+) (?P<status>SUCCESS|NOTFOUND)' + r'( (?P<payload>.+))?)') 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<length>\d+) (?P<checksum>[0-9a-f]+)' - r' (?P<body>(?P<request_id>[0-9a-f]+) (?P<status>SUCCESS|NOTFOUND)' - r'( (?P<payload>.+))?)') - 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( |