1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# 5# Copyright 2017, Data61 6# Commonwealth Scientific and Industrial Research Organisation (CSIRO) 7# ABN 41 687 119 230. 8# 9# This software may be distributed and modified according to the terms of 10# the BSD 2-Clause license. Note that NO WARRANTY is provided. 11# See "LICENSE_BSD2.txt" for details. 12# 13# @TAG(DATA61_BSD) 14# 15 16''' 17Because sometimes six just isn't enough. 18 19Various shims to provide a consistent environment between Python 2 and Python 203. Note, this is a home for things *not* already provided by `six`. 21''' 22 23# These imports are relevant for compatibility, but need to be included 24# per-file as they meddle with Python's internal parser. 25from __future__ import absolute_import, division, print_function, \ 26 unicode_literals 27 28import itertools 29 30# Python 3 does not have the `cmp` function, but it can be defined as follow. 31def cmp(a, b): 32 return (a > b) - (a < b) 33 34# In Python 2, `filter`, `map` and `zip` return lists, whereas in Python 3 they 35# return iterators. Try to force the Python 3 semantics. 36 37try: 38 from future_builtins import filter 39except ImportError: 40 try: 41 from itertools import ifilter as filter 42 except ImportError: 43 filter = filter 44 45try: 46 from future_builtins import map 47except ImportError: 48 try: 49 from itertools import imap as map 50 except ImportError: 51 map = map 52 53try: 54 from future_builtins import zip 55except ImportError: 56 try: 57 from itertools import izip as zip 58 except ImportError: 59 zip = zip 60