コード例 #1
0
ファイル: utils.py プロジェクト: scottwedge/n6
 def _prepare_single_raw_value(val):
     if isinstance(val, basestring):
         return val
     if isinstance(val, (bool, int, long, float)):
         return str(val)
     if isinstance(val, datetime.datetime):
         return str(datetime_utc_normalize(val))
     raise TypeError('unsupported class {} of parameter value {!r}'.format(
         ascii_str(val.__class__.__name__), val))
コード例 #2
0
 def _prepare_single_raw_value(val):
     if isinstance(val, str):
         return val
     if isinstance(val, (bytes, bytearray)):
         return val.decode('utf-8')
     if isinstance(val, (bool, int, float)):
         return str(val)
     if isinstance(val, datetime.datetime):
         return str(datetime_utc_normalize(val))
     raise TypeError('unsupported class {} of parameter value {!a}'.format(
         ascii_str(val.__class__.__name__), val))
コード例 #3
0
    def clean_result_value(self, value):
        """
        The input `value` should be a :class:`str`/:class:`unicode` string
        (*ISO-8601*-formatted) or a :class:`datetime.datetime` object
        (timezone-aware or *naive*).

        Returns: a :class:`datetime.datetime` object (a *naive* one,
        i.e. not aware of any timezone).
        """
        value = super(DateTimeField, self).clean_result_value(value)
        if isinstance(value, datetime.datetime):
            return datetime_utc_normalize(value)
        if isinstance(value, basestring):
            return self._parse_datetime_string(value)
        raise TypeError('{!r} is neither a str/unicode nor a '
                        'datetime.datetime object'.format(value))
コード例 #4
0
ファイル: fields.py プロジェクト: CERT-Polska/n6sdk
    def clean_result_value(self, value):
        """
        The input `value` should be a :class:`str`/:class:`unicode` string
        (*ISO-8601*-formatted) or a :class:`datetime.datetime` object
        (timezone-aware or *naive*).

        Returns: a :class:`datetime.datetime` object (a *naive* one,
        i.e. not aware of any timezone).
        """
        value = super(DateTimeField, self).clean_result_value(value)
        if isinstance(value, datetime.datetime):
            return datetime_utc_normalize(value)
        if isinstance(value, basestring):
            return self._parse_datetime_string(value)
        raise TypeError(
            '{!r} is neither a str/unicode nor a '
            'datetime.datetime object'.format(value))
コード例 #5
0
    def clean_result_value(self, value):
        """
        The input `value` should be a :class:`str` (*ISO-8601*-formatted)
        or a :class:`bytes`/:class:`bytearray` (*ISO-8601*-formatted), or
        a :class:`datetime.datetime` object (timezone-aware or *naive*).

        Returns: a :class:`datetime.datetime` object (a *naive* one,
        i.e. not aware of any timezone).
        """
        value = super(DateTimeField, self).clean_result_value(value)
        if isinstance(value, datetime.datetime):
            return datetime_utc_normalize(value)
        if isinstance(value, (bytes, bytearray)):
            value = value.decode('utf-8', 'replace')
        if isinstance(value, (str, unicode)):  #3: `unicode`--
            return self._parse_datetime_string(value)
        raise TypeError('{!r} is neither a str/bytes/bytearray nor a '
                        'datetime.datetime object'.format(value))
コード例 #6
0
ファイル: _pyramid_commons.py プロジェクト: CERT-Polska/n6
 def _datetime_to_str(self, dt):
     return datetime_utc_normalize(dt).isoformat() + "Z"