Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Factorize removing comments and empty lines from string
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Hanselmann  
View profile  
 More options Oct 3 2012, 9:52 pm
From: Michael Hanselmann <han...@google.com>
Date: Thu, 4 Oct 2012 03:52:13 +0200
Local: Wed, Oct 3 2012 9:52 pm
Subject: [PATCH master] Factorize removing comments and empty lines from string
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bernardo Dal Seno  
View profile  
 More options Oct 4 2012, 7:28 am
From: Bernardo Dal Seno <bdals...@google.com>
Date: Thu, 4 Oct 2012 13:28:21 +0200
Local: Thurs, Oct 4 2012 7:28 am
Subject: Re: [PATCH master] Factorize removing comments and empty lines from string

On Thu, Oct 4, 2012 at 3:52 AM, Michael Hanselmann <han...@google.com> wrote:
> 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(-)
> +  for line in text.splitlines():
> +    line = line.strip()

This stripping is not advertised in the doc string. Please document
it, then LGTM.

Bernardo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »