/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        # so nothing to do with from_transport
55
55
 
56
56
    def _get(self, relpath, ranges, tail_amount=0):
 
57
        return self._request(relpath, 'GET', ranges, tail_amount=tail_amount)
 
58
 
 
59
    def _request(self, relpath, method, ranges, tail_amount=0, body=None):
57
60
        path = relpath
58
61
        try:
59
62
            path = self._real_abspath(relpath)
60
 
            resp = self._get_url_impl(path, method='GET', ranges=ranges,
61
 
                                      tail_amount=tail_amount)
 
63
            resp = self._get_url_impl(path, method=method, ranges=ranges,
 
64
                                      tail_amount=tail_amount, body=body)
62
65
            return resp.code, response.handle_response(path,
63
66
                                resp.code, resp.headers, resp)
64
67
        except urllib2.HTTPError, e:
67
70
                raise NoSuchFile(path, extra=e)
68
71
            raise
69
72
        except (BzrError, IOError), e:
70
 
            if hasattr(e, 'errno'):
 
73
            if getattr(e, 'errno', None) is not None:
71
74
                mutter('io error: %s %s for has url: %r',
72
75
                    e.errno, errno.errorcode.get(e.errno), path)
73
76
                if e.errno == errno.ENOENT:
74
77
                    raise NoSuchFile(path, extra=e)
75
 
            raise ConnectionError(msg = "Error retrieving %s: %s" 
76
 
                             % (self.abspath(relpath), str(e)),
77
 
                             orig_error=e)
 
78
            raise ConnectionError(msg = "Error retrieving %s: %s"
 
79
                                  % (self.abspath(relpath), str(e)),
 
80
                                  orig_error=e)
78
81
 
79
 
    def _get_url_impl(self, url, method, ranges, tail_amount=0):
 
82
    def _get_url_impl(self, url, method, ranges, tail_amount=0, body=None):
80
83
        """Actually pass get request into urllib
81
84
 
82
85
        :returns: urllib Response object
87
90
        opener = urllib2.build_opener(auth_handler)
88
91
        request = Request(url)
89
92
        request.method = method
 
93
        if body is not None:
 
94
            request.add_data(body)
90
95
        request.add_header('Pragma', 'no-cache')
91
96
        request.add_header('Cache-control', 'max-age=0')
92
97
        request.add_header('User-Agent',
97
102
        response = opener.open(request)
98
103
        return response
99
104
 
 
105
    def _post(self, body_bytes):
 
106
        return self._request('.bzr/smart', 'POST', [], body=body_bytes)
 
107
 
100
108
    def should_cache(self):
101
109
        """Return True if the data pulled across should be cached locally.
102
110
        """
113
121
            f.read()
114
122
            f.close()
115
123
            return True
 
124
        except urllib2.HTTPError, e:
 
125
            mutter('url error code: %s, for has url: %r', e.code, abspath)
 
126
            if e.code == 404:
 
127
                return False
 
128
            raise
116
129
        except urllib2.URLError, e:
117
 
            mutter('url error code: %s for has url: %r', e.code, abspath)
118
 
            if e.code == 404:
119
 
                return False
 
130
            mutter('url error: %s, for has url: %r', e.reason, abspath)
120
131
            raise
121
132
        except IOError, e:
122
133
            mutter('io error: %s %s for has url: %r',