forked from python-openxml/python-docx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompat.py
More file actions
50 lines (39 loc) · 1.29 KB
/
compat.py
File metadata and controls
50 lines (39 loc) · 1.29 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
# encoding: utf-8
"""
Provides Python 2/3 compatibility objects
"""
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import sys
# ===========================================================================
# Python 3 versions
# ===========================================================================
if sys.version_info >= (3, 0):
def cls_method_fn(cls, method_name):
"""
Return the function object associated with the method of *cls* having
*method_name*.
"""
return getattr(cls, method_name)
def is_string(obj):
"""
Return True if *obj* is a string, False otherwise.
"""
return isinstance(obj, str)
# ===========================================================================
# Python 2 versions
# ===========================================================================
else:
def cls_method_fn(cls, method_name):
"""
Return the function object associated with the method of *cls* having
*method_name*.
"""
unbound_method = getattr(cls, method_name)
return unbound_method.__func__
def is_string(obj):
"""
Return True if *obj* is a string, False otherwise.
"""
return isinstance(obj, basestring)