0 0 1
default
Jean-Francois Pieronne - 16 months ago 2018-10-04 12:39:46
jf.pieronne@laposte.net
Add vms.starlet.IdToAsc
1 file changed with 43 insertions and 0 deletions:
↑ Collapse Diff ↑
 
new file 100644
1
 
from vms import starlet, ssdef
2
 

	
3
 

	
4
 
class IdToAsc(object):
5
 
    def __init__(self):
6
 
        self.contxt = 0
7
 
        self.iid = None
8
 

	
9
 
    def __enter__(self):
10
 
        self.contxt = 0
11
 
        self.iid = 0xFFFFFFFF  # do a wildcard lookup
12
 
        return self
13
 

	
14
 
    def __exit__(self, exc_type, exc_value, traceback):
15
 
        starlet.finish_rdb(self.contxt)
16
 

	
17
 
    def __iter__(self):
18
 
        return self
19
 

	
20
 
    def __next__(self):
21
 
        try:
22
 
            s, idname, rid, attrib, self.contxt = \
23
 
                starlet.idtoasc(self.iid, self.contxt)
24
 
            return self.uictoasc(rid) if (rid < 0x80000000L) else "%s" % idname
25
 
        except VMSError, e:
26
 
            raise StopIteration if e.errno == ssdef.SS__NOSUCHID else e
27
 
     
28
 
    def next(self):
29
 
        return self.__next__()
30
 

	
31
 
    def uictoasc(self, uic_value):
32
 
        high_word = int(uic_value / 65536)
33
 
        low_word  = int(uic_value - (high_word * 65536))
34
 
        # Note: [1:], because octal values will be preceeded by '0'
35
 
        uic_string = \
36
 
          '[' + oct(high_word)[1:] + ',' + oct(low_word)[1:]  + ']'
37
 
        return uic_string
38
 

	
39
 

	
40
 
if __name__ == '__main__':
41
 
    with IdToAsc() as iid:
42
 
        for idnam in iid:
43
 
            print idnam
0 comments (0 inline, 0 general)