~ubuntu-branches/ubuntu/saucy/solfege/saucy

« back to all changes in this revision

Viewing changes to tools/unpickle.py

  • Committer: Bazaar Package Importer
  • Author(s): Tom Cato Amundsen
  • Date: 2010-03-28 06:34:28 UTC
  • mfrom: (1.1.10 upstream) (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100328063428-wg2bqvoce2aq4xfb
Tags: 3.15.9-1
* New upstream release.
* Redo packaging. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import pickle
4
4
import pprint
5
5
import sys
 
6
try:
 
7
    from cStringIO import StringIO
 
8
except ImportError:
 
9
    from StringIO import StringIO
 
10
 
 
11
renametable = {
 
12
    'src.dataparser': 'solfege.dataparser',
 
13
    }
 
14
 
 
15
def mapname(name):
 
16
    if name in renametable:
 
17
        return renametable[name]
 
18
    return name
 
19
 
 
20
def mapped_load_global(self):
 
21
    module = mapname(self.readline()[:-1])
 
22
    name = mapname(self.readline()[:-1])
 
23
    klass = self.find_class(module, name)
 
24
    self.append(klass)
 
25
 
 
26
def loads(file):
 
27
    unpickler = pickle.Unpickler(file)
 
28
    unpickler.dispatch[pickle.GLOBAL] = mapped_load_global
 
29
    return unpickler.load() 
6
30
 
7
31
print sys.argv
8
32
f = file(sys.argv[1], 'r')
9
 
d = pickle.load(f)
 
33
d = loads(f)
10
34
f.close()
11
35
pprint.pprint(d)