Boringlamb's cnblog - Just like a Taurus!

Yesterday is History. Tomorrow is a Mystery, and Today is a gift. That's why we call it the Present.

导航

对 resPickle 的改进

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

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