def request(url, callback, content='', headers=None, method='GET', timeout=5.0, close=True, ssl_args=None, compress=False, recv_len=None, event=None): ''' make an async http request When operating a tcpserver.SERVER, use this method to make async HTTP requests that eventually finish with a success or error call to a RequestCallback instance. The timeout feature will not work unless TIMERS.service is being called with appropriate frequency. Parameters: url : resource url callback: a type of RequestCallback to which asynchronous results are reported content : http content to send headers : dictionary of http headers method : http method timeout : max time, in seconds, allowed for network inactivity close : close socket after request complete, boolean ssl_args: dict of kwargs for SSLParam recv_len: read buffer size (default = BasicHandler.RECV_LEN) event : dictionary of Handler event callback routines on_init(handler) on_open(handler) on_close(handler) on_handshake(handler, cert): bool, True means keep going on_ready(handler) on_http_headers(handler): (rc, result), (0, None) means keep going on_http_send(handler, headers, content) on_data(handler, data) ''' url = _URLParser(url) context = _Context(host=url.host, resource=url.resource, callback=callback, content=content, headers=headers, method=method, timeout=timeout, close=close, compress=compress, recv_len=recv_len, event=event) if url.is_ssl: ssl = SSLParam(**(ssl_args if ssl_args else {})) else: ssl = None SERVER.add_connection((url.address, url.port), _Handler, context, ssl=ssl)
def run(command, delay=.01, loop=0): ''' helper function: loop through SERVER/TIMER until command.is_done is True ''' while not command.is_done: SERVER.service(delay=delay, max_iterations=loop) TIMERS.service()