本文整理汇总了Python中pycurl.global_init函数的典型用法代码示例。如果您正苦于以下问题:Python global_init函数的具体用法?Python global_init怎么用?Python global_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了global_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, core):
"""Constructor"""
self.core = core
self.log = core.log
self.threads = [] # thread list
self.localThreads = [] #addon+decrypter threads
self.pause = True
self.reconnecting = Event()
self.reconnecting.clear()
self.downloaded = 0 #number of files downloaded since last cleanup
self.lock = Lock()
# some operations require to fetch url info from hoster, so we caching them so it wont be done twice
# contains a timestamp and will be purged after timeout
self.infoCache = {}
# pool of ids for online check
self.resultIDs = 0
# threads which are fetching hoster results
self.infoResults = {}
# timeout for cache purge
self.timestamp = 0
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
for i in range(self.core.config.get("download", "max_downloads")):
self.createThread()
示例2: test_global_init_ack_eintr
def test_global_init_ack_eintr(self):
# the GLOBAL_ACK_EINTR flag was introduced in libcurl-7.30, but can also
# be backported for older versions of libcurl at the distribution level
if not util.pycurl_version_less_than(7, 30) or hasattr(pycurl, 'GLOBAL_ACK_EINTR'):
# initialize libcurl with the GLOBAL_ACK_EINTR flag
pycurl.global_init(pycurl.GLOBAL_ACK_EINTR)
pycurl.global_cleanup()
示例3: main
def main():
global saw_error
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
outf = file("/dev/null", "rb+")
cm = pycurl.CurlMulti()
# Set multi handle's options
cm.setopt(pycurl.M_PIPELINING, 1)
eh = pycurl.Curl()
for x in range(1, 20):
eh.setopt(pycurl.WRITEDATA, outf)
eh.setopt(pycurl.URL, sys.argv[1])
cm.add_handle(eh)
while 1:
ret, active_handles = cm.perform()
if ret != pycurl.E_CALL_MULTI_PERFORM:
break
while active_handles:
ret = cm.select(1.0)
if ret == -1:
continue
while 1:
ret, active_handles = cm.perform()
if ret != pycurl.E_CALL_MULTI_PERFORM:
break
count, good, bad = cm.info_read()
for h, en, em in bad:
print "Transfer to %s failed with %d, %s\n" % \
(h.getinfo(pycurl.EFFECTIVE_URL), en, em)
raise RuntimeError
for h in good:
httpcode = h.getinfo(pycurl.RESPONSE_CODE)
if httpcode != 200:
print "Transfer to %s failed with code %d\n" %\
(h.getinfo(pycurl.EFFECTIVE_URL), httpcode)
raise RuntimeError
else:
print "Recd %d bytes from %s" % \
(h.getinfo(pycurl.SIZE_DOWNLOAD),
h.getinfo(pycurl.EFFECTIVE_URL))
cm.remove_handle(eh)
eh.reset()
eh.close()
cm.close()
outf.close()
pycurl.global_cleanup()
示例4: assembled
def assembled(cls):
cls.needs_registration = True
cls.needs_perform = False
pycurl.global_init(pycurl.GLOBAL_ALL)
cls.multi = pycurl.CurlMulti()
cls.multi.setopt(pycurl.M_TIMERFUNCTION, cls.curl_timeout)
cls.multi.setopt(pycurl.M_SOCKETFUNCTION, cls.on_socket)
cls.instances = {}
示例5: test_global_init_ack_eintr
def test_global_init_ack_eintr(self):
# the GLOBAL_ACK_EINTR flag was introduced in libcurl-7.30, but can also
# be backported for older versions of libcurl at the distribution level
if util.pycurl_version_less_than(7, 30) and not hasattr(pycurl, 'GLOBAL_ACK_EINTR'):
raise nose.plugins.skip.SkipTest('libcurl < 7.30.0 or no GLOBAL_ACK_EINTR')
# initialize libcurl with the GLOBAL_ACK_EINTR flag
pycurl.global_init(pycurl.GLOBAL_ACK_EINTR)
pycurl.global_cleanup()
示例6: cleanPycurl
def cleanPycurl(self):
""" make a global curl cleanup (currently unused) """
if self.processingIds():
return False
pycurl.global_cleanup()
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
self.downloaded = 0
self.log.debug("Cleaned up pycurl")
return True
示例7: __init__
def __init__(self, options):
webdav_options = get_options(type=WebDAVSettings, from_options=options)
proxy_options = get_options(type=ProxySettings, from_options=options)
self.webdav = WebDAVSettings(webdav_options)
self.proxy = ProxySettings(proxy_options)
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
self.default_options = {}
示例8: wrapper
def wrapper(*args, **kwargs):
# curl_global_init(3) and curl_global_cleanup(3) must be called with only
# one thread running. This check is just a safety measure -- it doesn't
# cover all cases.
assert threading.activeCount() == 1, \
"Found active threads when initializing pycURL"
pycurl.global_init(pycurl.GLOBAL_ALL)
try:
return fn(*args, **kwargs)
finally:
pycurl.global_cleanup()
示例9: __init__
def __init__(self, url):
# Remove trailing slashes from url
url = url.rstrip('/')
url = url + '/json/'
self.url = url
self.is_error = 0
self.last_error = ''
self.curl_response = ''
self.curl_content = ''
self.curl_content_type = ''
self.curl_headers = ''
self.cookie = ''
pycurl.global_init(pycurl.GLOBAL_ALL)
示例10: dj_pycurl_download
def dj_pycurl_download(url):
pycurl.global_init(pycurl.GLOBAL_ALL)
c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.WRITEDATA,fp)
c.setopt(pycurl.WRITEFUNCTION,dj_pycurl_writeFile)
c.setopt(pycurl.NOPROGRESS,0)
c.setopt(pycurl.CONNECTTIMEOUT,DJ_PYCURL_CONNECTTIMEOUT)
c.setopt(pycurl.TIMEOUT,DJ_PYCURL_TIMEOUT)
c.setopt(pycurl.VERBOSE,1)
c.perform()
c.close()
fp.close()
示例11: Init
def Init():
"""Initializes the module-global HTTP client manager.
Must be called before using any RPC function and while exactly one thread is
running.
"""
# curl_global_init(3) and curl_global_cleanup(3) must be called with only
# one thread running. This check is just a safety measure -- it doesn't
# cover all cases.
assert threading.activeCount() == 1, \
"Found more than one active thread when initializing pycURL"
logging.info("Using PycURL %s", pycurl.version)
pycurl.global_init(pycurl.GLOBAL_ALL)
示例12: perform
def perform(self):
print self.version()
filesize = self.get_filesize()
pycurl.global_init(pycurl.GLOBAL_ALL) # GLOBAL_ALL must be set in normal
if filesize == -1: # length not known, use single connection instead
c = self.gen_curl()
outfile = self.try_soutfile(self.filename)
c.setopt(pycurl.WRITEFUNCTION, outfile.write)
c.perform()
outfile.close()
else:
curlpool = []
blocksize = filesize / self.num_blocks + 1
print filesize
for p_start, p_end in [(x, x + blocksize) for x in xrange(0, filesize, blocksize)]:
curlpool.append(self.gen_curl(p_start, p_end, filesize))
m = pycurl.CurlMulti()
m.handles = []
for c in curlpool:
m.add_handle(c)
m.handles.append(c)
try:
while True:
ret, num_handles = m.perform()
if ret != pycurl.E_CALL_MULTI_PERFORM:
break
while num_handles:
ret = m.select(1.0)
if ret == -1:
continue
while True:
ret, num_handles = m.perform()
if ret != pycurl.E_CALL_MULTI_PERFORM:
break
self.end_perform(normal = True)
self.event.set()
except KeyboardInterrupt:
self.end_perform(normal = False)
except SystemExit:
self.end_perform(normal = False)
pycurl.global_cleanup()
示例13: __init__
def __init__(self, options):
self.options = options
self.server_hostname = options.get("webdav_hostname", '')
self.server_login = options.get("webdav_login", '')
self.server_password = options.get("webdav_password", '')
self.proxy_hostname = options.get("proxy_hostname", '')
self.proxy_login = options.get("proxy_login", '')
self.proxy_password = options.get("proxy_password", '')
self.cert_path = options.get("cert_path", '')
self.key_path = options.get("key_path", '')
webdav_root = options.get("webdav_root", '')
self.webdav_root = Urn(webdav_root).quote() if webdav_root else ''
self.webdav_root = self.webdav_root.rstrip(Urn.separate)
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
self.default_options = {}
示例14: get_json
def get_json(self, url):
# Set up the PyCurl process so we can download the results
# directly. We do this so it is easier to pull out the data
# later (e.g., cache it).
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
# Retrieve the JSON for that specific movie.
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.HTTPHEADER, ["Accept: application/json"])
# Download into a string.
buf = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, buf.write)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.perform()
# Return the resulting JSON file.
json = simplejson.loads(buf.getvalue())
return json
示例15: get_filesize
def get_filesize(self):
if hasattr(self, 'filesize') and self.filesize != None:
return self.filesize
pycurl.global_init(pycurl.GLOBAL_ALL) # GLOBAL_ALL must be set in normal
curl = pycurl.Curl()
curl.setopt(pycurl.HEADER, True)
curl.setopt(pycurl.NOBODY, True)
curl.setopt(pycurl.URL, self.url)
curl.setopt(pycurl.TIMEOUT, HEADER_TIMEOUT)
b = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, b.write)
curl.perform()
try:
size = int(re.findall("Content-Length: (\d+)", b.getvalue())[0])
except:
size = -1
pycurl.global_cleanup()
self.filesize = size
return size