File: compat.py

package info (click to toggle)
python-vagrant 0.5.15-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 232 kB
  • sloc: python: 1,386; makefile: 18
file content (24 lines) | stat: -rw-r--r-- 506 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
vagrant.compat
--------------

Python 2/3 compatiblity module.
"""

# std
import locale
import sys


PY2 = sys.version_info[0] == 2


def decode(value):
    """Decode binary data to text if needed (for Python 3).

    Use with the functions that return in Python 2 value of `str` type and for Python 3 encoded bytes.

    :param value: Encoded bytes for Python 3 and `str` for Python 2.
    :return: Value as a text.
    """
    return value.decode(locale.getpreferredencoding()) if not PY2 else value