~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-18 02:24:28 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: aaron.bentley@utoronto.ca-20050818022428-4c0bf84005f4dba8
mergedĀ mbp@sourcefrog.net-20050817233101-0939da1cf91f2472

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
ENABLE_URLGRABBER = True
40
40
 
 
41
from bzrlib.errors import BzrError
 
42
 
 
43
class GetFailed(BzrError):
 
44
    def __init__(self, url, status):
 
45
        BzrError.__init__(self, "Get %s failed with status %s" % (url, status))
 
46
        self.url = url
 
47
        self.status = status
41
48
 
42
49
if ENABLE_URLGRABBER:
43
 
    import urlgrabber
44
 
    import urlgrabber.keepalive
45
 
    urlgrabber.keepalive.DEBUG = 0
 
50
    import util.urlgrabber
 
51
    import util.urlgrabber.keepalive
 
52
    util.urlgrabber.keepalive.DEBUG = 0
46
53
    def get_url(path, compressed=False):
47
54
        try:
48
55
            url = path
49
56
            if compressed:
50
57
                url += '.gz'
51
58
            mutter("grab url %s" % url)
52
 
            url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
 
59
            url_f = util.urlgrabber.urlopen(url, keepalive=1, close_connection=0)
 
60
            if url_f.status != 200:
 
61
                raise GetFailed(url, url_f.status)
53
62
            if not compressed:
54
63
                return url_f
55
64
            else:
167
176
        
168
177
    def __getitem__(self, fileid):
169
178
        p = self._path(fileid)
170
 
        return get_url(p, compressed=True)
 
179
        try:
 
180
            return get_url(p, compressed=True)
 
181
        except:
 
182
            raise KeyError(fileid)
171
183
    
172
184
 
173
185