Пример #1
0
    def test_threading(self):
        queue = Queue.Queue()
        cookiejar = threadedhttp.LockableCookieJar()
        connection_pool = threadedhttp.ConnectionPool()
        proc = threadedhttp.HttpProcessor(queue, cookiejar, connection_pool)
        proc.setDaemon(True)
        proc.start()
        r = threadedhttp.HttpRequest('http://www.wikipedia.org/')
        queue.put(r)

        self.assertNotIsInstance(r.exception, Exception)
        self.assertIsInstance(r.data, tuple)
        self.assertIsInstance(r.response_headers, dict)
        self.assertIn('status', r.response_headers)
        self.assertIsInstance(r.response_headers['status'], str)
        self.assertEqual(r.response_headers['status'], '200')
        self.assertEqual(r.status, 200)

        self.assertIsInstance(r.raw, bytes)
        self.assertIn(b'<html lang="mul"', r.raw)
        self.assertEqual(int(r.response_headers['content-length']), len(r.raw))

        queue.put(None)  # Stop the http processor thread
Пример #2
0
    # https://www.python.org/dev/peps/pep-0466/
    SSL_CERT_VERIFY_FAILED_MSG = "SSL: CERTIFICATE_VERIFY_FAILED"
else:
    # The OpenSSL error code for
    #   certificate verify failed
    # cf. `openssl errstr 14090086`
    SSL_CERT_VERIFY_FAILED_MSG = ":14090086:"

_logger = "comm.http"

# global variables

numthreads = 1
threads = []

connection_pool = threadedhttp.ConnectionPool()
http_queue = Queue.Queue()

cookie_jar = threadedhttp.LockableCookieJar(
    config.datafilepath("pywikibot.lwp"))
try:
    cookie_jar.load()
except (IOError, cookielib.LoadError):
    pywikibot.debug(u"Loading cookies failed.", _logger)
else:
    pywikibot.debug(u"Loaded cookies from file.", _logger)


# Build up HttpProcessors
pywikibot.log(u'Starting %(numthreads)i threads...' % locals())
for i in range(numthreads):