1# Copyright 2016 Google Inc. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15""" A tiny version of `six` to help with backwards compability. """
16
17import sys
18
19PY2 = sys.version_info[0] == 2
20PY26 = sys.version_info[0:2] == (2, 6)
21PY27 = sys.version_info[0:2] == (2, 7)
22PY275 = sys.version_info[0:3] >= (2, 7, 5)
23PY3 = sys.version_info[0] == 3
24PY34 = sys.version_info[0:2] >= (3, 4)
25
26if PY3:
27    string_types = (str,)
28    binary_types = (bytes,bytearray)
29    range_func = range
30    memoryview_type = memoryview
31    struct_bool_decl = "?"
32else:
33    string_types = (unicode,)
34    if PY26 or PY27:
35        binary_types = (str,bytearray)
36    else:
37        binary_types = (str,)
38    range_func = xrange
39    if PY26 or (PY27 and not PY275):
40        memoryview_type = buffer
41        struct_bool_decl = "<b"
42    else:
43        memoryview_type = memoryview
44        struct_bool_decl = "?"
45
46# NOTE: Future Jython support may require code here (look at `six`).
47