#NEWLINE# def check_whitelist_blacklist( value , whitelist = None , blacklist = None ) : #NEWLINE# #INDENT# '\n    Check a whitelist and/or blacklist to see if the value matches it.\n    ' #NEWLINE# if ( not any ( ( whitelist , blacklist ) ) ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# in_whitelist = False #NEWLINE# in_blacklist = False #NEWLINE# if whitelist : #NEWLINE# #INDENT# if ( not isinstance ( whitelist , list ) ) : #NEWLINE# #INDENT# whitelist = [ whitelist ] #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# for expr in whitelist : #NEWLINE# #INDENT# if expr_match ( value , expr ) : #NEWLINE# #INDENT# in_whitelist = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# log . error ( 'Non-iterable whitelist {0}' . format ( whitelist ) ) #NEWLINE# whitelist = None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# whitelist = None #NEWLINE# #UNINDENT# if blacklist : #NEWLINE# #INDENT# if ( not isinstance ( blacklist , list ) ) : #NEWLINE# #INDENT# blacklist = [ blacklist ] #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# for expr in blacklist : #NEWLINE# #INDENT# if expr_match ( value , expr ) : #NEWLINE# #INDENT# in_blacklist = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# log . error ( 'Non-iterable blacklist {0}' . format ( whitelist ) ) #NEWLINE# blacklist = None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# blacklist = None #NEWLINE# #UNINDENT# if ( whitelist and ( not blacklist ) ) : #NEWLINE# #INDENT# ret = in_whitelist #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( blacklist and ( not whitelist ) ) : #NEWLINE# #INDENT# ret = ( not in_blacklist ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( whitelist and blacklist ) : #NEWLINE# #INDENT# ret = ( in_whitelist and ( not in_blacklist ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ret