mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Merged revisions 74495 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r74495 | tarek.ziade | 2009-08-17 23:48:22 +0200 (Mon, 17 Aug 2009) | 1 line module cleanup ........
This commit is contained in:
		
							parent
							
								
									74c23ac08d
								
							
						
					
					
						commit
						de550558ca
					
				
					 1 changed files with 20 additions and 16 deletions
				
			
		|  | @ -180,10 +180,11 @@ def process_template_line(self, line): | ||||||
| 
 | 
 | ||||||
|     def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0): |     def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0): | ||||||
|         """Select strings (presumably filenames) from 'self.files' that |         """Select strings (presumably filenames) from 'self.files' that | ||||||
|         match 'pattern', a Unix-style wildcard (glob) pattern.  Patterns |         match 'pattern', a Unix-style wildcard (glob) pattern. | ||||||
|         are not quite the same as implemented by the 'fnmatch' module: '*' | 
 | ||||||
|         and '?'  match non-special characters, where "special" is platform- |         Patterns are not quite the same as implemented by the 'fnmatch' | ||||||
|         dependent: slash on Unix; colon, slash, and backslash on |         module: '*' and '?'  match non-special characters, where "special" | ||||||
|  |         is platform-dependent: slash on Unix; colon, slash, and backslash on | ||||||
|         DOS/Windows; and colon on Mac OS. |         DOS/Windows; and colon on Mac OS. | ||||||
| 
 | 
 | ||||||
|         If 'anchor' is true (the default), then the pattern match is more |         If 'anchor' is true (the default), then the pattern match is more | ||||||
|  | @ -220,13 +221,13 @@ def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0): | ||||||
|         return files_found |         return files_found | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     def exclude_pattern (self, pattern, |     def exclude_pattern(self, pattern, anchor=1, prefix=None, is_regex=0): | ||||||
|                          anchor=1, prefix=None, is_regex=0): |  | ||||||
|         """Remove strings (presumably filenames) from 'files' that match |         """Remove strings (presumably filenames) from 'files' that match | ||||||
|         'pattern'.  Other parameters are the same as for |         'pattern'. | ||||||
|         'include_pattern()', above. | 
 | ||||||
|         The list 'self.files' is modified in place. |         Other parameters are the same as for 'include_pattern()', above. | ||||||
|         Return True if files are found, False otherwise. |         The list 'self.files' is modified in place. Return 1 if files are | ||||||
|  |         found. | ||||||
|         """ |         """ | ||||||
|         files_found = False |         files_found = False | ||||||
|         pattern_re = translate_pattern(pattern, anchor, prefix, is_regex) |         pattern_re = translate_pattern(pattern, anchor, prefix, is_regex) | ||||||
|  | @ -275,10 +276,11 @@ def findall(dir=os.curdir): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def glob_to_re(pattern): | def glob_to_re(pattern): | ||||||
|     """Translate a shell-like glob pattern to a regular expression; return |     """Translate a shell-like glob pattern to a regular expression. | ||||||
|     a string containing the regex.  Differs from 'fnmatch.translate()' in | 
 | ||||||
|     that '*' does not match "special characters" (which are |     Return a string containing the regex.  Differs from | ||||||
|     platform-specific). |     'fnmatch.translate()' in that '*' does not match "special characters" | ||||||
|  |     (which are platform-specific). | ||||||
|     """ |     """ | ||||||
|     pattern_re = fnmatch.translate(pattern) |     pattern_re = fnmatch.translate(pattern) | ||||||
| 
 | 
 | ||||||
|  | @ -296,7 +298,9 @@ def glob_to_re(pattern): | ||||||
| 
 | 
 | ||||||
| def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0): | def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0): | ||||||
|     """Translate a shell-like wildcard pattern to a compiled regular |     """Translate a shell-like wildcard pattern to a compiled regular | ||||||
|     expression.  Return the compiled regex.  If 'is_regex' true, |     expression. | ||||||
|  | 
 | ||||||
|  |     Return the compiled regex.  If 'is_regex' true, | ||||||
|     then 'pattern' is directly compiled to a regex (if it's a string) |     then 'pattern' is directly compiled to a regex (if it's a string) | ||||||
|     or just returned as-is (assumes it's a regex object). |     or just returned as-is (assumes it's a regex object). | ||||||
|     """ |     """ | ||||||
|  | @ -314,7 +318,7 @@ def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0): | ||||||
|     if prefix is not None: |     if prefix is not None: | ||||||
|         # ditch end of pattern character |         # ditch end of pattern character | ||||||
|         empty_pattern = glob_to_re('') |         empty_pattern = glob_to_re('') | ||||||
|         prefix_re = (glob_to_re(prefix))[:-len(empty_pattern)] |         prefix_re = glob_to_re(prefix)[:-len(empty_pattern)] | ||||||
|         pattern_re = "^" + os.path.join(prefix_re, ".*" + pattern_re) |         pattern_re = "^" + os.path.join(prefix_re, ".*" + pattern_re) | ||||||
|     else:                               # no prefix -- respect anchor flag |     else:                               # no prefix -- respect anchor flag | ||||||
|         if anchor: |         if anchor: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tarek Ziadé
						Tarek Ziadé