#NEWLINE# def parsetime( t ) : #NEWLINE# #INDENT# 'Parses a time string into a datetime object.  This is the function used by parse the dates in an OWS request, so\n    all OWS requests accept these date formats.  ParseTime accepts the following formats:\n        \n        * \'%Y.%m.%d-%H:%M:%S.%f\'\n        * \'%Y.%m.%d-%H:%M:%S\'\n        * \'%Y.%m.%d-%H:%M\'\n        * \'%Y.%m.%d\'\n        * \'%Y%m%d%H%M%S%f\'\n        * \'%Y%m%d%H%M%S\'\n        * \'%Y%m%d%H%M\'\n        * \'%Y%m%d\'\n        * \'%Y.%m\'\n        * \'%Y\'\n        * \'%Y.%m.%d-%H:%M:%S.%f\'\n        * \'%Y/%m/%d-%H:%M:%S\'\n        * \'%Y/%m/%d-%H:%M\'\n        * \'%Y/%m/%d\'\n        * \'%Y/%m\'\n        * \'%Y\'\n        * "now"\n        * "today"\n        * "today+${days}"\n        * "now+${weeks}w${days}d${hours}h${mins}m${seconds}s${millisecs}ms"\n    \n    :param t: a string in one of the above formats.\n    :return: a datetime object\n    ' #NEWLINE# timeformats = [ '%Y.%m.%d-%H:%M:%S.%f' , '%Y.%m.%d-%H:%M:%S' , '%Y.%m.%d-%H:%M' , '%Y.%m.%d' , '%Y%m%d%H%M%S%f' , '%Y%m%d%H%M%S' , '%Y%m%d%H%M' , '%Y%m%d' , '%Y.%m' , '%Y' , '%Y.%m.%d-%H:%M:%S.%f' , '%Y/%m/%d-%H:%M:%S' , '%Y/%m/%d-%H:%M' , '%Y/%m/%d' , '%Y/%m' , '%Y' ] #NEWLINE# alt_formats = { #NEWLINE# #INDENT# 'now' : datetime . datetime . utcnow ( ) , #NEWLINE# 'today' : datetime . date . today ( ) , #NEWLINE# #UNINDENT# } #NEWLINE# high_level = [ ( re . compile ( 'today(\\+|-)([0-9]+)' ) , _from_today ) , ( re . compile ( 'now(\\+|-)([0-9]+w)?([0-9]+d)?([0-9]+h)?([0-9]+m)?([0-9]+s)?([0-9]+ms)?' ) , _from_now ) ] #NEWLINE# if ( not t ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# ret = None #NEWLINE# for tf in timeformats : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ret = datetime . datetime . strptime ( t , tf ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not ret ) and ( t in alt_formats ) ) : #NEWLINE# #INDENT# return alt_formats [ t ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ret ) : #NEWLINE# #INDENT# for ( tf , l ) in high_level : #NEWLINE# #INDENT# k = tf . match ( t ) #NEWLINE# if k : #NEWLINE# #INDENT# ret = l ( k ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ret : #NEWLINE# #INDENT# return ret #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'time data does not match any valid format: ' + t ) )