Michael Hanselmann
unread,Oct 3, 2012, 9:52:13 PM10/3/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ganeti...@googlegroups.com
This will also be used for verifying the file storage directory.
---
lib/http/auth.py | 9 ++-------
lib/utils/text.py | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/lib/http/auth.py b/lib/http/auth.py
index 5a7bfac..1e33f2c 100644
--- a/lib/http/auth.py
+++ b/lib/http/auth.py
@@ -29,6 +29,7 @@ import binascii
from ganeti import compat
from ganeti import http
+from ganeti import utils
from cStringIO import StringIO
@@ -305,13 +306,7 @@ def ParsePasswordFile(contents):
"""
users = {}
- for line in contents.splitlines():
- line = line.strip()
-
- # Ignore empty lines and comments
- if not line or line.startswith("#"):
- continue
-
+ for line in utils.FilterEmptyLinesAndComments(contents):
parts = line.split(None, 2)
if len(parts) < 2:
# Invalid line
diff --git a/lib/utils/text.py b/lib/utils/text.py
index f4c9adc..5785e80 100644
--- a/lib/utils/text.py
+++ b/lib/utils/text.py
@@ -589,3 +589,19 @@ def Truncate(text, length):
return text
else:
return text[:length - len(_ASCII_ELLIPSIS)] + _ASCII_ELLIPSIS
+
+
+def FilterEmptyLinesAndComments(text):
+ """Filters empty lines and comments from a line-based string.
+
+ @type text: string
+ @param text: Input string
+ @rtype: generator
+
+ """
+ for line in text.splitlines():
+ line = line.strip()
+
+ # Ignore empty lines and comments
+ if line and not line.startswith("#"):
+ yield line
--
1.7.7.3