commit 17ce11ac3822ec811fc9b25ed28f24391ae50137 Author: Damian Johnson atagar@torproject.org Date: Sat Sep 29 11:19:59 2012 -0700
Dropping _read_keyword_line_str() and line_matches_keyword()
Dropping a couple of the descriptor helper functions that are no longer used. There's a couple more that I'd like to get rid of but they're not yet fully replaced. --- stem/descriptor/__init__.py | 36 ------------------------------------ stem/descriptor/networkstatus.py | 2 +- 2 files changed, 1 insertions(+), 37 deletions(-)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py index 362500a..ea69300 100644 --- a/stem/descriptor/__init__.py +++ b/stem/descriptor/__init__.py @@ -234,39 +234,6 @@ def _read_keyword_line(keyword, descriptor_file, validate = True, optional = Fal raise ValueError("Error parsing network status document: Expected %s, received: %s" % (keyword, line)) else: return None
-def _read_keyword_line_str(keyword, lines, validate = True, optional = False): - """ - Returns the rest of the line if the first keyword matches the given keyword. If - it doesn't, a ValueError is raised if optional and validate are True, if - not, None is returned. - - Respects the opt keyword and returns the next keyword if the first is "opt". - - :param str keyword: keyword the line must begin with - :param list lines: list of strings to be read from - :param bool validate: validation is enabled - :param bool optional: if the current line must begin with the given keyword - - :returns: the text after the keyword if the keyword matches the one provided, otherwise returns None or raises an exception - - :raises: ValueError if a non-optional keyword doesn't match when validation is enabled - """ - - if not lines: - if not optional and validate: - raise ValueError("Unexpected end of document") - return - - if lines[0].startswith("opt "): - line = line[4:] - if line_matches_keyword(keyword, lines[0]): - line = lines.pop(0) - - return line[len(keyword):].strip() - elif not optional and validate: - raise ValueError("Error parsing network status document: Expected %s, received: %s" % (keyword, lines[0])) - else: return None - def _read_until_keywords(keywords, descriptor_file, inclusive = False, ignore_first = False, skip = False, end_position = None): """ Reads from the descriptor file until we get to one of the given keywords or reach the @@ -438,6 +405,3 @@ def _strptime(string, validate = True, optional = False): if validate or not optional: raise exc else: return None
-def line_matches_keyword(keyword, line): - return re.search("^(opt )?" + re.escape(keyword) + "($| )", line) - diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py index 989bd95..7c95f96 100644 --- a/stem/descriptor/networkstatus.py +++ b/stem/descriptor/networkstatus.py @@ -55,7 +55,7 @@ import stem.exit_policy import stem.util.tor_tools
from stem.descriptor import _read_until_keywords, _peek_keyword, _strptime -from stem.descriptor import _read_keyword_line, _read_keyword_line_str, _get_pseudo_pgp_block, _peek_line +from stem.descriptor import _read_keyword_line, _get_pseudo_pgp_block, _peek_line
# Network status document are either a 'vote' or 'consensus', with different # mandatory fields for each. Both though require that their fields appear in a
tor-commits@lists.torproject.org