Home | Trees | Indices | Help |
|
---|
|
1 from twisted.python.failure import Failure 2 from twisted.internet import error 3 from ldaptor.protocols.ldap import ldifprotocol 4 from ldaptor import delta, entry 5 6 WAIT_FOR_CHANGETYPE = 'WAIT_FOR_CHANGETYPE' 7 WAIT_FOR_MOD_SPEC = 'WAIT_FOR_MOD_SPEC' 8 IN_MOD_SPEC = 'IN_MOD_SPEC' 9 IN_ADD_ENTRY = 'IN_ADD_ENTRY' 10 IN_DELETE = 'IN_DELETE' 11 15 19 23 27 31 3515338 super(LDIFDelta, self).state_WAIT_FOR_DN(line) 39 if self.mode == ldifprotocol.IN_ENTRY: 40 self.mode = WAIT_FOR_CHANGETYPE4143 assert self.dn is not None, 'self.dn must be set when in entry' 44 assert self.data is not None, 'self.data must be set when in entry' 45 46 if line == '': 47 raise LDIFDeltaMissingChangeTypeError, self.dn 48 49 key, val = self._parseLine(line) 50 51 if key != 'changetype': 52 raise LDIFDeltaMissingChangeTypeError, (self.dn, key, val) 53 54 if val == 'modify': 55 self.modifications = [] 56 self.mode = WAIT_FOR_MOD_SPEC 57 elif val == 'add': 58 self.mode = IN_ADD_ENTRY 59 elif val == 'delete': 60 self.mode = IN_DELETE 61 elif val == 'modrdn' or val == 'moddn': 62 raise NotImplementedError #TODO63 64 MOD_SPEC_TO_DELTA = { 65 'add': delta.Add, 66 'delete': delta.Delete, 67 'replace': delta.Replace, 68 } 6971 if line == '': 72 # end of entry 73 self.mode = ldifprotocol.WAIT_FOR_DN 74 m = delta.ModifyOp(dn=self.dn, 75 modifications=self.modifications) 76 self.dn = None 77 self.data = None 78 self.modifications = None 79 self.gotEntry(m) 80 return 81 82 key, val = self._parseLine(line) 83 84 if key not in self.MOD_SPEC_TO_DELTA: 85 raise LDIFDeltaUnknownModificationError, \ 86 (self.dn, key) 87 88 self.mod_spec = key 89 self.mod_spec_attr = val 90 self.mod_spec_data = [] 91 self.mode = IN_MOD_SPEC9294 if line == '': 95 raise LDIFDeltaModificationMissingEndDashError 96 97 if line == '-': 98 mod = self.MOD_SPEC_TO_DELTA[self.mod_spec] 99 de = mod(self.mod_spec_attr, self.mod_spec_data) 100 self.modifications.append(de) 101 del self.mod_spec 102 del self.mod_spec_attr 103 del self.mod_spec_data 104 self.mode = WAIT_FOR_MOD_SPEC 105 return 106 107 key, val = self._parseLine(line) 108 109 if key != self.mod_spec_attr: 110 raise LDIFDeltaModificationDifferentAttributeTypeError, \ 111 (key, self.mod_spec_attr) 112 113 self.mod_spec_data.append(val)114116 assert self.dn is not None, 'self.dn must be set when in entry' 117 assert self.data is not None, 'self.data must be set when in entry' 118 119 if line == '': 120 # end of entry 121 if not self.data: 122 raise LDIFDeltaAddMissingAttributesError, \ 123 self.dn 124 self.mode = ldifprotocol.WAIT_FOR_DN 125 o = delta.AddOp(entry.BaseLDAPEntry(dn=self.dn, 126 attributes=self.data)) 127 self.dn = None 128 self.data = None 129 self.gotEntry(o) 130 return 131 132 key, val = self._parseLine(line) 133 134 if not key in self.data: 135 self.data[key] = [] 136 137 self.data[key].append(val)138140 assert self.dn is not None, 'self.dn must be set when in entry' 141 142 if line == '': 143 # end of entry 144 self.mode = ldifprotocol.WAIT_FOR_DN 145 o = delta.DeleteOp(dn=self.dn) 146 self.dn = None 147 self.data = None 148 self.gotEntry(o) 149 return 150 151 raise LDIFDeltaDeleteHasJunkAfterChangeTypeError, \ 152 (self.dn, line)155 """Read LDIF data from a file.""" 156 157 p = LDIFDelta() 158 l = [] 159 p.gotEntry = l.append 160 while 1: 161 data = f.read() 162 if not data: 163 break 164 p.dataReceived(data) 165 p.connectionLost(Failure(error.ConnectionDone())) 166 167 return l168
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue May 15 09:31:51 2012 | http://epydoc.sourceforge.net |