From 5be9b757e42447aeb66bbe4d9bdb2b07f2201867 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Thu, 2 May 2013 14:16:31 +0800 Subject: [PATCH] Use builtin startswith and endswith methods in iniparser Change-Id: Icbcd9d9c2f8ebc5f827772a0d8dbfba3f6c72da3 --- oslo/config/iniparser.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/oslo/config/iniparser.py b/oslo/config/iniparser.py index 3e9ddc4c..175ebe81 100644 --- a/oslo/config/iniparser.py +++ b/oslo/config/iniparser.py @@ -34,7 +34,7 @@ class BaseParser(object): return None, [] def _get_section(self, line): - if line[-1] != ']': + if not line.endswith(']'): return self.error_no_section_end_bracket(line) if len(line) <= 2: return self.error_no_section_name(line) @@ -53,8 +53,7 @@ class BaseParser(object): key, value = line[:colon], line[colon + 1:] value = value.strip() - if ((value and value[0] == value[-1]) and - (value[0] == "\"" or value[0] == "'")): + if value and value[0] == value[-1] and value.startswith(("\"", "'")): value = value[1:-1] return key.strip(), [value] @@ -71,7 +70,7 @@ class BaseParser(object): if key: key, value = self._assignment(key, value) continue - elif line[0] in (' ', '\t'): + elif line.startswith((' ', '\t')): # Continuation of previous assignment if key is None: self.error_unexpected_continuation(line) @@ -83,12 +82,12 @@ class BaseParser(object): # Flush previous assignment, if any key, value = self._assignment(key, value) - if line[0] == '[': + if line.startswith('['): # Section start section = self._get_section(line) if section: self.new_section(section) - elif line[0] in '#;': + elif line.startswith(('#', ';')): self.comment(line[1:].lstrip()) else: key, value = self._split_key_value(line)