classification
Title: HTTPConnection.send
Type: behavior Stage:
Components: Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Rosuav, Stephen.Tu, dspublic@freemail.hu
Priority: normal Keywords:

Created on 2013-03-29 16:25 by dspublic@freemail.hu, last changed 2013-04-14 20:13 by dspublic@freemail.hu. This issue is now closed.

Messages (3)
msg185501 - (view) Author: dspublic@freemail.hu (dspublic@freemail.hu) Date: 2013-03-29 16:25
http.client modul, HTTPConnection object, send method

Missing an "else" for self.sock.sendall(data) try block.


...
if hasattr(data, "read") : 
            if self.debuglevel > 0: 
                print("sendIng a read()able") 
            encode = False 
            try: 
                mode = data.mode 
            except AttributeError: 
                # io.BytesIO and other file-like objects don't have a `mode` 
                # attribute. 
                pass 
            else: 
                if "b" not in mode: 
                    encode = True 
                    if self.debuglevel > 0: 
                        print("encoding file using iso-8859-1") 
            while 1: 
                datablock = data.read(blocksize) 
                if not datablock: 
                    break 
                if encode: 
                    datablock = datablock.encode("iso-8859-1") 
                self.sock.sendall(datablock) 
        else: #missing else
          try: 
              self.sock.sendall(data) 
          except TypeError: 
              if isinstance(data, collections.Iterable): 
                    for d in data: 
                        self.sock.sendall(d) 
              else: 
                  raise TypeError("data should be a bytes-like object " 
                                "or an iterable, got %r" % type(data))
msg186794 - (view) Author: Stephen Tu (Stephen.Tu) * Date: 2013-04-13 18:49
I don't think this is a bug anymore in the codebase- looking at Lib/http/client.py, if hasattr(data, "read") is true, then the branch will return unconditionally. 

        if hasattr(data, "read") :
            if self.debuglevel > 0: 
                print("sendIng a read()able")
            encode = False
            try: 
                mode = data.mode
            except AttributeError:
                # io.BytesIO and other file-like objects don't have a `mode`
                # attribute.
                pass 
            else:
                if "b" not in mode:
                    encode = True 
                    if self.debuglevel > 0: 
                        print("encoding file using iso-8859-1")
            while 1:
                datablock = data.read(blocksize)
                if not datablock:
                    break
                if encode:
                    datablock = datablock.encode("iso-8859-1")
                self.sock.sendall(datablock)
            return
msg186949 - (view) Author: dspublic@freemail.hu (dspublic@freemail.hu) Date: 2013-04-14 20:13
Thank you Stephen.Tu for information. I think so, the "return" has been found ;-)
History
Date User Action Args
2013-04-14 20:13:05dspublic@freemail.husetstatus: open -> closed
resolution: fixed
messages: + msg186949
2013-04-13 18:49:07Stephen.Tusetnosy: + Stephen.Tu
messages: + msg186794
2013-03-29 16:49:36Rosuavsetnosy: + Rosuav
2013-03-29 16:25:03dspublic@freemail.hucreate