本文整理汇总了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)
示例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)
示例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(),
})
示例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'
)
示例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
示例6: timedelta_as_iso8601
# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import duration_isoformat [as 别名]
def timedelta_as_iso8601(timedelta):
return isodate.duration_isoformat(timedelta)
示例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)
示例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)
示例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
})
示例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
})
示例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)
示例12: isoduration
# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import duration_isoformat [as 别名]
def isoduration(v):
return isodate.duration_isoformat(v)
示例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)