#NEWLINE# def str_to_datetime_processor_factory( regexp , type_ ) : #NEWLINE# #INDENT# rmatch = regexp . match #NEWLINE# has_named_groups = bool ( regexp . groupindex ) #NEWLINE# def process( value ) : #NEWLINE# #INDENT# if ( value is None ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# m = rmatch ( value ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# raise ValueError ( ( "Couldn't parse %s string '%r' - value is not a string." % ( type_ . __name__ , value ) ) ) #NEWLINE# #UNINDENT# if ( m is None ) : #NEWLINE# #INDENT# raise ValueError ( ( "Couldn't parse %s string: '%s'" % ( type_ . __name__ , value ) ) ) #NEWLINE# #UNINDENT# if has_named_groups : #NEWLINE# #INDENT# groups = m . groupdict ( 0 ) #NEWLINE# return type_ ( ** dict ( list ( zip ( iter ( groups . keys ( ) ) , list ( map ( int , iter ( groups . values ( ) ) ) ) ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return type_ ( * list ( map ( int , m . groups ( 0 ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return regexp