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


Python timestamp.Timestamp方法代码示例

本文整理汇总了Python中bson.timestamp.Timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python timestamp.Timestamp方法的具体用法?Python timestamp.Timestamp怎么用?Python timestamp.Timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bson.timestamp的用法示例。


在下文中一共展示了timestamp.Timestamp方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dumps

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def dumps(obj, *args, **kwargs):
    """Helper function that wraps :func:`json.dumps`.

    Recursive function that handles all BSON types including
    :class:`~bson.binary.Binary` and :class:`~bson.code.Code`.

    :Parameters:
      - `json_options`: A :class:`JSONOptions` instance used to modify the
        encoding of MongoDB Extended JSON types. Defaults to
        :const:`DEFAULT_JSON_OPTIONS`.

    .. versionchanged:: 3.4
       Accepts optional parameter `json_options`. See :class:`JSONOptions`.

    .. versionchanged:: 2.7
       Preserves order when rendering SON, Timestamp, Code, Binary, and DBRef
       instances.
    """
    json_options = kwargs.pop("json_options", DEFAULT_JSON_OPTIONS)
    return json.dumps(_json_convert(obj, json_options), *args, **kwargs) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:json_util.py

示例2: get_consistent_end_ts

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def get_consistent_end_ts(self):
        end_ts     = None
        bkp_end_ts = self.get_backup_end_max_ts()
        for shard in self.tailed_oplogs:
            instance = self.tailed_oplogs[shard]
            if 'last_ts' in instance and instance['last_ts'] is not None:
                last_ts = instance['last_ts']
                if end_ts is None or last_ts < end_ts:
                    end_ts = last_ts
                    if last_ts < bkp_end_ts:
                        end_ts = bkp_end_ts
        if end_ts is None:
            # Happens when there were _no_ oplog changes since the backup
            # end, i. e. when all tailed-oplogs are empty
            end_ts = bkp_end_ts
        return Timestamp(end_ts.time + 1, 0) 
开发者ID:Percona-Lab,项目名称:mongodb_consistent_backup,代码行数:18,代码来源:Resolver.py

示例3: _get_timestamp

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def _get_timestamp(
        data, position, as_class, tz_aware, uuid_subtype, compile_re):
    inc, position = _get_int(data, position, unsigned=True)
    timestamp, position = _get_int(data, position, unsigned=True)
    return Timestamp(timestamp, inc), position 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:__init__.py

示例4: dumps

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def dumps(obj, *args, **kwargs):
    """Helper function that wraps :class:`json.dumps`.

    Recursive function that handles all BSON types including
    :class:`~bson.binary.Binary` and :class:`~bson.code.Code`.

    .. versionchanged:: 2.7
       Preserves order when rendering SON, Timestamp, Code, Binary, and DBRef
       instances. (But not in Python 2.4.)
    """
    if not json_lib:
        raise Exception("No json library available")
    return json.dumps(_json_convert(obj), *args, **kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:json_util.py

示例5: advance_cluster_time

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def advance_cluster_time(self, cluster_time):
        """Update the cluster time for this session.

        :Parameters:
          - `cluster_time`: The
            :data:`~pymongo.client_session.ClientSession.cluster_time` from
            another `ClientSession` instance.
        """
        if not isinstance(cluster_time, abc.Mapping):
            raise TypeError(
                "cluster_time must be a subclass of collections.Mapping")
        if not isinstance(cluster_time.get("clusterTime"), Timestamp):
            raise ValueError("Invalid cluster_time")
        self._advance_cluster_time(cluster_time) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:16,代码来源:client_session.py

示例6: advance_operation_time

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def advance_operation_time(self, operation_time):
        """Update the operation time for this session.

        :Parameters:
          - `operation_time`: The
            :data:`~pymongo.client_session.ClientSession.operation_time` from
            another `ClientSession` instance.
        """
        if not isinstance(operation_time, Timestamp):
            raise TypeError("operation_time must be an instance "
                            "of bson.timestamp.Timestamp")
        self._advance_operation_time(operation_time) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:14,代码来源:client_session.py

示例7: _get_timestamp

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def _get_timestamp(data, position, dummy0, dummy1, dummy2):
    """Decode a BSON timestamp to bson.timestamp.Timestamp."""
    end = position + 8
    inc, timestamp = _UNPACK_TIMESTAMP(data[position:end])
    return Timestamp(timestamp, inc), end 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:__init__.py

示例8: _encode_timestamp

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def _encode_timestamp(name, value, dummy0, dummy1):
    """Encode bson.timestamp.Timestamp."""
    return b"\x11" + name + _PACK_TIMESTAMP(value.inc, value.time) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:__init__.py

示例9: stop

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def stop(self, kill=False, sleep_secs=3):
        if not self.enabled():
            return
        logging.info("Stopping all oplog tailers")
        for shard in self.shards:
            replset = self.replsets[shard]
            state   = self.shards[shard]['state']
            thread  = self.shards[shard]['thread']

            try:
                uri = MongoUri(state.get('uri'))
            except Exception, e:
                raise OperationError(e)

            if not kill:
                # get current optime of replset primary to use a stop position
                try:
                    timestamp = replset.primary_optime(True, True)
                except Exception:
                    logging.warning("Could not get current optime from PRIMARY! Using now as a stop time")
                    timestamp = Timestamp(int(time()), 0)

                # wait for replication to get in sync
                while state.get('last_ts') and state.get('last_ts') < timestamp:
                    logging.info('Waiting for %s tailer to reach ts: %s, currrent: %s' % (uri, timestamp, state.get('last_ts')))
                    sleep(sleep_secs)

            # set thread stop event
            self.shards[shard]['stop'].set()
            if kill:
                thread.terminate()
            sleep(1)

            # wait for thread to stop
            while thread.is_alive():
                logging.info('Waiting for tailer %s to stop' % uri)
                sleep(sleep_secs)

            # gather state info
            self._summary[shard] = state.get().copy() 
开发者ID:Percona-Lab,项目名称:mongodb_consistent_backup,代码行数:42,代码来源:Tailer.py

示例10: dumps

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def dumps(obj, *args, **kwargs):
    """Helper function that wraps :class:`json.dumps`.

    Recursive function that handles all BSON types including
    :class:`~bson.binary.Binary` and :class:`~bson.code.Code`.

    .. versionchanged:: 2.7
       Preserves order when rendering SON, Timestamp, Code, Binary, and DBRef
       instances.
    """
    return json.dumps(_json_convert(obj), *args, **kwargs) 
开发者ID:leancloud,项目名称:satori,代码行数:13,代码来源:json_util.py

示例11: _get_timestamp

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def _get_timestamp(data, view, position, dummy0, dummy1, dummy2):
    """Decode a BSON timestamp to bson.timestamp.Timestamp."""
    inc, timestamp = _UNPACK_TIMESTAMP_FROM(data, position)
    return Timestamp(timestamp, inc), position + 8 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:6,代码来源:__init__.py

示例12: test_timestamp

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def test_timestamp(self):
        dct = {"ts": Timestamp(4, 13)}
        res = bsonjs_dumps(dct)
        self.assertEqual('{ "ts" : { "$timestamp" : { "t" : 4, "i" : 13 } } }',
                         res)

        rtdct = bsonjs_loads(res)
        self.assertEqual(dct, rtdct) 
开发者ID:mongodb-labs,项目名称:python-bsonjs,代码行数:10,代码来源:test_bsonjs.py

示例13: default

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def default(obj):
    # We preserve key order when rendering SON, DBRef, etc. as JSON by
    # returning a SON for those types instead of a dict. This works with
    # the "json" standard library in Python 2.6+ and with simplejson
    # 2.1.0+ in Python 2.5+, because those libraries iterate the SON
    # using PyIter_Next. Python 2.4 must use simplejson 2.0.9 or older,
    # and those versions of simplejson use the lower-level PyDict_Next,
    # which bypasses SON's order-preserving iteration, so we lose key
    # order in Python 2.4.
    if isinstance(obj, ObjectId):
        return {"$oid": str(obj)}
    if isinstance(obj, DBRef):
        return _json_convert(obj.as_doc())
    if isinstance(obj, datetime.datetime):
        # TODO share this code w/ bson.py?
        if obj.utcoffset() is not None:
            obj = obj - obj.utcoffset()
        millis = int(calendar.timegm(obj.timetuple()) * 1000 +
                     obj.microsecond / 1000)
        return {"$date": millis}
    if isinstance(obj, (RE_TYPE, Regex)):
        flags = ""
        if obj.flags & re.IGNORECASE:
            flags += "i"
        if obj.flags & re.LOCALE:
            flags += "l"
        if obj.flags & re.MULTILINE:
            flags += "m"
        if obj.flags & re.DOTALL:
            flags += "s"
        if obj.flags & re.UNICODE:
            flags += "u"
        if obj.flags & re.VERBOSE:
            flags += "x"
        if isinstance(obj.pattern, str):
            pattern = obj.pattern
        else:
            pattern = obj.pattern.decode('utf-8')
        return SON([("$regex", pattern), ("$options", flags)])
    if isinstance(obj, MinKey):
        return {"$minKey": 1}
    if isinstance(obj, MaxKey):
        return {"$maxKey": 1}
    if isinstance(obj, Timestamp):
        return {"$timestamp": SON([("t", obj.time), ("i", obj.inc)])}
    if isinstance(obj, Code):
        return SON([('$code', str(obj)), ('$scope', obj.scope)])
    if isinstance(obj, Binary):
        return SON([
            ('$binary', base64.b64encode(obj).decode()),
            ('$type', "%02x" % obj.subtype)])
    if PY3 and isinstance(obj, binary_type):
        return SON([
            ('$binary', base64.b64encode(obj).decode()),
            ('$type', "00")])
    if bson.has_uuid() and isinstance(obj, bson.uuid.UUID):
        return {"$uuid": obj.hex}
    raise TypeError("%r is not JSON serializable" % obj) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:60,代码来源:json_util.py

示例14: default

# 需要导入模块: from bson import timestamp [as 别名]
# 或者: from bson.timestamp import Timestamp [as 别名]
def default(obj):
    # We preserve key order when rendering SON, DBRef, etc. as JSON by
    # returning a SON for those types instead of a dict.
    if isinstance(obj, ObjectId):
        return {"$oid": str(obj)}
    if isinstance(obj, DBRef):
        return _json_convert(obj.as_doc())
    if isinstance(obj, datetime.datetime):
        # TODO share this code w/ bson.py?
        if obj.utcoffset() is not None:
            obj = obj - obj.utcoffset()
        millis = int(calendar.timegm(obj.timetuple()) * 1000 +
                     obj.microsecond / 1000)
        return {"$date": millis}
    if isinstance(obj, (RE_TYPE, Regex)):
        flags = ""
        if obj.flags & re.IGNORECASE:
            flags += "i"
        if obj.flags & re.LOCALE:
            flags += "l"
        if obj.flags & re.MULTILINE:
            flags += "m"
        if obj.flags & re.DOTALL:
            flags += "s"
        if obj.flags & re.UNICODE:
            flags += "u"
        if obj.flags & re.VERBOSE:
            flags += "x"
        if isinstance(obj.pattern, text_type):
            pattern = obj.pattern
        else:
            pattern = obj.pattern.decode('utf-8')
        return SON([("$regex", pattern), ("$options", flags)])
    if isinstance(obj, MinKey):
        return {"$minKey": 1}
    if isinstance(obj, MaxKey):
        return {"$maxKey": 1}
    if isinstance(obj, Timestamp):
        return {"$timestamp": SON([("t", obj.time), ("i", obj.inc)])}
    if isinstance(obj, Code):
        return SON([('$code', str(obj)), ('$scope', obj.scope)])
    if isinstance(obj, Binary):
        return SON([
            ('$binary', base64.b64encode(obj).decode()),
            ('$type', "%02x" % obj.subtype)])
    if PY3 and isinstance(obj, bytes):
        return SON([
            ('$binary', base64.b64encode(obj).decode()),
            ('$type', "00")])
    if isinstance(obj, uuid.UUID):
        return {"$uuid": obj.hex}
    raise TypeError("%r is not JSON serializable" % obj) 
开发者ID:leancloud,项目名称:satori,代码行数:54,代码来源:json_util.py


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