equal
deleted
inserted
replaced
172 """ |
172 """ |
173 return '>'+('BB'*nbparams) |
173 return '>'+('BB'*nbparams) |
174 |
174 |
175 parthandlermapping = {} |
175 parthandlermapping = {} |
176 |
176 |
177 def parthandler(parttype): |
177 def parthandler(parttype, params=()): |
178 """decorator that register a function as a bundle2 part handler |
178 """decorator that register a function as a bundle2 part handler |
179 |
179 |
180 eg:: |
180 eg:: |
181 |
181 |
182 @parthandler('myparttype') |
182 @parthandler('myparttype') |
186 """ |
186 """ |
187 def _decorator(func): |
187 def _decorator(func): |
188 lparttype = parttype.lower() # enforce lower case matching. |
188 lparttype = parttype.lower() # enforce lower case matching. |
189 assert lparttype not in parthandlermapping |
189 assert lparttype not in parthandlermapping |
190 parthandlermapping[lparttype] = func |
190 parthandlermapping[lparttype] = func |
|
191 func.params = frozenset(params) |
191 return func |
192 return func |
192 return _decorator |
193 return _decorator |
193 |
194 |
194 class unbundlerecords(object): |
195 class unbundlerecords(object): |
195 """keep record of what happens during and unbundle |
196 """keep record of what happens during and unbundle |
837 if params is not None: |
838 if params is not None: |
838 kwargs['params'] = params.split('\0') |
839 kwargs['params'] = params.split('\0') |
839 |
840 |
840 raise error.BundleValueError(**kwargs) |
841 raise error.BundleValueError(**kwargs) |
841 |
842 |
842 @parthandler('b2x:error:pushraced') |
843 @parthandler('b2x:error:pushraced', ('message',)) |
843 def handlereplycaps(op, inpart): |
844 def handlereplycaps(op, inpart): |
844 """Used to transmit push race error over the wire""" |
845 """Used to transmit push race error over the wire""" |
845 raise error.ResponseError(_('push failed:'), inpart.params['message']) |
846 raise error.ResponseError(_('push failed:'), inpart.params['message']) |