Beispiel #1
0
def _processpart(op, part):
    """process a single part from a bundle

    The part is guaranteed to have been fully consumed when the function exits
    (even if an exception is raised)."""
    try:
        parttype = part.type
        # part key are matched lower case
        key = parttype.lower()
        try:
            handler = parthandlermapping.get(key)
            if handler is None:
                raise error.UnsupportedPartError(parttype=key)
            op.ui.debug('found a handler for part %r\n' % parttype)
            unknownparams = part.mandatorykeys - handler.params
            if unknownparams:
                unknownparams = list(unknownparams)
                unknownparams.sort()
                raise error.UnsupportedPartError(parttype=key,
                                                 params=unknownparams)
        except error.UnsupportedPartError, exc:
            if key != parttype:  # mandatory parts
                raise
            op.ui.debug('ignoring unsupported advisory part %s\n' % exc)
            return  # skip to part processing

        # handler is called outside the above try block so that we don't
        # risk catching KeyErrors from anything other than the
        # parthandlermapping lookup (any KeyError raised by handler()
        # itself represents a defect of a different variety).
        output = None
        if op.reply is not None:
            op.ui.pushbuffer(error=True)
            output = ''
        try:
            handler(op, part)
        finally:
            if output is not None:
                output = op.ui.popbuffer()
        if output:
            outpart = op.reply.newpart('b2x:output', data=output)
            outpart.addparam('in-reply-to', str(part.id), mandatory=False)
Beispiel #2
0
def handlereplycaps(op, inpart):
    """Used to transmit unknown content error over the wire"""
    kwargs = {}
    parttype = inpart.params.get('parttype')
    if parttype is not None:
        kwargs['parttype'] = parttype
    params = inpart.params.get('params')
    if params is not None:
        kwargs['params'] = params.split('\0')

    raise error.UnsupportedPartError(**kwargs)
Beispiel #3
0
    def _processparam(self, name, value):
        """process a parameter, applying its effect if needed

        Parameter starting with a lower case letter are advisory and will be
        ignored when unknown.  Those starting with an upper case letter are
        mandatory and will this function will raise a KeyError when unknown.

        Note: no option are currently supported. Any input will be either
              ignored or failing.
        """
        if not name:
            raise ValueError('empty parameter name')
        if name[0] not in string.letters:
            raise ValueError('non letter first character: %r' % name)
        # Some logic will be later added here to try to process the option for
        # a dict of known parameter.
        if name[0].islower():
            self.ui.debug("ignoring unknown parameter %r\n" % name)
        else:
            raise error.UnsupportedPartError(params=(name, ))