我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用httplib.NotConnected()。
def send(self, data): """ ?????????? pclHTTPSConnectionBase.send ??? ??????????? ??????? ??????? ??????????? ????? """ if self.sock is None: if self.auto_open: self.connect() else: raise pclNotConnected() if hasattr(data, "read") and not isinstance(data, array.array): self.upload(data) else: self.sock.sendall(data)
def send(self, value): """Send ``value`` to the server. ``value`` can be a string object, a file-like object that supports a .read() method, or an iterable object that supports a .next() method. """ # Based on python 2.6's httplib.HTTPConnection.send() if self.sock is None: if self.auto_open: self.connect() else: raise NotConnected() # send the data to the server. if we get a broken pipe, then close # the socket. we want to reconnect when somebody tries to send again. # # NOTE: we DO propagate the error, though, because we cannot simply # ignore the error... the caller will know if they can retry. if self.debuglevel > 0: print "send:", repr(value) try: blocksize = 8192 if hasattr(value, 'read') : if hasattr(value, 'seek'): value.seek(0) if self.debuglevel > 0: print "sendIng a read()able" data = value.read(blocksize) while data: self.sock.sendall(data) data = value.read(blocksize) elif hasattr(value, 'next'): if hasattr(value, 'reset'): value.reset() if self.debuglevel > 0: print "sendIng an iterable" for data in value: self.sock.sendall(data) else: self.sock.sendall(value) except socket.error, v: if v[0] == 32: # Broken pipe self.close() raise