~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to serialize_transform.py

  • Committer: Aaron Bentley
  • Date: 2008-10-05 00:21:03 UTC
  • mto: (0.15.1 unshelve)
  • mto: This revision was merged to the branch mainline in revision 3820.
  • Revision ID: aaron@aaronbentley.com-20081005002103-cw64p67k347v7oo2
Initial bencode-based encoding

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib.util import bencode
 
2
 
 
3
 
 
4
def serialize(tt):
 
5
    new_name = dict((k, v.encode('utf-8')) for k, v in tt._new_name.items())
 
6
    attribs = {
 
7
        '_id_number': tt._id_number,
 
8
        '_new_name': new_name,
 
9
        '_new_id': tt._new_id,
 
10
        }
 
11
    return bencode.bencode(attribs)
 
12
 
 
13
def deserialize(tt, input):
 
14
    attribs = bencode.bdecode(input)
 
15
    tt._id_number = attribs['_id_number']
 
16
    tt._new_name = dict((k, v.decode('utf-8'))
 
17
                        for k, v in attribs['_new_name'].items())
 
18
    tt._new_id = attribs['_new_id']
 
19
    tt._r_new_id = dict((v, k) for k, v in tt._new_id.items())