mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Rewrite normcase() using string.translate...
This commit is contained in:
		
							parent
							
								
									efa683726f
								
							
						
					
					
						commit
						e2ad88c202
					
				
					 1 changed files with 6 additions and 14 deletions
				
			
		| 
						 | 
					@ -5,23 +5,15 @@
 | 
				
			||||||
import string
 | 
					import string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Normalize the case of a pathname.
 | 
					# Normalize the case of a pathname and map slashes to backslashes.
 | 
				
			||||||
# On MS-DOS it maps the pathname to lowercase, turns slashes into
 | 
					# Other normalizations (such as optimizing '../' away) are not done
 | 
				
			||||||
# backslashes.
 | 
					 | 
				
			||||||
# Other normalizations (such as optimizing '../' away) are not allowed
 | 
					 | 
				
			||||||
# (this is done by normpath).
 | 
					# (this is done by normpath).
 | 
				
			||||||
# Previously, this version mapped invalid consecutive characters to a 
 | 
					
 | 
				
			||||||
# single '_', but this has been removed.  This functionality should 
 | 
					_normtable = string.maketrans(string.uppercase + "\\/",
 | 
				
			||||||
# possibly be added as a new function.
 | 
								      string.lowercase + os.sep * 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def normcase(s):
 | 
					def normcase(s):
 | 
				
			||||||
	res, s = splitdrive(s)
 | 
					    return string.translate(s, _normtable)
 | 
				
			||||||
	for c in s:
 | 
					 | 
				
			||||||
		if c in '/\\':
 | 
					 | 
				
			||||||
			res = res + os.sep
 | 
					 | 
				
			||||||
		else:
 | 
					 | 
				
			||||||
			res = res + c
 | 
					 | 
				
			||||||
	return string.lower(res)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Return wheter a path is absolute.
 | 
					# Return wheter a path is absolute.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue