Completed
Push — master ( dfbec1...7e13b1 )
by Satoru
01:08
created

to_str()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
1
#
2
# Copyright (C) 2011 - 2015 Red Hat, Inc.
3
# Copyright (C) 2011 - 2016 Satoru SATOH <ssato redhat.com>
4
# License: MIT
5
#
6
# pylint: disable=import-error,unused-import
7
"""Module to keep backward compatibilities.
8
9
- basic str types are different in python 2.x and 3.x.
10
- collections.ordereddict is not available in python 2.6.
11
"""
12
from __future__ import absolute_import
13
14
import sys
15
16
try:
17
    from collections import OrderedDict  # flake8: noqa
18
except ImportError:
19
    from ordereddict import OrderedDict  # flake8: noqa
20
21
try:
22
    from hashlib import md5
23
except ImportError:
24
    from md5 import md5
25
26
try:
27
    STR_TYPES = (basestring, unicode)  # flake8: noqa
28
except NameError:
29
    STR_TYPES = (str, )  # flake8: noqa
30
31
32
def to_str(obj):
33
    """
34
    :return: String representation of given object
35
    """
36
    return str(obj).encode("utf-8") if sys.version_info[0] == 3 else str(obj)
37
38
# vim:sw=4:ts=4:et:
39