def send_req(self, method, params=None, content=None): print 'prepare to send request {0}'.format(method) if 'Content' in REQUEST_PARAMS[method]: try: assert params except: params = {} assert content params['Content-Length'] = len(content) req = [method] req += ['{0}: {1}'.format(k, v) for (k, v) in params.iteritems()] if params else [] req += ['\n{0}'.format(content)] if content else [] req = '\n'.join(req) print 'req >>' print req try: self.sock.sendall(libchat.packetify(req)) except socket.error as e: raise resp = libchat.recv_packet(self.sock) return libchat.parse(resp, libchat.RESPONSE)