本文整理汇总了Python中testmanager.core.base.ModelDataBase.validateTs方法的典型用法代码示例。如果您正苦于以下问题:Python ModelDataBase.validateTs方法的具体用法?Python ModelDataBase.validateTs怎么用?Python ModelDataBase.validateTs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testmanager.core.base.ModelDataBase
的用法示例。
在下文中一共展示了ModelDataBase.validateTs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getEffectiveDateParam
# 需要导入模块: from testmanager.core.base import ModelDataBase [as 别名]
# 或者: from testmanager.core.base.ModelDataBase import validateTs [as 别名]
def getEffectiveDateParam(self, sParamName = None):
"""
Gets the effective date parameter.
Returns a timestamp suitable for database and url parameters.
Returns None if not found or empty.
The first call with sParamName set to None will set the internal _tsNow
value upon successfull return.
"""
sName = sParamName if sParamName is not None else WuiDispatcherBase.ksParamEffectiveDate
if sName not in self._dParams:
return None;
if sName not in self._asCheckedParams:
self._asCheckedParams.append(sName);
sValue = self._dParams[sName];
if isinstance(sValue, list):
raise WuiException('%s parameter "%s" is given multiple times: %s' % (self._sAction, sName, sValue));
sValue = sValue.strip();
if sValue == '':
return None;
#
# Timestamp, just validate it and return.
#
if sValue[0] not in ['-', '+']:
(sValue, sError) = ModelDataBase.validateTs(sValue);
if sError is not None:
raise WuiException('%s parameter "%s" ("%s") is invalid: %s' % (self._sAction, sName, sValue, sError));
if sParamName is None and self._tsNow is None:
self._tsNow = sValue;
return sValue;
#
# Relative timestamp. Validate and convert it to a fixed timestamp.
#
chSign = sValue[0];
(sValue, sError) = ModelDataBase.validateTs(sValue[1:]);
if sError is not None:
raise WuiException('%s parameter "%s" ("%s") is invalid: %s' % (self._sAction, sName, sValue, sError));
if sValue[-6] in ['-', '+']:
raise WuiException('%s parameter "%s" ("%s") is a relative timestamp but incorrectly includes a time zone.'
% (self._sAction, sName, sValue));
offTime = 11;
if sValue[offTime - 1] != ' ':
raise WuiException('%s parameter "%s" ("%s") incorrect format.' % (self._sAction, sName, sValue));
sInterval = 'P' + sValue[:(offTime - 1)] + 'T' + sValue[offTime:];
self._oDb.execute('SELECT CURRENT_TIMESTAMP ' + chSign + ' \'' + sInterval + '\'::INTERVAL');
oDate = self._oDb.fetchOne()[0];
sValue = str(oDate);
if sParamName is None and self._tsNow is None:
self._tsNow = sValue;
return sValue;
示例2: getEffectiveDateParam
# 需要导入模块: from testmanager.core.base import ModelDataBase [as 别名]
# 或者: from testmanager.core.base.ModelDataBase import validateTs [as 别名]
def getEffectiveDateParam(self, sParamName=None):
"""
Gets the effective date parameter.
Returns a timestamp suitable for database and url parameters.
Returns None if not found or empty.
"""
sName = sParamName if sParamName is not None else WuiDispatcherBase.ksParamEffectiveDate
if sName not in self._dParams:
return None
if sName not in self._asCheckedParams:
self._asCheckedParams.append(sName)
sValue = self._dParams[sName]
if isinstance(sValue, list):
raise WuiException('%s parameter "%s" is given multiple times: %s' % (self._sAction, sName, sValue))
sValue = sValue.strip()
if sValue == "":
return None
#
# Timestamp, just validate it and return.
#
if sValue[0] not in ["-", "+"]:
(sValue, sError) = ModelDataBase.validateTs(sValue)
if sError is not None:
raise WuiException('%s parameter "%s" ("%s") is invalid: %s' % (self._sAction, sName, sValue, sError))
return sValue
#
# Relative timestamp. Validate and convert it to a fixed timestamp.
#
chSign = sValue[0]
(sValue, sError) = ModelDataBase.validateTs(sValue[1:])
if sError is not None:
raise WuiException('%s parameter "%s" ("%s") is invalid: %s' % (self._sAction, sName, sValue, sError))
if sValue[-6] in ["-", "+"]:
raise WuiException(
'%s parameter "%s" ("%s") is a relative timestamp but incorrectly includes a time zone.'
% (self._sAction, sName, sValue)
)
offTime = 11
if sValue[offTime - 1] != " ":
raise WuiException('%s parameter "%s" ("%s") incorrect format.' % (self._sAction, sName, sValue))
sInterval = "P" + sValue[: (offTime - 1)] + "T" + sValue[offTime:]
self._oDb.execute("SELECT CURRENT_TIMESTAMP " + chSign + " '" + sInterval + "'::INTERVAL")
oDate = self._oDb.fetchOne()[0]
return str(oDate)
示例3: getTsParam
# 需要导入模块: from testmanager.core.base import ModelDataBase [as 别名]
# 或者: from testmanager.core.base.ModelDataBase import validateTs [as 别名]
def getTsParam(self, sName, tsDefault=None, fRequired=True):
"""
Gets a timestamp parameter.
Raises exception if not found and fRequired is True.
"""
if fRequired is False and sName not in self._dParams:
return tsDefault
sValue = self.getStringParam(sName, None, None if tsDefault is None else str(tsDefault))
(sValue, sError) = ModelDataBase.validateTs(sValue)
if sError is not None:
raise WuiException('%s parameter %s value "%s": %s' % (self._sAction, sName, sValue, sError))
return sValue