class ExtType(namedtuple("ExtType", "code data")): """ExtType represents ext type in msgpack."""
def __new__(cls, code, data): ifnot isinstance(code, int): raise TypeError("code must be int") ifnot isinstance(data, bytes): raise TypeError("data must be bytes") ifnot 0 <= code <= 127: raise ValueError("code must be 0~127") return super(ExtType, cls).__new__(cls, code, data)
class Timestamp(object): """Timestamp represents the Timestamp extension type in msgpack.
When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python
msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and unpack `Timestamp`.
This classis immutable: Do not override seconds and nanoseconds. """
__slots__ = ["seconds", "nanoseconds"]
def __init__(self, seconds, nanoseconds=0): """Initialize a Timestamp object.
:param int seconds:
Number of seconds since the UNIX epoch (00:00:00 UTC Jan 1 1970, minus leap seconds).
May be negative.
:param int nanoseconds:
Number of nanoseconds to add to `seconds` to get fractional time.
Maximum is 999_999_999. Default is 0.
Note: Negative times (before the UNIX epoch) are represented as negative seconds + positive ns. """ ifnot isinstance(seconds, int_types): raise TypeError("seconds must be an integer") ifnot isinstance(nanoseconds, int_types): raise TypeError("nanoseconds must be an integer") ifnot (0 <= nanoseconds < 10**9): raise ValueError( "nanoseconds must be a non-negative integer less than 999999999."
)
self.seconds = seconds
self.nanoseconds = nanoseconds
def __eq__(self, other): """Check for equality with another Timestamp object""" if type(other) is self.__class__: return (
self.seconds == other.seconds and self.nanoseconds == other.nanoseconds
) returnFalse
def __ne__(self, other): """not-equals method (see :func:`__eq__()`)""" returnnot self.__eq__(other)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.