0 1 0
default
Jean-Francois Pieronne - 4 years ago 2016-04-20 15:51:59
jf.pieronne@laposte.net
Various fixes in IndexedFile2.py
1 file changed with 48 insertions and 5 deletions:
↑ Collapse Diff ↑
...
 
@@ -10,6 +10,17 @@ from decimal import Decimal
10 10
 
from construct import *
11 11
 
from vms.vmsconstruct import *
12 12
 

	
13
 
class BCD(object):
14
 
    def __init__(self, ipart, dpart):
15
 
        self._ipart = ipart
16
 
        self._dpart = dpart
17
 
    def decode(self, val):
18
 
        return Decimal(vms.rms.BCD2Tuple(val, self._dpart))
19
 
    def pack(self, val):
20
 
        return vms.rms.Tuple2BCD(val.as_tuple(), self._ipart,
21
 
                                 self._dpart)
22
 

	
23
 

	
13 24
 
class FileNotOpened(ValueError):
14 25
 
    def __init__(self, value=None):
15 26
 
        self.value = value
...
 
@@ -34,6 +45,36 @@ class FileNotOpened(ValueError):
34 45
 
       }
35 46
 

	
36 47
 

	
48
 
class DictContainer(Container):
49
 
    def __init__(self, d):
50
 
        super(DictContainer, self).__init__(**self._build_container(d))
51
 
        
52
 
    def _build_container(self, d):
53
 
        c = Container()
54
 
        for k, v in d.iteritems():
55
 
            if isinstance(v, dict):
56
 
                c[k] = self._build_container(v)
57
 
            else:
58
 
                c[k] = v
59
 
        return c
60
 

	
61
 

	
62
 
class ListContainer(Container):
63
 
    def __init__(self, format, liste):
64
 
       if not isinstance(format, Struct):
65
 
           raise ValueError('format must be a Struct instance, not %s' % type(format))
66
 
       super(ListContainer, self).__init__(**self._build_container(format, liste))
67
 
        
68
 
    def _build_container(self, format, liste):
69
 
        c = Container()
70
 
        for n, f in enumerate(format.subcons):
71
 
            if isinstance(f, Struct):
72
 
                c[f.name] = self._build_container(f, liste[n])
73
 
            else:
74
 
                c[f.name] = liste[n]
75
 
        return c
76
 

	
77
 

	
37 78
 
class IndexedFile(object):
38 79
 
    """ create an IndexedFile handle.
39 80
 

	
...
 
@@ -93,7 +134,8 @@ class IndexedFile(object):
93 134
 
        self._auto = False
94 135
 
        self._status = None
95 136
 
        self._file = vms.rms.file(self.filename, fac=self._decode_acc(acc),
96
 
                                  shr=self._decode_shr(shr), fop=self._decode_fop(fop))
137
 
                                  shr=self._decode_shr(shr),
138
 
                                  fop=self._decode_fop(fop))
97 139
 

	
98 140
 
    def close(self):
99 141
 
        self._file.close()
...
 
@@ -142,7 +184,8 @@ class IndexedFile(object):
142 184
 
            raise StopIteration
143 185
 
        if status == RMS__OK_LIM:
144 186
 
            self._rec_exceeds = True
145
 
        return self._item_class.parse(rec)
187
 
#        return self._item_class.parse(rec)
188
 
        return rec
146 189
 

	
147 190
 
    def usekey(self, keynum):
148 191
 
        self._file.usekey(keynum)
...
 
@@ -162,9 +205,9 @@ class IndexedFile(object):
162 205
 
            f.usekey(keynum)
163 206
 
        try:
164 207
 
            keypack = self.pack_key(keynum, keyval)
165
 
            print "find:", keypack, rob, self._decode_rob(rob)
208
 
            # print "find:", len(keypack), keypack, rob, self._decode_rob(rob)
166 209
 
            s = f.find(keypack, self._decode_rob(rob))
167
 
            print "find/status:", s
210
 
            # print "find/status:", s
168 211
 
        except vms.rms.error, e:
169 212
 
            if e.errno == RMS__RNF:
170 213
 
                return False
...
 
@@ -229,7 +272,7 @@ class IndexedFile(object):
229 272
 
            raise
230 273
 
        if status % 2 == 0:
231 274
 
            return status, None
232
 
        print "fetch_next/status:", status
275
 
        # print "fetch_next/status:", status
233 276
 
        return status, item_class.parse(r)
234 277
 
    
235 278
 

	
0 comments (0 inline, 0 general)