當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。