~ubuntu-branches/ubuntu/wily/python-urllib3/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/01_do-not-use-embedded-python-six.patch/urllib3/connectionpool.py

  • Committer: Package Import Robot
  • Author(s): Daniele Tricoli
  • Date: 2015-08-17 18:51:43 UTC
  • mfrom: (4.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20150817185143-o57dout57ku76uux
Tags: 1.11-1
* New upstream release.
* debian/control
  - Add python{,3}-tornado to Build-Depends.
  - Add python-ntlm to python-urllib3's Suggests.
* debian/patches/01_do-not-use-embedded-python-six.patch
  - Refresh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
    ClosedPoolError,
18
18
    ProtocolError,
19
19
    EmptyPoolError,
 
20
    HeaderParsingError,
20
21
    HostChangedError,
21
22
    LocationValueError,
22
23
    MaxRetryError,
38
39
from .response import HTTPResponse
39
40
 
40
41
from .util.connection import is_connection_dropped
 
42
from .util.response import assert_header_parsing
41
43
from .util.retry import Retry
42
44
from .util.timeout import Timeout
43
 
from .util.url import get_host
 
45
from .util.url import get_host, Url
44
46
 
45
47
 
46
48
xrange = six.moves.xrange
120
122
 
121
123
    :param maxsize:
122
124
        Number of connections to save that can be reused. More than 1 is useful
123
 
        in multithreaded situations. If ``block`` is set to false, more
 
125
        in multithreaded situations. If ``block`` is set to False, more
124
126
        connections will be created but they will not be saved once they've
125
127
        been used.
126
128
 
381
383
        log.debug("\"%s %s %s\" %s %s" % (method, url, http_version,
382
384
                                          httplib_response.status,
383
385
                                          httplib_response.length))
 
386
 
 
387
        try:
 
388
            assert_header_parsing(httplib_response.msg)
 
389
        except HeaderParsingError as hpe:  # Platform-specific: Python 3
 
390
            log.warning(
 
391
                'Failed to parse headers (url=%s): %s',
 
392
                self._absolute_url(url), hpe, exc_info=True)
 
393
 
384
394
        return httplib_response
385
395
 
 
396
    def _absolute_url(self, path):
 
397
        return Url(scheme=self.scheme, host=self.host, port=self.port, path=path).url
 
398
 
386
399
    def close(self):
387
400
        """
388
401
        Close all pooled connections and disable the pool.
409
422
 
410
423
        # TODO: Add optional support for socket.gethostbyname checking.
411
424
        scheme, host, port = get_host(url)
412
 
 
 
425
 
413
426
        # Use explicit default port for comparison when none is given
414
427
        if self.port and not port:
415
428
            port = port_by_scheme.get(scheme)
568
581
            # Close the connection. If a connection is reused on which there
569
582
            # was a Certificate error, the next request will certainly raise
570
583
            # another Certificate error.
571
 
            if conn:
572
 
                conn.close()
573
 
                conn = None
 
584
            conn = conn and conn.close()
 
585
            release_conn = True
574
586
            raise SSLError(e)
575
587
 
576
588
        except SSLError:
577
589
            # Treat SSLError separately from BaseSSLError to preserve
578
590
            # traceback.
579
 
            if conn:
580
 
                conn.close()
581
 
                conn = None
 
591
            conn = conn and conn.close()
 
592
            release_conn = True
582
593
            raise
583
594
 
584
595
        except (TimeoutError, HTTPException, SocketError, ConnectionError) as e:
585
 
            if conn:
586
 
                # Discard the connection for these exceptions. It will be
587
 
                # be replaced during the next _get_conn() call.
588
 
                conn.close()
589
 
                conn = None
 
596
            # Discard the connection for these exceptions. It will be
 
597
            # be replaced during the next _get_conn() call.
 
598
            conn = conn and conn.close()
 
599
            release_conn = True
590
600
 
591
601
            if isinstance(e, SocketError) and self.proxy:
592
602
                e = ProxyError('Cannot connect to proxy.', e)
626
636
                retries = retries.increment(method, url, response=response, _pool=self)
627
637
            except MaxRetryError:
628
638
                if retries.raise_on_redirect:
 
639
                    # Release the connection for this response, since we're not
 
640
                    # returning it to be released manually.
 
641
                    response.release_conn()
629
642
                    raise
630
643
                return response
631
644
 
683
696
        HTTPConnectionPool.__init__(self, host, port, strict, timeout, maxsize,
684
697
                                    block, headers, retries, _proxy, _proxy_headers,
685
698
                                    **conn_kw)
 
699
 
 
700
        if ca_certs and cert_reqs is None:
 
701
            cert_reqs = 'CERT_REQUIRED'
 
702
 
686
703
        self.key_file = key_file
687
704
        self.cert_file = cert_file
688
705
        self.cert_reqs = cert_reqs