provide separate 'normalizeName()' method
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3925 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									8ecf2645f1
								
							
						
					
					
						commit
						2fb16b5c24
					
				
					 1 changed files with 31 additions and 28 deletions
				
			
		
							
								
								
									
										59
									
								
								common.py
									
										
									
									
									
								
							
							
						
						
									
										59
									
								
								common.py
									
										
									
									
									
								
							| 
						 | 
					@ -224,38 +224,41 @@ class NameChooser(BaseNameChooser):
 | 
				
			||||||
        return self.normalizeName(title)
 | 
					        return self.normalizeName(title)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def normalizeName(self, baseName):
 | 
					    def normalizeName(self, baseName):
 | 
				
			||||||
        result = []
 | 
					        return normalizeName(baseName)
 | 
				
			||||||
        for c in baseName:
 | 
					 | 
				
			||||||
            try:
 | 
					 | 
				
			||||||
                c = c.encode('ISO8859-15')
 | 
					 | 
				
			||||||
            except UnicodeEncodeError:
 | 
					 | 
				
			||||||
                # skip all characters not representable in ISO encoding
 | 
					 | 
				
			||||||
                continue
 | 
					 | 
				
			||||||
            if c in '._':
 | 
					 | 
				
			||||||
                # separator and special characters to keep
 | 
					 | 
				
			||||||
                result.append(c)
 | 
					 | 
				
			||||||
                continue
 | 
					 | 
				
			||||||
            if c in self.specialCharacters:
 | 
					 | 
				
			||||||
                # transform umlauts and other special characters
 | 
					 | 
				
			||||||
                result.append(self.specialCharacters[c].lower())
 | 
					 | 
				
			||||||
                continue
 | 
					 | 
				
			||||||
            if ord(c) > 127:
 | 
					 | 
				
			||||||
                # map to ASCII characters
 | 
					 | 
				
			||||||
                c = chr(ord(c) & 127)
 | 
					 | 
				
			||||||
            if c in ':,/\\ ':
 | 
					 | 
				
			||||||
                # replace separator characters with _
 | 
					 | 
				
			||||||
                result.append('_')
 | 
					 | 
				
			||||||
                # skip all other characters
 | 
					 | 
				
			||||||
            elif not c.isalpha() and not c.isdigit():
 | 
					 | 
				
			||||||
                continue
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                result.append(c.lower())
 | 
					 | 
				
			||||||
        name = unicode(''.join(result))
 | 
					 | 
				
			||||||
        return name
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def normalizeName(baseName):
 | 
				
			||||||
    specialCharacters = {
 | 
					    specialCharacters = {
 | 
				
			||||||
        '\xc4': 'Ae', '\xe4': 'ae', '\xd6': 'Oe', '\xf6': 'oe',
 | 
					        '\xc4': 'Ae', '\xe4': 'ae', '\xd6': 'Oe', '\xf6': 'oe',
 | 
				
			||||||
        '\xdc': 'Ue', '\xfc': 'ue', '\xdf': 'ss'}
 | 
					        '\xdc': 'Ue', '\xfc': 'ue', '\xdf': 'ss'}
 | 
				
			||||||
 | 
					    result = []
 | 
				
			||||||
 | 
					    for c in baseName:
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            c = c.encode('ISO8859-15')
 | 
				
			||||||
 | 
					        except UnicodeEncodeError:
 | 
				
			||||||
 | 
					            # skip all characters not representable in ISO encoding
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					        if c in '._':
 | 
				
			||||||
 | 
					            # separator and special characters to keep
 | 
				
			||||||
 | 
					            result.append(c)
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					        if c in specialCharacters:
 | 
				
			||||||
 | 
					            # transform umlauts and other special characters
 | 
				
			||||||
 | 
					            result.append(specialCharacters[c].lower())
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					        if ord(c) > 127:
 | 
				
			||||||
 | 
					            # map to ASCII characters
 | 
				
			||||||
 | 
					            c = chr(ord(c) & 127)
 | 
				
			||||||
 | 
					        if c in ':,/\\ ':
 | 
				
			||||||
 | 
					            # replace separator characters with _
 | 
				
			||||||
 | 
					            result.append('_')
 | 
				
			||||||
 | 
					            # skip all other characters
 | 
				
			||||||
 | 
					        elif not c.isalpha() and not c.isdigit():
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            result.append(c.lower())
 | 
				
			||||||
 | 
					    name = unicode(''.join(result))
 | 
				
			||||||
 | 
					    return name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# virtual attributes/properties
 | 
					# virtual attributes/properties
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue