对 resPickle 的改进
resPickle容易出现编码问题,所以进行了修正
1
from System import Convert
2
from System.IO import MemoryStream
3
from System.Runtime.Serialization.Formatters.Binary import BinaryFormatter
4
import copy_reg
5![]()
6
_formatter = BinaryFormatter()
7![]()
8
def _unpickler(string):
9
bytes = Convert.FromBase64String(string)
10
stream = MemoryStream(bytes)
11
return _formatter.Deserialize(stream)
12![]()
13
def _pickler(obj):
14
stream = MemoryStream()
15
_formatter.Serialize(stream, obj)
16
bytes = stream.ToArray()
17
string = Convert.ToBase64String(bytes)
18
return _unpickler, (string,)
19![]()
20
def Register(type):
21
copy_reg.pickle(type, _pickler, _unpickler)

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

posted on 2007-11-08 10:34 Boringlamb 阅读(228) 评论(0) 收藏 举报