mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 01:13:47 +00:00
25 lines
803 B
Python
25 lines
803 B
Python
# coding=utf-8
|
|
import xmlrpclib
|
|
import httplib
|
|
|
|
|
|
class TimeoutHTTPConnection(httplib.HTTPConnection):
|
|
def __init__(self, host, timeout=10):
|
|
httplib.HTTPConnection.__init__(self, host, timeout=timeout)
|
|
|
|
|
|
class TimeoutTransport(xmlrpclib.Transport):
|
|
def __init__(self, timeout=10, *args, **kwargs):
|
|
xmlrpclib.Transport.__init__(self, *args, **kwargs)
|
|
self.timeout = timeout
|
|
|
|
def make_connection(self, host):
|
|
conn = TimeoutHTTPConnection(host, self.timeout)
|
|
return conn
|
|
|
|
|
|
class TimeoutServerProxy(xmlrpclib.ServerProxy):
|
|
def __init__(self, uri, timeout=10, *args, **kwargs):
|
|
kwargs['transport'] = TimeoutTransport(timeout=timeout, use_datetime=kwargs.get('use_datetime', 0))
|
|
xmlrpclib.ServerProxy.__init__(self, uri, *args, **kwargs)
|