Skip to content

Commit

Permalink
在python3部分兼容问题 (#156)
Browse files Browse the repository at this point in the history
* fix MemoryError

* 类型转换错误

* change type

* python2/3字符兼容

* python2/3字符兼容版本

* python3中文加密错误

* 自定义类成员函数处理消息时,缺少self参数

* 解决threadid不一致SQLlite写入错误

* 解决中文字符检测长度在py2/3不一致的问题

* fix bug

* revert
  • Loading branch information
weberwang authored and whtsky committed Aug 12, 2016
1 parent e18989e commit bf69b1e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions werobot/crypto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def encrypt(self, text, app_id):
"""
text = b"".join([
to_binary(self.get_random_string()),
struct.pack(b"I", socket.htonl(len(text))),
struct.pack(b"I", socket.htonl(len(to_binary(text)))),
to_binary(text),
to_binary(app_id)
])
Expand Down Expand Up @@ -125,7 +125,7 @@ def encrypt_message(self, reply, timestamp=None, nonce=None):
if hasattr(reply, "render"):
reply = reply.render()

timestamp = timestamp or int(time.time())
timestamp = timestamp or to_text(int(time.time()))
nonce = nonce or generate_token(5)
encrypt = to_text(self.prp_crypto.encrypt(reply, self.app_id))
signature = get_signature(self.token, timestamp, nonce, encrypt)
Expand Down
3 changes: 1 addition & 2 deletions werobot/session/sqlitestorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from werobot.utils import json_loads, json_dumps
import sqlite3


__CREATE_TABLE_SQL__ = """CREATE TABLE IF NOT EXISTS WeRoBot
(id TEXT PRIMARY KEY NOT NULL ,
value TEXT NOT NULL );"""
Expand All @@ -25,7 +24,7 @@ class SQLiteStorage(SessionStorage):
"""

def __init__(self, filename='werobot_session.sqlite3'):
self.db = sqlite3.connect(filename)
self.db = sqlite3.connect(filename, check_same_thread=False)
self.db.text_factory = str
self.db.execute(__CREATE_TABLE_SQL__)

Expand Down

0 comments on commit bf69b1e

Please sign in to comment.