~ubuntu-branches/ubuntu/utopic/swift/utopic

« back to all changes in this revision

Viewing changes to swift/common/internal_client.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2014-10-06 10:06:11 UTC
  • mfrom: (1.2.31)
  • Revision ID: package-import@ubuntu.com-20141006100611-wdzkkuoru7ubtlml
Tags: 2.1.0-0ubuntu1
[ Chuck Short ]
* debian/patches/fix-doc-no-network.patch: Refreshed.
* debian/control: Add python-oslosphinx as a build dependency.

[ James Page ]
* New upstream release for OpenStack Juno.
* d/copyright: Add linebreaks to fixup file-without-copyright-
  information warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
728
728
                 max_backoff=5, retries=5):
729
729
        self.url = url
730
730
        self.token = token
731
 
        self.attempts = 0
 
731
        self.attempts = 0  # needed in swif-dispersion-populate
732
732
        self.starting_backoff = starting_backoff
733
733
        self.max_backoff = max_backoff
734
734
        self.retries = retries
735
735
 
736
736
    def base_request(self, method, container=None, name=None, prefix=None,
737
737
                     headers=None, proxy=None, contents=None,
738
 
                     full_listing=None, logger=None, additional_info=None):
 
738
                     full_listing=None, logger=None, additional_info=None,
 
739
                     timeout=None):
739
740
        # Common request method
740
741
        trans_start = time()
741
742
        url = self.url
756
757
            if prefix:
757
758
                url += '&prefix=%s' % prefix
758
759
 
 
760
        req = urllib2.Request(url, headers=headers, data=contents)
759
761
        if proxy:
760
762
            proxy = urlparse.urlparse(proxy)
761
 
            proxy = urllib2.ProxyHandler({proxy.scheme: proxy.netloc})
762
 
            opener = urllib2.build_opener(proxy)
763
 
            urllib2.install_opener(opener)
764
 
 
765
 
        req = urllib2.Request(url, headers=headers, data=contents)
 
763
            req.set_proxy(proxy.netloc, proxy.scheme)
766
764
        req.get_method = lambda: method
767
 
        urllib2.urlopen(req)
768
 
        conn = urllib2.urlopen(req)
 
765
        conn = urllib2.urlopen(req, timeout=timeout)
769
766
        body = conn.read()
770
767
        try:
771
768
            body_data = json.loads(body)
799
796
        return [None, body_data]
800
797
 
801
798
    def retry_request(self, method, **kwargs):
 
799
        retries = kwargs.pop('retries', self.retries)
802
800
        self.attempts = 0
803
801
        backoff = self.starting_backoff
804
 
        while self.attempts <= self.retries:
 
802
        while self.attempts <= retries:
805
803
            self.attempts += 1
806
804
            try:
807
805
                return self.base_request(method, **kwargs)
808
806
            except (socket.error, httplib.HTTPException, urllib2.URLError):
809
 
                if self.attempts > self.retries:
 
807
                if self.attempts > retries:
810
808
                    raise
811
809
            sleep(backoff)
812
810
            backoff = min(backoff * 2, self.max_backoff)