本文整理汇总了Python中pycurl.global_cleanup函数的典型用法代码示例。如果您正苦于以下问题:Python global_cleanup函数的具体用法?Python global_cleanup怎么用?Python global_cleanup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了global_cleanup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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()
示例2: 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()
示例3: Shutdown
def Shutdown():
"""Stops the module-global HTTP client manager.
Must be called before quitting the program and while exactly one thread is
running.
"""
pycurl.global_cleanup()
示例4: 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
示例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: 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()
示例7: 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()
示例8: 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
示例9: test_global_init_default
def test_global_init_default(self):
# initialize libcurl with DEFAULT flags
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
pycurl.global_cleanup()
示例10: main
#.........这里部分代码省略.........
parser = OptionParser(usage=usage)
# parser.add_option('-q', '--quiet', action="store_const", const=0, dest="v", default=1, help='quiet')
parser.add_option('-c', '--config', action='store', dest='config', default=DEFAULT_CONF, help='load parameters from configfile (default: ' + DEFAULT_CONF + ')')
parser.add_option('-t', '--tcp', action='store_const', dest='mode', const='tcp', help='tcp mode (default)')
parser.add_option('-u', '--udp', action='store_const', dest='mode', const='udp', help='udp mode')
parser.add_option('-L', action='append', dest='forward', help='forward port:remotehost:remoteport (like ssh)')
parser.add_option('--url', action="store", dest="url", help='URL of tunnelendpoint')
parser.add_option('--proxy', action='store', dest='proxy', help='proxy to use')
parser.add_option('--auth', action='store', dest='auth', help='auth with user:password')
parser.add_option('-a', '--agent', action='store', dest='agent', help='fake useragent')
parser.add_option('-v', '--verbose', action='store_const', dest='verbose', const=1, help='verbose')
parser.add_option('--no-verify-ssl', action='store_true', dest='nv', help='do not verify ssl-host')
parser.add_option('--verify-ssl', action='store_false', dest='nv', help='do not verify ssl-host')
global options
(options, args) = parser.parse_args()
cparser = ConfigParser.ConfigParser(defaults={
'mode': 'tcp',
'url': DEFAULT_URL,
'auth': '',
'proxy': '',
'agent': '',
'verbose': 0,
'verify': True
})
cparser.read(options.config)
if cparser.has_section('pyhstopc'):
if not options.url: options.url = cparser.get('pyhstopc', 'url')
if not options.auth: options.auth = cparser.get('pyhstopc', 'auth')
if not options.agent: options.agent = cparser.get('pyhstopc', 'agent')
if not options.proxy: options.proxy = cparser.get('pyhstopc', 'proxy')
if not options.forward:
options.forward = []
try:
options.forward.extend(cparser.get('pyhstopc', 'forward').split(','))
except ConfigParser.NoOptionError:
pass
try:
if not options.verbose: options.verbose = cparser.getint('pyhstopc', 'verbose')
except TypeError:
options.verbose = 0
try:
if options.nv == None: options.nv = not cparser.getboolean('pyhstopc', 'verify')
except TypeError:
options.nv = False
cparser = None
tmpforward = options.forward
options.forward = []
for i in tmpforward:
try:
lport, rhost, rport = i.split(':')
options.forward.append((int(lport.strip()), rhost.strip(), int(rport.strip()),'tcp'))
except (KeyError, ValueError):
try:
lport, rhost, rport, mode = i.split(':')
options.forward.append((int(lport.strip()), rhost.strip(), int(rport.strip()), mode))
except (KeyError, ValueError):
print 'malformed forward option: ', i
print 'pyhstopc Version: ' + VERSION
print 'terminate with EOF'
print 'start..'
pycurl.global_init(pycurl.GLOBAL_ALL)
sls = []
for i in range(len(options.forward)):
sl = socketListener(i)
sl.listen()
try:
input = sys.stdin.readline()
while input:
input = sys.stdin.readline()
except KeyboardInterrupt:
print 'interrupted'
for sl in sls:
sl.terminate()
pycurl.global_cleanup()
print 'end..'
示例11: cleanup
def cleanup(self):
"""do global cleanup, should be called when finished with pycurl"""
pycurl.global_cleanup()
示例12: main
def main():
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
# parser.add_option('-q', '--quiet', action="store_const", const=0, dest="v", default=1, help='quiet')
# parser.add_option('-v', '--verbose', action="store_const", const=1, dest="v", help='verbose')
parser.add_option('-c', '--config', action='store', dest='config', default=DEFAULT_CONF, help='load parameters from configfile (default: ' + DEFAULT_CONF + ')')
parser.add_option('-t', '--tcp', action='store_const', dest='mode', const='tcp', help='tcp mode (default)')
#parser.add_option('-u', '--udp', action='store_const', dest='t', const='udp', help='udp mode')
parser.add_option('-p', '--port', action="store", type='int', dest="port", help='port to listen (default: '+ str(DEFAULT_LISTENPORT) +')')
parser.add_option('--url', action="store", dest="url", help='URL of tunnelendpoint (default: '+ DEFAULT_URL +')')
parser.add_option('-d', '--dest', action="store", dest="dest", help='destination to connect to (default ' + DEFAULT_TARGET + ')')
parser.add_option('--proxy', action='store', dest='proxy', help='proxy to use')
parser.add_option('--auth', action='store', dest='auth', help='auth with user:password')
parser.add_option('-v', '--verbose', action='store_const', dest='verbose', const=1, help='verbose')
#parser.add_option('--no-proxy', action='store_true', dest='np', default=False, help='use no proxy (default: use proxy from env)')
global options
(options, args) = parser.parse_args()
cparser = ConfigParser.ConfigParser(defaults={
'mode': 'tcp',
'port': DEFAULT_LISTENPORT,
'url': DEFAULT_URL,
'dest': DEFAULT_TARGET,
'auth': '',
'proxy': '',
'verbose': 0
})
cparser.read(options.config)
if cparser.has_section('pyhstopc'):
if not options.mode: options.mode = cparser.get('pyhstopc', 'mode')
if not options.port: options.port = cparser.getint('pyhstopc', 'port')
if not options.url: options.url = cparser.get('pyhstopc', 'url')
if not options.dest: options.dest = cparser.get('pyhstopc', 'dest')
if not options.auth: options.auth = cparser.get('pyhstopc', 'auth')
if not options.proxy: options.proxy = cparser.get('pyhstopc', 'proxy')
try:
if not options.verbose: options.verbose = cparser.getint('pyhstopc', 'verbose')
except TypeError:
options.verbose = 0
cparser = None
print 'pyhstopc Version: ' + VERSION
print 'terminate with EOF'
print 'start..'
if USE_CURL:
pycurl.global_init(pycurl.GLOBAL_ALL)
sl = socketListener()
sl.listen()
input = sys.stdin.readline()
while input:
input = sys.stdin.readline()
sl.terminate()
if USE_CURL:
pycurl.global_cleanup()
print 'end..'
示例13: process
def process(self, args):
# Perform any base class processing.
if not super(JsonProcess, self).process(args):
return
# Check to see if the JSON file exists.
if args.json == "-":
json = {}
elif os.path.isfile(args.json):
self.log.info("Using JSON file: " + args.json)
stream = open(args.json, 'r')
json = simplejson.load(stream)
stream.close()
else:
self.log.info("Creating JSON file: " + args.json)
json = {}
# If the file exists and we have the enable flag, then we
# check to see if we are going to force writing the file.
if "enable-tmdb" in json and not args.force:
self.log.info("Information already cached, skipping")
return False
# If the ID is 0 or less, then we disable it.
if args.id <= 0:
# Remove any existing JSON data and disable TMDB.
json["enable-tmdb"] = False
if "tmdb" in json:
del json["tmdb"]
else:
# Set up the configuration for TMDB.
self.configure()
url = "http://api.themoviedb.org/3/movie/{0}?api_key={1}".format(
args.id,
args.api_key)
tmdb_json = self.get_json(url)
# Insert the TMDB JSON data into the JSON.
json["enable-tmdb"] = True
json["tmdb"] = tmdb_json
# Now that we are done, get the formatted JSON file.
formatted = simplejson.dumps(json, indent=4, sort_keys=True)
# Figure out how to output the file.
if not args.output:
args.output = args.json
if args.output == "-":
# Just print it to the output.
print formatted
else:
# Open the stream for writing.
stream = open(args.output, "w")
simplejson.dump(json, stream, sort_keys=True, indent=4)
stream.close()
# Finish up the PyCurl library.
pycurl.global_cleanup()
示例14: cleanup_libcurl
def cleanup_libcurl():
pycurl.global_cleanup()
示例15: an
try:
print 'get_data: fetch %s', url
curl.perform()
except pycurl.error, e:
# pycurl.error is an (errorcode, errormsg) tuple
print 'cURL command failed! %s', e[1]
return ''
http_status = curl.getinfo(pycurl.HTTP_CODE)
# Clean up after cURL
curl.close()
pycurl.global_cleanup()
server_status = ''
if http_status == http_success:
# Go to start of buffer
output.seek(0)
try:
server_status = output.readlines()
except:
print 'Failed to parse server status'
return None
else:
print 'Server returned HTTP code %d, expected %d', http_status, \