Use voussoirkit.stringtools for remove_characters.
This commit is contained in:
		
							parent
							
								
									4988f6dbdd
								
							
						
					
					
						commit
						01f85d41b6
					
				
					 2 changed files with 5 additions and 19 deletions
				
			
		|  | @ -16,6 +16,7 @@ from voussoirkit import bytestring | |||
| from voussoirkit import hms | ||||
| from voussoirkit import imagetools | ||||
| from voussoirkit import pathclass | ||||
| from voussoirkit import stringtools | ||||
| 
 | ||||
| from . import constants | ||||
| from . import exceptions | ||||
|  | @ -413,21 +414,6 @@ def read_filebytes(filepath, range_min=0, range_max=None, chunk_size=bytestring. | |||
|             yield chunk | ||||
|             sent_amount += len(chunk) | ||||
| 
 | ||||
| def remove_characters(text, characters): | ||||
|     translator = {ord(c): None for c in characters} | ||||
|     text = text.translate(translator) | ||||
|     return text | ||||
| 
 | ||||
| def remove_control_characters(text): | ||||
|     ''' | ||||
|     Thanks Alex Quinn | ||||
|     https://stackoverflow.com/a/19016117 | ||||
| 
 | ||||
|     unicodedata.category(character) returns some two-character string | ||||
|     where if [0] is a C then the character is a control character. | ||||
|     ''' | ||||
|     return ''.join(c for c in text if unicodedata.category(c)[0] != 'C') | ||||
| 
 | ||||
| def remove_path_badchars(filepath, allowed=''): | ||||
|     ''' | ||||
|     Remove the bad characters seen in constants.FILENAME_BADCHARS, except | ||||
|  | @ -436,9 +422,9 @@ def remove_path_badchars(filepath, allowed=''): | |||
|     'file*name' -> 'filename' | ||||
|     ('D:\\file*name', allowed=':\\') -> 'D:\\filename' | ||||
|     ''' | ||||
|     badchars = remove_characters(constants.FILENAME_BADCHARS, allowed) | ||||
|     filepath = remove_characters(filepath, badchars) | ||||
|     filepath = remove_control_characters(filepath) | ||||
|     badchars = stringtools.remove_characters(constants.FILENAME_BADCHARS, allowed) | ||||
|     filepath = stringtools.remove_characters(filepath, badchars) | ||||
|     filepath = stringtools.remove_control_characters(filepath) | ||||
| 
 | ||||
|     filepath = filepath.replace('/', os.sep) | ||||
|     filepath = filepath.replace('\\', os.sep) | ||||
|  |  | |||
|  | @ -1278,7 +1278,7 @@ class Tag(ObjectBase, GroupableMixin): | |||
|         #     valid_chars = constants.DEFAULT_CONFIGURATION['tag']['valid_chars'] | ||||
| 
 | ||||
|         name = name.lower() | ||||
|         name = helpers.remove_control_characters(name) | ||||
|         name = stringtools.remove_control_characters(name) | ||||
|         name = re.sub(r'\s+', ' ', name) | ||||
|         name = name.strip(' .+') | ||||
|         name = name.split('+')[0].split('.')[-1] | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue