[MERGE] don't report malformed bundles as NotABundle

John Arbash Meinel john at arbash-meinel.com
Wed Jun 21 18:09:30 BST 2006

Aaron Bentley wrote:
> John Arbash Meinel wrote:
>>> I don't think 'assertNotRaises' is really what we want.
>>> I think we want a fixed exception to be raised (MalformedBundle).
> I think it's a bug in our implementation that crlf bundle cause
> MalformedBundle to be raised.
>>> As far
>>> as the "doesn't raise anything" case, that is already handled by *not*
>>> catching the exception at all.
> If we say 'assertRaises', it's a failure if it doesn't raise.
> Aaron

But assertNotRaises could raise an IOError, or BadBundle, or IndexError,
or KeyError, or anything.
If you want it to succeed, then just perform the action and don't

I agree that bundles should support \r\n as much as they support \n. In
the loop to find the header of the bundle, we are currently doing:

if found:
    # not all mailers will keep trailing whitespace
    if line == '#\n':
        line = '# \n'
    if (not line.startswith('# ') or not line.endswith('\n')
            or line[2:-1].decode('utf-8') != header[0]):
        raise MalformedHeader('Found a header, but it'
            ' was improperly formatted')
    header.pop(0) # We read this line.
    if not header:
        break # We found everything.
elif (line.startswith('#') and line.endswith('\n')):
    line = line[1:-1].strip().decode('utf-8')
    if line[:len(header_str)] == header_str:
        if line == header[0]:
            found = True
            raise MalformedHeader('Found what looks like'
                    ' a header, but did not match')

I could see changing this line to be:

if found:
  if (not line.startswith('#')
      or line[1:].strip().decode('utf-8') != header[0]):
    raise MalformedHeader...
  header.pop(0) # We handled the header line
  if not header:
    break # We have read all the lines of the header
elif line.startswith('#'):
    line = line[1:].strip().decode('utf-8')
  except UnicodeDecodeError:
    continue # This can't be a bundle header line, it isn't utf8
  if line.startswith(header_str):
    if line == header[0]:
      found = True
      raise MalformedHeader(....)

And then in '_read_next_entry()' we can change this line:
line = line[1:-1].decode('utf-8') # Remove the '#' and '\n'
line = line[1:].rstrip().decode('utf-8')

The initial indent is important, so we can't strip it (yet).

The other piece is that I was originally planning on changing from a
custom serializer to using RIO to read/write the information, and just
wrap around the RIO iterator so that we prepend/strip the '# ' for each

So for any lines that start with '#' we can strip the trailing
whitespace. We obviously can't do that for patch lines.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060621/81ef9bfc/attachment.pgp 

More information about the bazaar mailing list