__init__.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import json
  16. import time
  17. def time_msec():
  18. """
  19. Get the current time in milliseconds.
  20. :return: The current time in milliseconds.
  21. :rtype: int
  22. """
  23. return int(time.time() * 1000)
  24. def _reject_invalid_json(val):
  25. """Do not allow Infinity, -Infinity, or NaN values in JSON."""
  26. raise ValueError("Invalid JSON value: '%s'" % val)
  27. # a custom JSON decoder which will reject Python extensions to JSON.
  28. json_decoder = json.JSONDecoder(parse_constant=_reject_invalid_json)