fcall.py (2672B)
1 from pyxp.messages import MessageBase, Message 2 from pyxp.fields import * 3 from types import Qid, Stat 4 5 __all__ = 'Fcall', 6 7 NO_FID = 1<<32 - 1 8 MAX_WELEM = 16 9 10 class FcallBase(MessageBase): 11 idx = 99 12 def __new__(cls, name, bases, attrs): 13 new_cls = super(FcallBase, cls).__new__(cls, name, bases, attrs) 14 new_cls.type = FcallBase.idx 15 if new_cls.type > 99: 16 new_cls.types[new_cls.type] = new_cls 17 FcallBase.idx += 1 18 return new_cls 19 20 class Fcall(Message): 21 __metaclass__ = FcallBase 22 types = {} 23 24 def response(self, *args, **kwargs): 25 assert self.type % 2 == 0, "No respense type for response fcalls" 26 kwargs['tag'] = self.tag 27 return self.types[self.type + 1]() 28 29 @classmethod 30 def unmarshall(cls, data, offset=0): 31 res = super(Fcall, cls).unmarshall(data, offset) 32 if cls.type < 100: 33 res = cls.types[res[1].type].unmarshall(data, offset) 34 return res 35 36 size = Size(4, 4) 37 type = Int(1) 38 tag = Int(2) 39 40 class Tversion(Fcall): 41 msize = Int(4) 42 version = String() 43 class Rversion(Fcall): 44 msize = Int(4) 45 version = String() 46 47 class Tauth(Fcall): 48 afid = Int(4) 49 uname = String() 50 aname = String() 51 class Rauth(Fcall): 52 aqid = Qid.field() 53 54 class Tattach(Fcall): 55 fid = Int(4) 56 afid = Int(4) 57 uname = String() 58 aname = String() 59 class Rattach(Fcall): 60 qid = Qid.field() 61 62 class Terror(Fcall): 63 def __init__(self): 64 raise Exception("Illegal 9P tag 'Terror' encountered") 65 class Rerror(Fcall): 66 ename = String() 67 68 class Tflush(Fcall): 69 oldtag = Int(2) 70 class Rflush(Fcall): 71 pass 72 73 class Twalk(Fcall): 74 fid = Int(4) 75 newfid = Int(4) 76 wname = Array(2, String()) 77 class Rwalk(Fcall): 78 wqid = Array(2, Qid.field()) 79 80 class Topen(Fcall): 81 fid = Int(4) 82 mode = Int(1) 83 class Ropen(Fcall): 84 qid = Qid.field() 85 iounit = Int(4) 86 87 class Tcreate(Fcall): 88 fid = Int(4) 89 name = String() 90 perm = Int(4) 91 mode = Int(1) 92 class Rcreate(Fcall): 93 qid = Qid.field() 94 iounit = Int(4) 95 96 class Tread(Fcall): 97 fid = Int(4) 98 offset = Int(8) 99 count = Int(4) 100 class Rread(Fcall): 101 data = Data(4) 102 103 class Twrite(Fcall): 104 fid = Int(4) 105 offset = Int(8) 106 data = Data(4) 107 class Rwrite(Fcall): 108 count = Int(4) 109 110 class Tclunk(Fcall): 111 fid = Int(4) 112 class Rclunk(Fcall): 113 pass 114 115 class Tremove(Tclunk): 116 pass 117 class Rremove(Fcall): 118 pass 119 120 class Tstat(Tclunk): 121 pass 122 class Rstat(Fcall): 123 sstat = Size(2) 124 stat = Stat.field() 125 126 class Twstat(Rstat): 127 pass 128 class Rwstat(Fcall): 129 pass 130 131 # vim:se sts=4 sw=4 et: