File: compat.py

package info (click to toggle)
python-furl 2.1.4-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 444 kB
  • sloc: python: 2,974; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 768 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
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-

#
# furl - URL manipulation made simple.
#
# Ansgar Grunseid
# grunseid.com
# grunseid@gmail.com
#
# License: Build Amazing Things (Unlicense)
#

import sys


if sys.version_info[0] == 2:
    string_types = basestring  # noqa
else:
    string_types = (str, bytes)


if list(sys.version_info[:2]) >= [2, 7]:
    from collections import OrderedDict  # noqa
else:
    from ordereddict import OrderedDict  # noqa


class UnicodeMixin(object):
    """
    Mixin that defines proper __str__/__unicode__ methods in Python 2 or 3.
    """
    if sys.version_info[0] >= 3:  # Python 3
        def __str__(self):
            return self.__unicode__()
    else:  # Python 2
        def __str__(self):
            return self.__unicode__().encode('utf8')