aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/misc_utils.py
diff options
context:
space:
mode:
authorGravatar borenet <borenet@google.com>2014-06-25 08:40:58 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-06-25 08:40:58 -0700
commit3da21d2b62270c993167e98b28a3b6a0967f847f (patch)
tree8c28c324a9a2e09fe5d4a9f272a6ce4c82772114 /tools/misc_utils.py
parentec368cf4d6efec8354c2c316cabfb3f5d59643f8 (diff)
Whitespace fixes for Python tools
BUG=skia: R=rmistry@google.com Author: borenet@google.com Review URL: https://codereview.chromium.org/353853003
Diffstat (limited to 'tools/misc_utils.py')
-rw-r--r--tools/misc_utils.py91
1 files changed, 46 insertions, 45 deletions
diff --git a/tools/misc_utils.py b/tools/misc_utils.py
index c3e09da40f..89a2f924b1 100644
--- a/tools/misc_utils.py
+++ b/tools/misc_utils.py
@@ -11,48 +11,49 @@ import re
class ReSearch(object):
- """A collection of static methods for regexing things."""
-
- @staticmethod
- def search_within_stream(input_stream, pattern, default=None):
- """Search for regular expression in a file-like object.
-
- Opens a file for reading and searches line by line for a match to
- the regex and returns the parenthesized group named return for the
- first match. Does not search across newlines.
-
- For example:
- pattern = '^root(:[^:]*){4}:(?P<return>[^:]*)'
- with open('/etc/passwd', 'r') as stream:
- return search_within_file(stream, pattern)
- should return root's home directory (/root on my system).
-
- Args:
- input_stream: file-like object to be read
- pattern: (string) to be passed to re.compile
- default: what to return if no match
-
- Returns:
- A string or whatever default is
- """
- pattern_object = re.compile(pattern)
- for line in input_stream:
- match = pattern_object.search(line)
- if match:
- return match.group('return')
- return default
-
- @staticmethod
- def search_within_string(input_string, pattern, default=None):
- """Search for regular expression in a string.
-
- Args:
- input_string: (string) to be searched
- pattern: (string) to be passed to re.compile
- default: what to return if no match
-
- Returns:
- A string or whatever default is
- """
- match = re.search(pattern, input_string)
- return match.group('return') if match else default
+ """A collection of static methods for regexing things."""
+
+ @staticmethod
+ def search_within_stream(input_stream, pattern, default=None):
+ """Search for regular expression in a file-like object.
+
+ Opens a file for reading and searches line by line for a match to
+ the regex and returns the parenthesized group named return for the
+ first match. Does not search across newlines.
+
+ For example:
+ pattern = '^root(:[^:]*){4}:(?P<return>[^:]*)'
+ with open('/etc/passwd', 'r') as stream:
+ return search_within_file(stream, pattern)
+ should return root's home directory (/root on my system).
+
+ Args:
+ input_stream: file-like object to be read
+ pattern: (string) to be passed to re.compile
+ default: what to return if no match
+
+ Returns:
+ A string or whatever default is
+ """
+ pattern_object = re.compile(pattern)
+ for line in input_stream:
+ match = pattern_object.search(line)
+ if match:
+ return match.group('return')
+ return default
+
+ @staticmethod
+ def search_within_string(input_string, pattern, default=None):
+ """Search for regular expression in a string.
+
+ Args:
+ input_string: (string) to be searched
+ pattern: (string) to be passed to re.compile
+ default: what to return if no match
+
+ Returns:
+ A string or whatever default is
+ """
+ match = re.search(pattern, input_string)
+ return match.group('return') if match else default
+