当前位置: 首页>>代码示例>>Python>>正文


Python ModelDataBase.validateTs方法代码示例

本文整理汇总了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;
开发者ID:svn2github,项目名称:virtualbox,代码行数:61,代码来源:wuibase.py

示例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)
开发者ID:swimming198243,项目名称:virtualbox,代码行数:54,代码来源:wuibase.py

示例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
开发者ID:swimming198243,项目名称:virtualbox,代码行数:15,代码来源:wuibase.py


注:本文中的testmanager.core.base.ModelDataBase.validateTs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。