Is it a bug (or a feature)?

Discussion in 'Python' started by Roman Suzi, Aug 25, 2004.

  1. Roman Suzi

    Roman Suzi Guest

    In Python2.3.4:
    .... print i
    ....
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.3/email/Message.py",
    line
    304, in __getitem__
    File "/usr/lib/python2.3/email/Message.py",
    line
    370, in get
    AttributeError: 'int' object has no attribute 'lower'

    However items() does work:
    .... print i
    ....
    ('Date', '24 Aug 2004 16:06:01 +0400')
    ('From', 'Mail System Internal Data <>')
    ('Subject', "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")
    ('Message-ID', '<>')
    ('X-IMAP', '1095527634 0000000005')
    ('Status', 'RO')

    I can probably guess why this happens ('cause multiple fields with the
    same names are possible), but .items() is broken by this... It needn't
    be!


    Sincerely yours, Roman A.Suzi
     
    Roman Suzi, Aug 25, 2004
    #1
    1. Advertisements

  2. Roman Suzi

    Paul McGuire Guest

    Looks like a bug to me. Message.__getitem__() makes a call to
    Message.get(), assuming that the argument passed in is a key name (such as
    'Date', 'From', etc. from your example). __getitem__ should first check to
    see if the input argument (named 'name', further indication that this method
    was written to expect only strings) is an integer or slice, and if so, just
    return self._headers[name].

    -- Paul
     
    Paul McGuire, Aug 25, 2004
    #2
    1. Advertisements

  3. Roman Suzi

    Paul McGuire Guest

    Looking further at Message.py, __delitem__ has this same problem. When
    fixing this, should probably also add an __iter__ method, that would return
    iter(self._headers).

    -- Paul
     
    Paul McGuire, Aug 25, 2004
    #3
  4. This looks like a bug. Please open a bug on SF, with the example code.
     
    Anthony Baxter, Aug 25, 2004
    #4
  5. This looks like a bug. Please open a bug on SF, with the example code.
     
    Anthony Baxter, Aug 25, 2004
    #5
  6. Roman Suzi

    Paul McGuire Guest

    Do you mean me or the OP?

    -- Paul
     
    Paul McGuire, Aug 26, 2004
    #6
  7. Roman Suzi

    Paul McGuire Guest

    I just opened this bug, it is number 1017329.

    -- Paul
     
    Paul McGuire, Aug 27, 2004
    #7
  8. It's very similar to a 'feature' in the urllib2 module. (Python 2.3.4)
    Traceback (most recent call last):
    File "<pyshell#11>", line 1, in -toplevel-
    for entry in i: print entry
    File "D:\PYTHON23\lib\rfc822.py", line 390, in __getitem__
    return self.dict[name.lower()]
    AttributeError: 'int' object has no attribute 'lower'


    Regards,


    Fuzzy

    http://www.voidspace.org.uk/atlantibots/pythonutils.html
     
    Michael Foord, Aug 27, 2004
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.