Python: puzzling behaviour inside httplib

Posted by Anna on Stack Overflow See other posts from Stack Overflow or by Anna
Published on 2010-03-14T10:12:55Z Indexed on 2010/03/14 10:15 UTC
Read the original article Hit count: 379

Filed under:
|
|

I have added one line ( import pdb; pdb.set_trace() ) to httplib's HTTPConnection.putheader, so I can see what's going on inside.

httplib.py, line 489:

def putheader(self, header, value):
    """Send a request header line to the server.

    For example: h.putheader('Accept', 'text/html')
    """
    import pdb; pdb.set_trace()
    if self.__state != _CS_REQ_STARTED:
        raise CannotSendHeader()

    str = '%s: %s' % (header, value)
    self._output(str)

then ran this from the interpreter

import urllib2
urllib2.urlopen('http://www.ioerror.us/ip/headers')

... and as expected PDB kicks in:

> c:\python26\lib\httplib.py(858)putheader()
-> if self.__state != _CS_REQ_STARTED:
(Pdb)

in PDB I have the luxury of evaluating expressions on the fly, so I have tried to enter self.__state:

(Pdb) self.__state
*** AttributeError: HTTPConnection instance has no attribute '__state'

Alas, there is no __state of this instance. However when I enter step, the debugger gets past the

if self.__state != _CS_REQ_STARTED:

line without a problem. Why is this happening? If the self.__state doesn't exist python would have to raise an exception as it did when I entered the expression.

Python version: 2.6.4 on win32

© Stack Overflow or respective owner

Related posts about python

Related posts about httplib