Skip to content

Commit 1c38747

Browse files
committed
Add support for Python2
Change-Id: I81ef1e3cc2e2b23a86aa2acbc3b6f292224e3140
1 parent 3d30a7a commit 1c38747

31 files changed

+207
-11
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
itchat==1.2.32
22
requests
3+
future

wxpy/__compat__.py

Whitespace-only changes.

wxpy/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding: utf-8
2+
13
from .utils import shell_entry
24

35
if __name__ == '__main__':

wxpy/api/bot.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# coding: utf-8
2+
from __future__ import unicode_literals
3+
14
import atexit
25
import functools
36
import logging
@@ -15,9 +18,13 @@
1518
from ..utils import PuidMap
1619
from ..utils import enhance_connection, enhance_webwx_request, ensure_list, get_user_name, handle_response, \
1720
start_new_thread, wrap_user_name
21+
from ..compatible import *
1822

1923
logger = logging.getLogger(__name__)
2024

25+
if PY2:
26+
from future.builtins import str
27+
2128

2229
class Bot(object):
2330
"""
@@ -86,13 +93,18 @@ def __init__(
8693

8794
self.is_listening = False
8895
self.listening_thread = None
89-
90-
self.temp_dir = tempfile.TemporaryDirectory(prefix='wxpy_')
96+
if PY2:
97+
from wxpy.compatible.utils import TemporaryDirectory
98+
self.temp_dir = TemporaryDirectory(prefix='wxpy_')
99+
else:
100+
self.temp_dir = tempfile.TemporaryDirectory(prefix='wxpy_')
91101
self.start()
92102

93103
atexit.register(self._cleanup)
94104

95105
def __repr__(self):
106+
if PY2:
107+
return '<{}: {}>'.format(unicode(self.__class__.__name__), unicode(self.self.name))
96108
return '<{}: {}>'.format(self.__class__.__name__, self.self.name)
97109

98110
@handle_response()

wxpy/api/chats/chat.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import datetime
1+
# coding: utf-8
22
import logging
33
import re
44
import time
5+
import datetime
56
from functools import partial, wraps
67

78
from wxpy.api.consts import ATTACHMENT, PICTURE, TEXT, VIDEO
89
from wxpy.utils import handle_response
910

1011
logger = logging.getLogger(__name__)
1112

13+
from ...compatible import *
14+
1215

1316
def wrap_sender(msg_type):
1417
"""

wxpy/api/chats/chats.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# coding: utf-8
2+
13
import logging
24
import time
35
from collections import Counter
46

57
from wxpy.utils import match_attributes, match_name
8+
from wxpy.compatible import *
69

710
logger = logging.getLogger(__name__)
811

wxpy/api/chats/friend.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding: utf-8
2+
13
import logging
24

35
from wxpy.utils import handle_response

wxpy/api/chats/group.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding: utf-8
2+
13
import logging
24

35
from wxpy.utils import ensure_list, get_user_name, handle_response, wrap_user_name

wxpy/api/chats/groups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding: utf-8
2+
13
from wxpy.utils import ensure_list, match_attributes, match_name
24
from .user import User
35

wxpy/api/chats/member.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding: utf-8
2+
13
from .user import User
24

35

0 commit comments

Comments
 (0)