def arg2Arg(cls, value): """ Expand the argument if it contains keywords. These keywords cannot be tested because the value will change in time: v.arg2Arg('today') 2006/3/4 v.arg2Arg('thisday') 11 v.arg2Arg('thismonth') 2 v.arg2Arg('lastyear') 2004 v.arg2Arg('thisyear') 2005 v.arg2Arg('nextyear') 2006 >>> v = Validator() >>> v.arg2Arg('1234') '1234' >>> v.arg2Arg(' 1234 ') '1234' >>> v.arg2Arg('infinite') '10.0e99' """ if isinstance(value, basestring): value = value.strip() # Remove trailing whitespace if value in ('today', 'now'): # Answer (year, month, day) tuple d = DateTime(date=value) return d.date2s(d.getdate(), 'dd/mm/yyyy') if value == 'thisday': return strftime("%d",localtime()) if value == 'thismonth': return strftime("%m",localtime()) if value == 'lastyear': return repr(int(strftime("%Y",localtime())) - 1) if value == 'thisyear': return strftime("%Y",localtime()) if value == 'nextyear': return repr(int(strftime("%Y",localtime())) + 1) if value == 'infinite': return '10.0e99' return value
def arg2Arg(cls, value): """ Expand the argument if it contains keywords. These keywords cannot be tested because the value will change in time: v.arg2Arg('today') 2006/3/4 v.arg2Arg('thisday') 11 v.arg2Arg('thismonth') 2 v.arg2Arg('lastyear') 2004 v.arg2Arg('thisyear') 2005 v.arg2Arg('nextyear') 2006 >>> v = Validator() >>> v.arg2Arg('1234') '1234' >>> v.arg2Arg(' 1234 ') '1234' >>> v.arg2Arg('infinite') '10.0e99' """ if isinstance(value, basestring): value = value.strip() # Remove trailing whitespace if value in ('today', 'now'): # Answer (year, month, day) tuple d = DateTime(date=value) return d.date2s(d.getdate(), 'dd/mm/yyyy') if value == 'thisday': return strftime("%d", localtime()) if value == 'thismonth': return strftime("%m", localtime()) if value == 'lastyear': return repr(int(strftime("%Y", localtime())) - 1) if value == 'thisyear': return strftime("%Y", localtime()) if value == 'nextyear': return repr(int(strftime("%Y", localtime())) + 1) if value == 'infinite': return '10.0e99' return value