Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(967)

Unified Diff: tools/misc_utils.py

Issue 353853003: Whitespace fixes for Python tools (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/add_codereview_message.py ('k') | tools/roll_deps.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/misc_utils.py
diff --git a/tools/misc_utils.py b/tools/misc_utils.py
index c3e09da40f79910548c4645fd6d59966d0c0687e..89a2f924b13b16d539c182d8e54cd2abf3724413 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
+
« no previous file with comments | « tools/add_codereview_message.py ('k') | tools/roll_deps.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698