forked from beba/foerderbarometer
				
			
		
			
	
	
		
			43 lines
		
	
	
		
			949 B
		
	
	
	
		
			Python
		
	
	
	
		
		
			
		
	
	
			43 lines
		
	
	
		
			949 B
		
	
	
	
		
			Python
		
	
	
	
| 
								 | 
							
								import os
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								from .confirmation import TRUTHY
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								def env(key, default=None, parser=None):
							 | 
						||
| 
								 | 
							
								    value = os.environ.get(key)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if value is None:
							 | 
						||
| 
								 | 
							
								        return default
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if parser is None:
							 | 
						||
| 
								 | 
							
								        if default is None:
							 | 
						||
| 
								 | 
							
								            return value
							 | 
						||
| 
								 | 
							
								        else:
							 | 
						||
| 
								 | 
							
								            parser = type(default)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if parser is bool:
							 | 
						||
| 
								 | 
							
								        return truthy(value, default)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return parser(value)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								def truthy(value, default=False):
							 | 
						||
| 
								 | 
							
								    return TRUTHY.get(value, default)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								def password_validators(*validators):
							 | 
						||
| 
								 | 
							
								    return list(_parse_password_validators(validators))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								def _parse_password_validators(validators):
							 | 
						||
| 
								 | 
							
								    for validator in validators:
							 | 
						||
| 
								 | 
							
								        if isinstance(validator, (tuple, list)):
							 | 
						||
| 
								 | 
							
								            validator, options = validator
							 | 
						||
| 
								 | 
							
								        else:
							 | 
						||
| 
								 | 
							
								            validator, options = validator, {}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        if '.' not in validator:
							 | 
						||
| 
								 | 
							
								            validator = 'django.contrib.auth.password_validation.%s' % validator
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        yield dict(NAME=validator, OPTIONS=options)
							 |