本文整理汇总了Python中pycurl.global_init函数的典型用法代码示例。如果您正苦于以下问题:Python global_init函数的具体用法?Python global_init怎么用?Python global_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了global_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:beefone,项目名称:pyload,代码行数:32,代码来源:ThreadManager.py
示例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()
开发者ID:tempbottle,项目名称:pycurl,代码行数:7,代码来源:global_init_test.py
示例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()
开发者ID:CongLi,项目名称:autotest-client-tests,代码行数:60,代码来源:test_reset.py
示例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 = {}
开发者ID:srobertson,项目名称:rambler.net,代码行数:8,代码来源:url_http_protocol.py
示例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()
开发者ID:AdamJacobMuller,项目名称:pycurl,代码行数:9,代码来源:global_init_test.py
示例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
开发者ID:beefone,项目名称:pyload,代码行数:9,代码来源:ThreadManager.py
示例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 = {}
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:11,代码来源:client.py
示例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()
开发者ID:ekohl,项目名称:ganeti,代码行数:12,代码来源:client.py
示例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)
开发者ID:SUNET,项目名称:Mailfilter-APIs,代码行数:13,代码来源:CanItAPIClient.py
示例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()
开发者ID:djstavaRT,项目名称:PythonSnippets,代码行数:15,代码来源:dj_pycurl.py
示例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)
开发者ID:ekohl,项目名称:ganeti,代码行数:16,代码来源:rpc.py
示例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()
开发者ID:akashacn,项目名称:Tget,代码行数:44,代码来源:GetService.py
示例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 = {}
开发者ID:developerror,项目名称:webdavclient,代码行数:19,代码来源:client.py
示例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
开发者ID:dmoonfire,项目名称:mfgames-media-python,代码行数:21,代码来源:themoviedb.py
示例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
开发者ID:akashacn,项目名称:Tget,代码行数:23,代码来源:GetService.py
示例16: test_global_init_default
def test_global_init_default(self):
# initialize libcurl with DEFAULT flags
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
pycurl.global_cleanup()
开发者ID:AdamJacobMuller,项目名称:pycurl,代码行数:4,代码来源:global_init_test.py
示例17: PutFile
def PutFile():
srcdir = "."
filename = "testfile"
protocol = "https"
host = "mig-1.imada.sdu.dk"
port = ""
filepath = srcdir + "/" + filename
try:
inputfile = open(filepath, "rb")
except:
print "Error: Failed to open %s for reading!" % filepath
return (False, "Invalid filename!")
# Set size of file to be uploaded.
size = os.path.getsize(filepath)
if port:
url = "%s://%s:%s/%s" % (protocol, host, port, filename)
else:
url = "%s://%s/%s" % (protocol, host, filename)
# TODO: change to 'real' server certs
# Just using default NorduGRID certificates for now
os.environ["HOME"] = pwd.getpwuid(os.geteuid())[5]
globus_dir = os.path.expanduser("~/.globus")
cert_dir = globus_dir
server_cert = cert_dir + "/usercert.pem"
server_key = cert_dir + "/userkey.pem"
passwd_file = "cert_pass"
passwd = ""
try:
pw_file = open(passwd_file, "r")
passwd = pw_file.readline().strip()
pw_file.close()
except:
print "Failed to read password from file!"
return ""
# Store output in memory
output = StringIO.StringIO()
# Init cURL (not strictly necessary, but for symmetry with cleanup)
pycurl.global_init(pycurl.GLOBAL_SSL)
curl = pycurl.Curl()
curl.setopt(pycurl.HTTPHEADER, ["User-Agent: MiG HTTP PUT"])
curl.setopt(pycurl.PUT, 1)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.WRITEFUNCTION, output.write)
curl.setopt(pycurl.NOSIGNAL, 1)
# Uncomment to get verbose cURL output including SSL negotiation
curl.setopt(curl.VERBOSE, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.TIMEOUT, 300)
# curl.setopt(curl.PORT, port)
curl.setopt(pycurl.INFILE, inputfile)
curl.setopt(pycurl.INFILESIZE, size)
if protocol == "https":
curl.setopt(curl.SSLCERT, server_cert)
curl.setopt(curl.SSLKEY, server_key)
if passwd:
curl.setopt(curl.SSLKEYPASSWD, passwd)
# Path to CA certificates (NorduGRID default certificate path)
curl.setopt(curl.CAPATH, "/etc/grid-security/certificates")
# TODO: Should not be necessary but mig-1 host cert has wrong subject (vcr)
curl.setopt(curl.SSL_VERIFYHOST, 1)
# Uncomment if server identity can't be verified from local hostcert or CA cert
curl.setopt(curl.SSL_VERIFYPEER, 0)
# TODO: uncomment the following to actually execute upload
try:
curl.perform()
except pycurl.error, e:
# pycurl.error is an (errorcode, errormsg) tuple
print "Error: cURL command failed! %s" % e[1]
return (404, "Error!")
开发者ID:heromod,项目名称:migrid,代码行数:98,代码来源:TestCurl.py
示例18: ObjectLoadError
from urlparse import urljoin
import simplejson as json
from opendiamond.helpers import murmur, split_scheme
from opendiamond.protocol import XDR_attribute, XDR_object
ATTR_HEADER_URL = 'x-attributes'
ATTR_HEADER_PREFIX = 'x-attr-'
# Object attributes handled directly by the server
ATTR_DATA = ''
ATTR_OBJ_ID = '_ObjectID'
ATTR_DISPLAY_NAME = 'Display-Name'
ATTR_DEVICE_NAME = 'Device-Name'
# Initialize curl before multiple threads have been started
curl.global_init(curl.GLOBAL_DEFAULT)
class ObjectLoadError(Exception):
'''Object failed to load.'''
class EmptyObject(object):
'''An immutable Diamond object with no data and no attributes.'''
def __init__(self):
self._attrs = dict()
self._signatures = dict()
self._omit_attrs = set()
def __str__(self):
开发者ID:dvlop,项目名称:opendiamond,代码行数:31,代码来源:object_.py
示例19: main
def main():
signal.signal(signal.SIGHUP, signal.SIG_IGN)
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('-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()
#.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:hstop-svn,代码行数:101,代码来源:pyhstopc.py
示例20: GetFile
def GetFile():
# Defaults
url = "cgi-bin/ls.py"
base_dir = "."
# Just using default NorduGRID certificates for now
os.environ["HOME"] = pwd.getpwuid(os.geteuid())[5]
globus_dir = os.path.expanduser("~/.globus")
cert_dir = globus_dir
server_cert = cert_dir + "/usercert.pem"
server_key = cert_dir + "/userkey.pem"
passwd = ""
MiGServer = "https://mig-1.imada.sdu.dk"
port = "8092"
if len(sys.argv) > 1:
passwd = sys.argv[1]
data = StringIO.StringIO()
# Init cURL (not strictly necessary, but for symmetry with cleanup)
pycurl.global_init(pycurl.GLOBAL_SSL)
print "cURL:\t\t", pycurl.version
curl = pycurl.Curl()
curl.setopt(pycurl.HTTPHEADER, ["User-Agent: MiG HTTP GET"])
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.URL, MiGServer + ":" + port + "/" + url)
curl.setopt(pycurl.WRITEFUNCTION, data.write)
curl.setopt(pycurl.NOSIGNAL, 1)
# Uncomment to get verbose cURL output including SSL negotiation
curl.setopt(curl.VERBOSE, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.TIMEOUT, 300)
# curl.setopt(curl.PORT, port)
curl.setopt(curl.SSLCERT, server_cert)
curl.setopt(curl.SSLKEY, server_key)
if passwd:
curl.setopt(curl.SSLKEYPASSWD, passwd)
# Path to CA certificates (NorduGRID default certificate path)
curl.setopt(curl.CAPATH, "/etc/grid-security/certificates")
# TODO: Should not be necessary but mig-1 host cert has wrong subject (vcr)
curl.setopt(curl.SSL_VERIFYHOST, 1)
# Uncomment if server identity can't be verified from local hostcert or CA cert
curl.setopt(curl.SSL_VERIFYPEER, 0)
print "fetching:\t", url
print "cert:\t\t", server_cert
print "key:\t\t", server_key
print "passwd:\t\t", passwd
# Clean up after cURL
try:
curl.perform()
except pycurl.error, e:
print "cURL command failed!:"
# error is a (errorcode, errormsg) tuple
print e[1]
return False
开发者ID:heromod,项目名称:migrid,代码行数:76,代码来源:TestCurl.py
注:本文中的pycurl.global_init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论