當前位置: 首頁>>代碼示例>>Python>>正文


Python isodate.duration_isoformat方法代碼示例

本文整理匯總了Python中isodate.duration_isoformat方法的典型用法代碼示例。如果您正苦於以下問題:Python isodate.duration_isoformat方法的具體用法?Python isodate.duration_isoformat怎麽用?Python isodate.duration_isoformat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在isodate的用法示例。


在下文中一共展示了isodate.duration_isoformat方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: default

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def default(self, obj):

        if isinstance(obj, decimal.Decimal):
            return {'type{decimal}': str(obj)}
        elif isinstance(obj, datetime.time):
            return {'type{time}': obj.strftime(TIME_FORMAT)}
        elif isinstance(obj, datetime.datetime):
            return {'type{datetime}':
                    (obj.strftime(DATETIME_FORMAT),
                     obj.utcoffset().seconds if obj.utcoffset() is not None else None,
                     obj.tzname())}
        elif isinstance(obj, datetime.date):
            return {'type{date}': obj.strftime(DATE_FORMAT)}
        elif isinstance(obj, (isodate.Duration, datetime.timedelta)):
            return {'type{duration}': isodate.duration_isoformat(obj)}
        elif isinstance(obj, set):
            return {'type{set}': list(obj)}
        return super().default(obj) 
開發者ID:datahq,項目名稱:dataflows,代碼行數:20,代碼來源:extended_json.py

示例2: default

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def default(self, obj):

        if isinstance(obj, decimal.Decimal):
            return {'type{decimal}': str(obj)}
        elif isinstance(obj, datetime.time):
            return {'type{time}': obj.strftime(TIME_FORMAT)}
        elif isinstance(obj, datetime.datetime):
            return {'type{datetime}': obj.strftime(DATETIME_FORMAT)}
        elif isinstance(obj, datetime.date):
            return {'type{date}': obj.strftime(DATE_FORMAT)}
        elif isinstance(obj, (isodate.Duration, datetime.timedelta)):
            return {'type{duration}': isodate.duration_isoformat(obj)}
        elif isinstance(obj, set):
            return {'type{set}': list(obj)}
        elif isinstance(obj, LazyDict):
            return obj.inner
        return super().default(obj) 
開發者ID:frictionlessdata,項目名稱:datapackage-pipelines,代碼行數:19,代碼來源:extended_json.py

示例3: fail

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def fail(self, error_message="", capture_exception=True):
        """
        Send a message to the controller that this message failed to process
        """
        self.controller_queue.send_json({
            'ramp_unique_id': self.ramp_unique_id,
            'ack_value': -1,
            'content': {
                'process_name': self.process_name,
                'msg_type': 'fail',
                'duration': duration_isoformat(datetime.datetime.now() - self.init_time),
                'message_content': self.content
            },
            'producer_uuid': self.producer_uuid,
            'destination_uuid': self.producer_uuid,
            'error_message': error_message if not capture_exception else traceback.format_exc(),
        }) 
開發者ID:plecto,項目名稱:motorway,代碼行數:19,代碼來源:messages.py

示例4: process

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def process(
        obj,
        fallback_processor: Optional[
            Callable[..., Serializable]
        ]=_DEFAULT_FALLBACK_PROCESSOR,
) -> Serializable:
    if isinstance(obj, timedelta):
        return isodate.duration_isoformat(obj)

    if isinstance(obj, pendulum.Pendulum):
        return obj.isoformat()

    if fallback_processor is not None:
        return fallback_processor(obj)

    raise TypeError(
        f'Cannot process object of type {type(obj)}, no fallback_processor '
        f'provided'
    ) 
開發者ID:miracle2k,項目名稱:k8s-snapshots,代碼行數:21,代碼來源:serialize.py

示例5: to_representation

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def to_representation(self, obj):
        if obj:
            d = Duration(milliseconds=obj)
            return duration_isoformat(d)
        else:
            return None 
開發者ID:City-of-Helsinki,項目名稱:linkedevents,代碼行數:8,代碼來源:api.py

示例6: timedelta_as_iso8601

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def timedelta_as_iso8601(timedelta):
    return isodate.duration_isoformat(timedelta) 
開發者ID:perfsonar,項目名稱:pscheduler,代碼行數:4,代碼來源:iso8601.py

示例7: serialize_duration

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def serialize_duration(attr, **kwargs):
        """Serialize TimeDelta object into ISO-8601 formatted string.

        :param TimeDelta attr: Object to be serialized.
        :rtype: str
        """
        if isinstance(attr, str):
            attr = isodate.parse_duration(attr)
        return isodate.duration_isoformat(attr) 
開發者ID:Azure,項目名稱:msrest-for-python,代碼行數:11,代碼來源:serialization.py

示例8: default

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def default(self, o):
        if type(o) == datetime.timedelta:
            return duration_isoformat(o)
        elif type(o) == datetime.datetime:
            return datetime_isoformat(o)
        elif isinstance(o, decimal.Decimal):
            return float(o)
        return super(DateTimeAwareJsonEncoder, self).default(o) 
開發者ID:plecto,項目名稱:motorway,代碼行數:10,代碼來源:utils.py

示例9: send_control_message

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def send_control_message(self, controller_queue, time_consumed=None, process_name=None, destination_endpoint=None,
                             destination_uuid=None, sender=None):
        """
        Control messages are notifications that a new message have been created, so the controller can keep track of
        this particular message and let the ramp know once the entire tree of messages has been completed.

        This is called implicitly on yield Message(_id, 'message')

        :param process_name: UUID of the process processing this message (as string)
        """
        content = {
            'process_name': process_name,
            'msg_type': 'new_msg',
        }
        if not self.producer_uuid:
            raise Exception("Cannot send control message without producer UUID")
        if time_consumed:
            # Ramps provide time consumed, since we don't know the "start time" like in a intersection
            # where it's clear when the message is received and later 'acked' as the last action
            content['duration'] = duration_isoformat(time_consumed)
            content['sender'] = sender
        controller_queue.send_json({
            'ramp_unique_id': self.ramp_unique_id,
            'ack_value': self.ack_value,
            'content': content,
            'producer_uuid': self.producer_uuid,
            'destination_endpoint': destination_endpoint,
            'destination_uuid': destination_uuid
        }) 
開發者ID:plecto,項目名稱:motorway,代碼行數:31,代碼來源:messages.py

示例10: ack

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def ack(self, time_consumed=None):
        """
        Send a message to the controller that this message was properly processed
        """
        self.controller_queue.send_json({
            'ramp_unique_id': self.ramp_unique_id,
            'ack_value': self.ack_value,
            'content': {
                'process_name': self.process_name,
                'msg_type': 'ack',
                'duration': duration_isoformat(time_consumed or (datetime.datetime.now() - self.init_time))
            },
            'producer_uuid': self.producer_uuid,
            'destination_uuid': self.producer_uuid
        }) 
開發者ID:plecto,項目名稱:motorway,代碼行數:17,代碼來源:messages.py

示例11: serialize_deltas

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def serialize_deltas(deltas: Iterable[timedelta]) -> str:
    delta_strs = [
        isodate.duration_isoformat(delta)
        for delta in deltas
    ]
    return ' '.join(delta_strs) 
開發者ID:miracle2k,項目名稱:k8s-snapshots,代碼行數:8,代碼來源:rule.py

示例12: isoduration

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def isoduration(v):
  return isodate.duration_isoformat(v) 
開發者ID:indietyp,項目名稱:hawthorne,代碼行數:4,代碼來源:utils.py

示例13: set

# 需要導入模塊: import isodate [as 別名]
# 或者: from isodate import duration_isoformat [as 別名]
def set(self, key: str, item: typing.Any, convert=True) -> None:
        if not convert:
            return self.__setitem__(key, item)

        if key in self.colors:
            try:
                hex_ = str(item)
                if hex_.startswith("#"):
                    hex_ = hex_[1:]
                if len(hex_) == 3:
                    hex_ = "".join(s for s in hex_ for _ in range(2))
                if len(hex_) != 6:
                    raise InvalidConfigError("Invalid color name or hex.")
                try:
                    int(hex_, 16)
                except ValueError:
                    raise InvalidConfigError("Invalid color name or hex.")

            except InvalidConfigError:
                name = str(item).lower()
                name = re.sub(r"[\-+|. ]+", " ", name)
                hex_ = ALL_COLORS.get(name)
                if hex_ is None:
                    name = re.sub(r"[\-+|. ]+", "", name)
                    hex_ = ALL_COLORS.get(name)
                    if hex_ is None:
                        raise
            return self.__setitem__(key, "#" + hex_)

        if key in self.time_deltas:
            try:
                isodate.parse_duration(item)
            except isodate.ISO8601Error:
                try:
                    converter = UserFriendlyTimeSync()
                    time = converter.convert(None, item)
                    if time.arg:
                        raise ValueError
                except BadArgument as exc:
                    raise InvalidConfigError(*exc.args)
                except Exception as e:
                    logger.debug(e)
                    raise InvalidConfigError(
                        "Unrecognized time, please use ISO-8601 duration format "
                        'string or a simpler "human readable" time.'
                    )
                item = isodate.duration_isoformat(time.dt - converter.now)
            return self.__setitem__(key, item)

        if key in self.booleans:
            try:
                return self.__setitem__(key, strtobool(item))
            except ValueError:
                raise InvalidConfigError("Must be a yes/no value.")

        # elif key in self.special_types:
        #     if key == "status":

        return self.__setitem__(key, item) 
開發者ID:kyb3r,項目名稱:modmail,代碼行數:61,代碼來源:config.py


注:本文中的isodate.duration_isoformat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。